From 545bfa28925c0f74df8da6cec41de52ca1838175 Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 8 Apr 2020 15:57:27 +0530 Subject: Fix and Add tests for questions view --- yaksh/test_views.py | 73 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 11 deletions(-) (limited to 'yaksh/test_views.py') diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 8f811c5..29a8542 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -4435,6 +4435,7 @@ class TestShowQuestions(TestCase): points=2.0, language="python", type="code", user=self.user, active=True ) + self.question.tags.add("question1") self.question1 = Question.objects.create( summary="Test_question2", description="Add two numbers", points=1.0, language="python", type="mcq", user=self.user, @@ -4504,7 +4505,7 @@ class TestShowQuestions(TestCase): ) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'yaksh/showquestions.html') - self.assertEqual(response.context['questions'][0], self.question) + self.assertEqual(response.context['objects'][0], self.question1) def test_download_questions(self): """ @@ -4655,13 +4656,13 @@ class TestShowQuestions(TestCase): ) trial_course = Course.objects.get(name="trial_course") trial_module = trial_course.learning_module.all()[0] - redirection_url = "/exam/start/1/{0}/{1}/{2}".format( + redirection_url = "/exam/start/1/{0}/{1}/{2}/".format( trial_module.id, trial_que_paper.id, trial_course.id ) self.assertEqual(response.status_code, 302) - self.assertRedirects(response, redirection_url, target_status_code=301) + self.assertRedirects(response, redirection_url, target_status_code=200) - def test_ajax_questions_filter(self): + def test_questions_filter(self): """ Check for filter questions based type, marks and language of a question @@ -4670,15 +4671,15 @@ class TestShowQuestions(TestCase): username=self.user.username, password=self.user_plaintext_pass ) - response = self.client.post( + response = self.client.get( reverse('yaksh:questions_filter'), data={'question_type': 'mcq', 'marks': '1.0', 'language': 'python' } ) self.assertEqual(response.status_code, 200) - self.assertTemplateUsed(response, 'yaksh/ajax_question_filter.html') - self.assertEqual(response.context['questions'][0], self.question1) + self.assertTemplateUsed(response, 'yaksh/showquestions.html') + self.assertEqual(response.context['objects'][0], self.question1) def test_download_question_yaml_template(self): """ Test to check download question yaml template """ @@ -4724,13 +4725,63 @@ class TestShowQuestions(TestCase): password=self.user_plaintext_pass ) self.question.tags.add('code') - response = self.client.post( - reverse('yaksh:show_questions'), - data={'question_tags': ['code']} + response = self.client.get( + reverse('yaksh:search_questions_by_tags'), + data={'question_tags': ['question1']} ) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'yaksh/showquestions.html') - self.assertEqual(response.context['questions'][0], self.question) + self.assertEqual(response.context['objects'][0], self.question) + + def test_single_question_attempt(self): + self.client.login( + username=self.user.username, + password=self.user_plaintext_pass + ) + response = self.client.get( + reverse('yaksh:test_question', args=[self.question.id]) + ) + trial_que_paper = QuestionPaper.objects.get( + quiz__description="trial_questions" + ) + trial_course = Course.objects.get(name="trial_course") + trial_module = trial_course.learning_module.all()[0] + redirection_url = "/exam/start/1/{0}/{1}/{2}/".format( + trial_module.id, trial_que_paper.id, trial_course.id + ) + self.assertEqual(response.status_code, 302) + self.assertRedirects(response, redirection_url, target_status_code=200) + + def test_single_question_download(self): + self.client.login( + username=self.user.username, + password=self.user_plaintext_pass + ) + response = self.client.get( + reverse('yaksh:download_question', args=[self.question.id]) + ) + file_name = "{0}_question.zip".format(self.user) + self.assertEqual(response.status_code, 200) + self.assertEqual(response.get('Content-Disposition'), + "attachment; filename={0}".format(file_name)) + zip_file = string_io(response.content) + zipped_file = zipfile.ZipFile(zip_file, 'r') + self.assertIsNone(zipped_file.testzip()) + self.assertIn('questions_dump.yaml', zipped_file.namelist()) + zip_file.close() + zipped_file.close() + + def test_single_question_delete(self): + self.client.login( + username=self.user.username, + password=self.user_plaintext_pass + ) + response = self.client.get( + reverse('yaksh:delete_question', args=[self.question.id]) + ) + self.assertEqual(response.status_code, 302) + updated_que = Question.objects.get(id=self.question.id) + self.assertFalse(updated_que.active) class TestShowStatistics(TestCase): -- cgit From 9b7c8c7f6eb3e93f1bc28d118da165a7c600cbb3 Mon Sep 17 00:00:00 2001 From: adityacp Date: Sun, 12 Apr 2020 10:54:54 +0530 Subject: Fix search courses --- yaksh/test_views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'yaksh/test_views.py') diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 29a8542..ef7c52f 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -2367,9 +2367,9 @@ class TestSearchFilters(TestCase): username=self.user1.username, password=self.user1_plaintext_pass ) - response = self.client.post( + response = self.client.get( reverse('yaksh:courses'), - data={'course_tags': 'demo', 'course_status': 'active'} + data={'search_tags': 'demo', 'search_status': 'active'} ) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'yaksh/courses.html') -- cgit