From b74128df59de974032d630a267a15e7d0c91a593 Mon Sep 17 00:00:00 2001 From: adityacp Date: Fri, 15 Apr 2016 12:37:59 +0530 Subject: models testcase changes --- yaksh/tests.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'yaksh/tests.py') diff --git a/yaksh/tests.py b/yaksh/tests.py index d3ff4fc..de9b39e 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -27,7 +27,7 @@ def setUpModule(): # create 20 questions for i in range(1, 21): - Question.objects.create(summary='Q%d' % (i), points=1, type='code') + Question.objects.create(summary='Q%d' % (i), points=1, type='code', user=user) # create a quiz quiz = Quiz.objects.create(start_date_time=datetime(2015, 10, 9, 10, 8, 15, 0), @@ -72,10 +72,11 @@ class ProfileTestCases(unittest.TestCase): class QuestionTestCases(unittest.TestCase): def setUp(self): # Single question details + self.user = User.objects.get(pk=1) self.question = Question(summary='Demo question', language='Python', type='Code', active=True, description='Write a function', points=1.0, - snippet='def myfunc()') + snippet='def myfunc()', user=self.user) self.question.save() self.question.tags.add('python', 'function') self.testcase = TestCase(question=self.question, @@ -121,10 +122,11 @@ class QuestionTestCases(unittest.TestCase): ############################################################################### class TestCaseTestCases(unittest.TestCase): def setUp(self): + self.user = User.objects.get(pk=1) self.question = Question(summary='Demo question', language='Python', type='Code', active=True, description='Write a function', points=1.0, - snippet='def myfunc()') + snippet='def myfunc()', user=self.user) self.question.save() self.testcase = TestCase(question=self.question, func_name='def myfunc', kw_args='a=10,b=11', -- cgit From 83b4826a242a6825197e42eb233f9301f99f3716 Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 25 Apr 2016 14:34:54 +0530 Subject: added test cases for loading and dumping questions --- yaksh/tests.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'yaksh/tests.py') diff --git a/yaksh/tests.py b/yaksh/tests.py index de9b39e..f78d151 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -73,11 +73,19 @@ class QuestionTestCases(unittest.TestCase): def setUp(self): # Single question details self.user = User.objects.get(pk=1) + self.user1 = User.objects.get(pk=2) self.question = Question(summary='Demo question', language='Python', type='Code', active=True, description='Write a function', points=1.0, snippet='def myfunc()', user=self.user) self.question.save() + + self.question1 = Question(summary='Demo Json', language='python', + type='code', active=True, + description='factorial of a no', points=2.0, + snippet='def fact()', user=self.user1) + self.question1.save() + self.question.tags.add('python', 'function') self.testcase = TestCase(question=self.question, func_name='def myfunc', kw_args='a=10,b=11', @@ -96,6 +104,11 @@ class QuestionTestCases(unittest.TestCase): } self.answer_data_json = json.dumps(answer_data) self.user_answer = "demo_answer" + questions_data = [{"snippet": "def fact()", "active": True, "points": 1.0, + "ref_code_path": "", "description": "factorial of a no", + "language": "Python", "test": "", "type": "Code", + "options": "", "summary": "Json Demo"}] + self.json_questions_data = json.dumps(questions_data) def test_question(self): """ Test question """ @@ -118,6 +131,31 @@ class QuestionTestCases(unittest.TestCase): self.user_answer) self.assertEqual(result, self.answer_data_json) + def test_dump_questions_into_json(self): + """ Test dump questions into json """ + question = Question() + questions = json.loads(question.dump_questions_into_json(self.user1)) + for que in questions: + self.assertEqual(self.question1.summary, que['summary']) + self.assertEqual(self.question1.language, que['language']) + self.assertEqual(self.question1.type, que['type']) + self.assertEqual(self.question1.description, que['description']) + self.assertEqual(self.question1.points, que['points']) + self.assertTrue(self.question1.active) + self.assertEqual(self.question1.snippet, que['snippet']) + + def test_load_questions_from_json(self): + """ Test load questions into database from json """ + question = Question() + result = question.load_questions_from_json(self.json_questions_data, self.user1) + question_data = Question.objects.all().last() + self.assertEqual(question_data.summary, 'Json Demo') + self.assertEqual(question_data.language, 'Python') + self.assertEqual(question_data.type, 'Code') + self.assertEqual(question_data.description, 'factorial of a no') + self.assertEqual(question_data.points, 1.0) + self.assertTrue(question_data.active) + self.assertEqual(question_data.snippet, 'def fact()') ############################################################################### class TestCaseTestCases(unittest.TestCase): -- cgit From 94b449a10e8ba709f64aa56cb18640ba93642cee Mon Sep 17 00:00:00 2001 From: adityacp Date: Mon, 25 Apr 2016 15:03:16 +0530 Subject: small test case change --- yaksh/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'yaksh/tests.py') diff --git a/yaksh/tests.py b/yaksh/tests.py index f78d151..8129ed5 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -148,7 +148,7 @@ class QuestionTestCases(unittest.TestCase): """ Test load questions into database from json """ question = Question() result = question.load_questions_from_json(self.json_questions_data, self.user1) - question_data = Question.objects.all().last() + question_data = Question.objects.get(pk=27) self.assertEqual(question_data.summary, 'Json Demo') self.assertEqual(question_data.language, 'Python') self.assertEqual(question_data.type, 'Code') -- cgit From 5bb441584628e65fe08ce1f240ad43f5f3ca88a8 Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 27 Apr 2016 18:22:17 +0530 Subject: test case changes --- yaksh/tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh/tests.py') diff --git a/yaksh/tests.py b/yaksh/tests.py index 8129ed5..eedcd30 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -134,7 +134,7 @@ class QuestionTestCases(unittest.TestCase): def test_dump_questions_into_json(self): """ Test dump questions into json """ question = Question() - questions = json.loads(question.dump_questions_into_json(self.user1)) + questions = json.loads(question.dump_into_json(self.user1)) for que in questions: self.assertEqual(self.question1.summary, que['summary']) self.assertEqual(self.question1.language, que['language']) @@ -147,7 +147,7 @@ class QuestionTestCases(unittest.TestCase): def test_load_questions_from_json(self): """ Test load questions into database from json """ question = Question() - result = question.load_questions_from_json(self.json_questions_data, self.user1) + result = question.load_from_json(self.json_questions_data, self.user1) question_data = Question.objects.get(pk=27) self.assertEqual(question_data.summary, 'Json Demo') self.assertEqual(question_data.language, 'Python') -- cgit From 2f7891874aec1dec962d55e3b2aaed1c61d7acaa Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 4 May 2016 22:55:19 +0530 Subject: rebase changes and changes as per comments --- yaksh/tests.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'yaksh/tests.py') diff --git a/yaksh/tests.py b/yaksh/tests.py index eedcd30..a3f3880 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -135,14 +135,14 @@ class QuestionTestCases(unittest.TestCase): """ Test dump questions into json """ question = Question() questions = json.loads(question.dump_into_json(self.user1)) - for que in questions: - self.assertEqual(self.question1.summary, que['summary']) - self.assertEqual(self.question1.language, que['language']) - self.assertEqual(self.question1.type, que['type']) - self.assertEqual(self.question1.description, que['description']) - self.assertEqual(self.question1.points, que['points']) + for q in questions: + self.assertEqual(self.question1.summary, q['summary']) + self.assertEqual(self.question1.language, q['language']) + self.assertEqual(self.question1.type, q['type']) + self.assertEqual(self.question1.description, q['description']) + self.assertEqual(self.question1.points, q['points']) self.assertTrue(self.question1.active) - self.assertEqual(self.question1.snippet, que['snippet']) + self.assertEqual(self.question1.snippet, q['snippet']) def test_load_questions_from_json(self): """ Test load questions into database from json """ -- cgit From a2d3d14e03c7f6a873b4f838752878d2bcab44aa Mon Sep 17 00:00:00 2001 From: adityacp Date: Thu, 5 May 2016 12:52:47 +0530 Subject: changes for download questions --- yaksh/tests.py | 59 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'yaksh/tests.py') diff --git a/yaksh/tests.py b/yaksh/tests.py index a3f3880..58b8518 100644 --- a/yaksh/tests.py +++ b/yaksh/tests.py @@ -72,22 +72,22 @@ class ProfileTestCases(unittest.TestCase): class QuestionTestCases(unittest.TestCase): def setUp(self): # Single question details - self.user = User.objects.get(pk=1) - self.user1 = User.objects.get(pk=2) - self.question = Question(summary='Demo question', language='Python', + self.user1 = User.objects.get(pk=1) + self.user2 = User.objects.get(pk=2) + self.question1 = Question(summary='Demo question', language='Python', type='Code', active=True, description='Write a function', points=1.0, - snippet='def myfunc()', user=self.user) - self.question.save() + snippet='def myfunc()', user=self.user1) + self.question1.save() - self.question1 = Question(summary='Demo Json', language='python', + self.question2 = Question(summary='Demo Json', language='python', type='code', active=True, description='factorial of a no', points=2.0, - snippet='def fact()', user=self.user1) - self.question1.save() + snippet='def fact()', user=self.user2) + self.question2.save() - self.question.tags.add('python', 'function') - self.testcase = TestCase(question=self.question, + self.question1.tags.add('python', 'function') + self.testcase = TestCase(question=self.question1, func_name='def myfunc', kw_args='a=10,b=11', pos_args='12,13', expected_answer='15') answer_data = { "test": "", @@ -99,7 +99,7 @@ class QuestionTestCases(unittest.TestCase): "kw_args": {"a": "10", "b": "11"} }], - "id": self.question.id, + "id": self.question1.id, "ref_code_path": "", } self.answer_data_json = json.dumps(answer_data) @@ -112,37 +112,38 @@ class QuestionTestCases(unittest.TestCase): def test_question(self): """ Test question """ - self.assertEqual(self.question.summary, 'Demo question') - self.assertEqual(self.question.language, 'Python') - self.assertEqual(self.question.type, 'Code') - self.assertFalse(self.question.options) - self.assertEqual(self.question.description, 'Write a function') - self.assertEqual(self.question.points, 1.0) - self.assertTrue(self.question.active) - self.assertEqual(self.question.snippet, 'def myfunc()') + self.assertEqual(self.question1.summary, 'Demo question') + self.assertEqual(self.question1.language, 'Python') + self.assertEqual(self.question1.type, 'Code') + self.assertFalse(self.question1.options) + self.assertEqual(self.question1.description, 'Write a function') + self.assertEqual(self.question1.points, 1.0) + self.assertTrue(self.question1.active) + self.assertEqual(self.question1.snippet, 'def myfunc()') tag_list = [] - for tag in self.question.tags.all(): + for tag in self.question1.tags.all(): tag_list.append(tag.name) self.assertEqual(tag_list, ['python', 'function']) def test_consolidate_answer_data(self): """ Test consolidate_answer_data function """ - result = self.question.consolidate_answer_data([self.testcase], + result = self.question1.consolidate_answer_data([self.testcase], self.user_answer) self.assertEqual(result, self.answer_data_json) def test_dump_questions_into_json(self): """ Test dump questions into json """ question = Question() - questions = json.loads(question.dump_into_json(self.user1)) + question_id = ['24'] + questions = json.loads(question.dump_into_json(question_id, self.user1)) for q in questions: - self.assertEqual(self.question1.summary, q['summary']) - self.assertEqual(self.question1.language, q['language']) - self.assertEqual(self.question1.type, q['type']) - self.assertEqual(self.question1.description, q['description']) - self.assertEqual(self.question1.points, q['points']) - self.assertTrue(self.question1.active) - self.assertEqual(self.question1.snippet, q['snippet']) + self.assertEqual(self.question2.summary, q['summary']) + self.assertEqual(self.question2.language, q['language']) + self.assertEqual(self.question2.type, q['type']) + self.assertEqual(self.question2.description, q['description']) + self.assertEqual(self.question2.points, q['points']) + self.assertTrue(self.question2.active) + self.assertEqual(self.question2.snippet, q['snippet']) def test_load_questions_from_json(self): """ Test load questions into database from json """ -- cgit