From 3d998f9d467ccfe795448dd12b33eac52f269ed4 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Sun, 19 Apr 2015 17:05:39 +0530 Subject: Add test cases for models --- testapp/exam/tests.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) (limited to 'testapp/exam/tests.py') diff --git a/testapp/exam/tests.py b/testapp/exam/tests.py index d76e4f8..30afb7e 100644 --- a/testapp/exam/tests.py +++ b/testapp/exam/tests.py @@ -1,7 +1,7 @@ from django.utils import unittest from exam.models import User, Profile, Question, Quiz, QuestionPaper,\ - QuestionSet, AnswerPaper, Answer -import datetime + QuestionSet, AnswerPaper, Answer, TestCase +import datetime, json def setUpModule(): @@ -51,12 +51,39 @@ class ProfileTestCases(unittest.TestCase): class QuestionTestCases(unittest.TestCase): def setUp(self): # Single question details + # self.question = Question(summary='Demo question', language='Python', + # type='Code', active=True, + # description='Write a function', points=1.0, + # test='Test Cases', snippet='def myfunc()') self.question = Question(summary='Demo question', language='Python', type='Code', active=True, description='Write a function', points=1.0, - test='Test Cases', snippet='def myfunc()') + snippet='def myfunc()') self.question.save() self.question.tags.add('python', 'function') + self.testcase = TestCase(question=self.question, + func_name='def myfunc', kw_args='a=10,b=11', + pos_args='12,13', expected_answer='15') + answer_data = {"user_answer": "demo_answer", + "test_parameter": [{"func_name": "def myfunc", + "expected_answer": "15", + "test_id": self.testcase.id, + "pos_args": ["12", "13"], + "kw_args": {"a": "10", + "b": "11"} + }], + "ref_code_path": "", + "id": self.question.id, + "language": "Python"} + self.answer_data_json = json.dumps(answer_data) + self.user_answer = "demo_answer" + + +# {"user_answer": "demo_answer", +# "test_parameter": [{"func_name": "def myfunc", +# "expected_answer": "15", "test_id": null, "pos_args": ["12", "13"], +# "kw_args": {"a": "10", "b": "11"}}], +# "ref_code_path": "", "id": 21, "language": "Python"} def test_question(self): """ Test question """ @@ -67,13 +94,41 @@ class QuestionTestCases(unittest.TestCase): self.assertEqual(self.question.description, 'Write a function') self.assertEqual(self.question.points, 1.0) self.assertTrue(self.question.active) - self.assertEqual(self.question.test, 'Test Cases') + # self.assertEqual(self.question.test, 'Test Cases') self.assertEqual(self.question.snippet, 'def myfunc()') tag_list = [] for tag in self.question.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], + user_answer) + self.assertEqual(result, self.answer_data_json) + + + +############################################################################### +class TestCaseTestCases(unittest.TestCase): + def setUp(self): + self.question = Question(summary='Demo question', language='Python', + type='Code', active=True, + description='Write a function', points=1.0, + snippet='def myfunc()') + self.question.save() + self.testcase = TestCase(question=self.question, + func_name='def myfunc', kw_args='a=10,b=11', + pos_args='12,13', expected_answer='15') + + def test_testcase(self): + """ Test question """ + self.assertEqual(self.testcase.question, self.question) + self.assertEqual(self.testcase.func_name, 'def myfunc') + self.assertEqual(self.testcase.kw_args, 'a=10,b=11') + self.assertEqual(self.testcase.pos_args, '12,13') + self.assertEqual(self.testcase.expected_answer, '15') + ############################################################################### class QuizTestCases(unittest.TestCase): -- cgit From 3ffdba6e587422a0f2955879d12e0b2aeac342e1 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 20 Apr 2015 21:42:02 +0530 Subject: Code review - code refactoring as per suggestion - Add subclasses for different languages - Create seperate modules for different languages - Dynamic selection of subclasses based on language used - Add testcases --- testapp/exam/tests.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'testapp/exam/tests.py') diff --git a/testapp/exam/tests.py b/testapp/exam/tests.py index 30afb7e..f73d0e2 100644 --- a/testapp/exam/tests.py +++ b/testapp/exam/tests.py @@ -3,7 +3,6 @@ from exam.models import User, Profile, Question, Quiz, QuestionPaper,\ QuestionSet, AnswerPaper, Answer, TestCase import datetime, json - def setUpModule(): # create user profile user = User.objects.create_user(username='demo_user', @@ -78,13 +77,6 @@ class QuestionTestCases(unittest.TestCase): self.answer_data_json = json.dumps(answer_data) self.user_answer = "demo_answer" - -# {"user_answer": "demo_answer", -# "test_parameter": [{"func_name": "def myfunc", -# "expected_answer": "15", "test_id": null, "pos_args": ["12", "13"], -# "kw_args": {"a": "10", "b": "11"}}], -# "ref_code_path": "", "id": 21, "language": "Python"} - def test_question(self): """ Test question """ self.assertEqual(self.question.summary, 'Demo question') @@ -94,7 +86,6 @@ class QuestionTestCases(unittest.TestCase): self.assertEqual(self.question.description, 'Write a function') self.assertEqual(self.question.points, 1.0) self.assertTrue(self.question.active) - # self.assertEqual(self.question.test, 'Test Cases') self.assertEqual(self.question.snippet, 'def myfunc()') tag_list = [] for tag in self.question.tags.all(): @@ -104,7 +95,7 @@ class QuestionTestCases(unittest.TestCase): def test_consolidate_answer_data(self): """ Test consolidate_answer_data function """ result = self.question.consolidate_answer_data([self.testcase], - user_answer) + self.user_answer) self.assertEqual(result, self.answer_data_json) -- cgit From 3e29dc7f6df7019562b179872b43cb13c7483738 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 30 Apr 2015 12:41:17 +0530 Subject: - Seperate testcases, Modify views, models, templates for compatibility - Change functions names in code_evaluator --- testapp/exam/tests.py | 1 - 1 file changed, 1 deletion(-) (limited to 'testapp/exam/tests.py') diff --git a/testapp/exam/tests.py b/testapp/exam/tests.py index f73d0e2..ff48c25 100644 --- a/testapp/exam/tests.py +++ b/testapp/exam/tests.py @@ -71,7 +71,6 @@ class QuestionTestCases(unittest.TestCase): "kw_args": {"a": "10", "b": "11"} }], - "ref_code_path": "", "id": self.question.id, "language": "Python"} self.answer_data_json = json.dumps(answer_data) -- cgit