diff options
author | ankitjavalkar | 2015-06-17 16:08:04 +0530 |
---|---|---|
committer | ankitjavalkar | 2015-06-22 16:51:53 +0530 |
commit | 924b0d1e39ec0d4f0ffab25c46e239c146f4a247 (patch) | |
tree | 86d1634cb9bfe72526db45fbcbff4b8471e1982c | |
parent | dd716fce438898e7bbc0dfd262eb424a4a800011 (diff) | |
download | online_test-924b0d1e39ec0d4f0ffab25c46e239c146f4a247.tar.gz online_test-924b0d1e39ec0d4f0ffab25c46e239c146f4a247.tar.bz2 online_test-924b0d1e39ec0d4f0ffab25c46e239c146f4a247.zip |
Fix test cases and code_server imports
-rw-r--r-- | .travis.yml | 1 | ||||
-rwxr-xr-x | testapp/exam/code_server.py | 2 | ||||
-rw-r--r-- | testapp/exam/models.py | 5 | ||||
-rw-r--r-- | testapp/exam/tests.py | 28 |
4 files changed, 23 insertions, 13 deletions
diff --git a/.travis.yml b/.travis.yml index a5fb3f1..8c064ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ env: # command to install dependencies install: + - "easy_install git+https://github.com/FOSSEE/online_test.git#egg=django_exam-0.1" - pip install -q Django==$DJANGO --use-mirrors before_install: diff --git a/testapp/exam/code_server.py b/testapp/exam/code_server.py index 56dfff4..8f53425 100755 --- a/testapp/exam/code_server.py +++ b/testapp/exam/code_server.py @@ -31,7 +31,7 @@ import re import json # Local imports. from settings import SERVER_PORTS, SERVER_POOL_PORT -from evaluators.language_registry import set_registry, get_registry +from language_registry import set_registry, get_registry MY_DIR = abspath(dirname(__file__)) diff --git a/testapp/exam/models.py b/testapp/exam/models.py index e5a51af..1e1fbea 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -329,10 +329,7 @@ class AnswerPaper(models.Model): def questions_left(self): """Returns the number of questions left.""" qu = self.get_unanswered_questions() - if len(qu) == 0: - return 0 - else: - return qu.count('|') + 1 + return len(qu) def get_unanswered_questions(self): """Returns the list of unanswered questions.""" diff --git a/testapp/exam/tests.py b/testapp/exam/tests.py index f4cff3e..cd84874 100644 --- a/testapp/exam/tests.py +++ b/testapp/exam/tests.py @@ -61,10 +61,11 @@ class QuestionTestCases(unittest.TestCase): snippet='def myfunc()') self.question.save() self.question.tags.add('python', 'function') - self.testcase = TestCase(question=self.question, + 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", + answer_data = { "test": "", + "user_answer": "demo_answer", "test_parameter": [{"func_name": "def myfunc", "expected_answer": "15", "test_id": self.testcase.id, @@ -72,8 +73,9 @@ class QuestionTestCases(unittest.TestCase): "kw_args": {"a": "10", "b": "11"} }], - "id": self.question.id, - "language": "Python"} + "id": self.question.id, + "ref_code_path": "", + } self.answer_data_json = json.dumps(answer_data) self.user_answer = "demo_answer" @@ -181,6 +183,9 @@ class QuestionPaperTestCases(unittest.TestCase): self.user = User.objects.get(pk=1) + self.attempted_papers = AnswerPaper.objects.filter(question_paper=self.question_paper, + user=self.user) + def test_questionpaper(self): """ Test question paper""" self.assertEqual(self.question_paper.quiz.description, 'demo quiz') @@ -229,7 +234,10 @@ class QuestionPaperTestCases(unittest.TestCase): def test_make_answerpaper(self): """ Test make_answerpaper() method of Question Paper""" - answerpaper = self.question_paper.make_answerpaper(self.user, self.ip) + already_attempted = self.attempted_papers.count() + attempt_num = already_attempted + 1 + answerpaper = self.question_paper.make_answerpaper(self.user, self.ip, + attempt_num) self.assertIsInstance(answerpaper, AnswerPaper) paper_questions = set((answerpaper.questions).split('|')) self.assertEqual(len(paper_questions), 7) @@ -250,13 +258,17 @@ class AnswerPaperTestCases(unittest.TestCase): self.question_paper.save() # create answerpaper - self.answerpaper = AnswerPaper(user=self.user, profile=self.profile, + self.answerpaper = AnswerPaper(user=self.user, questions='1|2|3', question_paper=self.question_paper, start_time='2014-06-13 12:20:19.791297', end_time='2014-06-13 12:50:19.791297', user_ip=self.ip) self.answerpaper.questions_answered = '1' + self.attempted_papers = AnswerPaper.objects.filter(question_paper=self.question_paper, + user=self.user) + already_attempted = self.attempted_papers.count() + self.answerpaper.attempt_number = already_attempted + 1 self.answerpaper.save() # answers for the Answer Paper @@ -272,7 +284,6 @@ class AnswerPaperTestCases(unittest.TestCase): def test_answerpaper(self): """ Test Answer Paper""" self.assertEqual(self.answerpaper.user.username, 'demo_user') - self.assertEqual(self.answerpaper.profile_id, 1) self.assertEqual(self.answerpaper.user_ip, self.ip) questions = self.answerpaper.questions num_questions = len(questions.split('|')) @@ -300,7 +311,8 @@ class AnswerPaperTestCases(unittest.TestCase): def test_skip(self): """ Test skip() method of Answer Paper""" - next_question_id = self.answerpaper.skip() + current_question = self.answerpaper.current_question() + next_question_id = self.answerpaper.skip(current_question) self.assertTrue(next_question_id is not None) self.assertEqual(next_question_id, '3') |