summaryrefslogtreecommitdiff
path: root/yaksh/test_views.py
diff options
context:
space:
mode:
authorprathamesh2017-11-10 11:18:58 +0530
committerprathamesh2017-11-10 11:18:58 +0530
commit886f544ac44d831c7844ca42edb4cb97bc3b6313 (patch)
tree87e2dff0a1efa36501c4c72969db5a8be6bad975 /yaksh/test_views.py
parent2eeddaf3bc2eaf9af3fe3e08caec12ff8bc9071a (diff)
parentcfcb2ed39c724639fe17338e29e327d08ae641b2 (diff)
downloadonline_test-886f544ac44d831c7844ca42edb4cb97bc3b6313.tar.gz
online_test-886f544ac44d831c7844ca42edb4cb97bc3b6313.tar.bz2
online_test-886f544ac44d831c7844ca42edb4cb97bc3b6313.zip
Merge branch 'master' of https://github.com/FOSSEE/online_test into upload_users_csv
Diffstat (limited to 'yaksh/test_views.py')
-rw-r--r--yaksh/test_views.py56
1 files changed, 47 insertions, 9 deletions
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index e27d5ef..465fb30 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -23,7 +23,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile
from yaksh.models import User, Profile, Question, Quiz, QuestionPaper,\
QuestionSet, AnswerPaper, Answer, Course, StandardTestCase,\
AssignmentUpload, FileUpload, McqTestCase, IntegerTestCase, StringTestCase,\
- FloatTestCase
+ FloatTestCase, FIXTURES_DIR_PATH
from yaksh.decorators import user_has_profile
@@ -196,6 +196,38 @@ class TestProfile(TestCase):
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'yaksh/profile_updated.html')
+ def test_edit_profile_post_for_user_without_profile(self):
+ """
+ POST request to edit_profile view should update the user's profile
+ """
+ self.client.login(
+ username=self.user1.username,
+ password=self.user1_plaintext_pass
+ )
+ response = self.client.post(reverse('yaksh:edit_profile'),
+ data={
+ 'user': self.user1,
+ 'first_name': 'new_first_name',
+ 'last_name': 'new_last_name',
+ 'roll_number': 21,
+ 'institute': 'new_institute',
+ 'department': 'Aerospace',
+ 'position': 'new_position',
+ 'timezone': 'UTC'
+ }
+ )
+ updated_profile_user = User.objects.get(id=self.user1.id)
+ updated_profile = Profile.objects.get(user=updated_profile_user)
+ self.assertEqual(updated_profile_user.first_name, 'new_first_name')
+ self.assertEqual(updated_profile_user.last_name, 'new_last_name')
+ self.assertEqual(updated_profile.roll_number, '21')
+ self.assertEqual(updated_profile.institute, 'new_institute')
+ self.assertEqual(updated_profile.department, 'Aerospace')
+ self.assertEqual(updated_profile.position, 'new_position')
+
+ self.assertEqual(response.status_code, 200)
+ self.assertTemplateUsed(response, 'yaksh/profile_updated.html')
+
def test_edit_profile_get(self):
"""
GET request to edit profile should display profile form
@@ -3041,6 +3073,7 @@ class TestDownloadcsv(TestCase):
self.mod_group.user_set.add(self.user)
self.course = Course.objects.create(name="Python Course",
enrollment="Enroll Request", creator=self.user)
+ self.course.students.add(self.student)
self.quiz = Quiz.objects.create(
start_date_time=datetime(2014, 10, 9, 10, 8, 15, 0, tzone),
@@ -3093,8 +3126,9 @@ class TestDownloadcsv(TestCase):
username=self.student.username,
password=self.student_plaintext_pass
)
- response = self.client.get(reverse('yaksh:download_csv',
- kwargs={"questionpaper_id": self.question_paper.id}),
+ response = self.client.get(reverse('yaksh:download_quiz_csv',
+ kwargs={"course_id": self.course.id,
+ "quiz_id": self.quiz.id}),
follow=True
)
self.assertEqual(response.status_code, 404)
@@ -3122,8 +3156,9 @@ class TestDownloadcsv(TestCase):
username=self.student.username,
password=self.student_plaintext_pass
)
- response = self.client.get(reverse('yaksh:download_csv',
- kwargs={"questionpaper_id": self.question_paper.id}),
+ response = self.client.get(reverse('yaksh:download_quiz_csv',
+ kwargs={"course_id": self.course.id,
+ "quiz_id": self.quiz.id}),
follow=True
)
self.assertEqual(response.status_code, 404)
@@ -3168,11 +3203,14 @@ class TestDownloadcsv(TestCase):
username=self.user.username,
password=self.user_plaintext_pass
)
- response = self.client.get(reverse('yaksh:download_csv',
- kwargs={'questionpaper_id': self.question_paper.id}),
+ response = self.client.get(reverse('yaksh:download_quiz_csv',
+ kwargs={"course_id": self.course.id,
+ "quiz_id": self.quiz.id}),
+
follow=True
)
- file_name = "{0}.csv".format(self.quiz.description)
+ file_name = "{0}-{1}-attempt{2}.csv".format(self.course.name.replace('.', ''),
+ self.quiz.description.replace('.', ''), 1)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.get('Content-Disposition'),
'attachment; filename="{0}"'.format(file_name))
@@ -3300,7 +3338,7 @@ class TestShowQuestions(TestCase):
username=self.user.username,
password=self.user_plaintext_pass
)
- ques_file = os.path.join(settings.FIXTURE_DIRS, "demo_questions.zip")
+ ques_file = os.path.join(FIXTURES_DIR_PATH, "demo_questions.zip")
f = open(ques_file, 'rb')
questions_file = SimpleUploadedFile(ques_file, f.read(),
content_type="application/zip")