diff options
author | ankitjavalkar | 2017-04-28 19:14:32 +0530 |
---|---|---|
committer | ankitjavalkar | 2017-04-28 19:14:32 +0530 |
commit | e9d5de3d83d925921365f5574ce787a24abbd90c (patch) | |
tree | 1bd9f9b020f988558b22cf406523ac2082558c7e | |
parent | 3597ee5fa814b0c7c737e72797d9e9911ca5e0dd (diff) | |
download | online_test-e9d5de3d83d925921365f5574ce787a24abbd90c.tar.gz online_test-e9d5de3d83d925921365f5574ce787a24abbd90c.tar.bz2 online_test-e9d5de3d83d925921365f5574ce787a24abbd90c.zip |
Add a negative test case to check attributes are duplicated
-rw-r--r-- | yaksh/models.py | 20 | ||||
-rw-r--r-- | yaksh/test_models.py | 12 |
2 files changed, 22 insertions, 10 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index ad64f2a..565bb23 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -151,21 +151,21 @@ class Course(models.Model): objects = CourseManager() + def _create_duplicate_instance(self, creator, course_name=None): + new_course = self + new_course.id = None + new_course.name = course_name if course_name else self.name + new_course.creator = creator + new_course.save() + return new_course + def create_duplicate_course(self, user): quizzes = self.quiz_set.all() prerequisite_map = [] duplicate_quiz_map = {} - new_course = Course.objects.create(creator=user, - name="Copy Of {0}".format(self.name), - enrollment=self.enrollment, - active=self.active, - is_trial=self.is_trial, - instructions=self.instructions, - start_enroll_time=self.start_enroll_time, - end_enroll_time=self.end_enroll_time - ) - new_course.teachers.add(*self.teachers.all()) + new_course_name = "Copy Of {0}".format(self.name) + new_course = self._create_duplicate_instance(user, new_course_name) for q in quizzes: new_quiz = q._create_duplicate_quiz(new_course) diff --git a/yaksh/test_models.py b/yaksh/test_models.py index 5a61c0f..c86d9a3 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -8,6 +8,7 @@ from django.utils import timezone import pytz from django.contrib.auth.models import Group from django.core.files import File +from django.forms.models import model_to_dict import zipfile import os import shutil @@ -961,6 +962,17 @@ class CourseTestCases(unittest.TestCase): self.template_course.end_enroll_time ) + # check if attributes are same + cloned_course_dict = model_to_dict(cloned_course, + fields=[field.name for field in cloned_course._meta.fields \ + if field.name != 'id'] + ) + template_course_dict = model_to_dict(self.template_course, + fields=[field.name for field in self.template_course._meta.fields \ + if field.name != 'id'] + ) + self.assertEqual(cloned_course_dict, template_course_dict) + # get duplicate quiz associated with duplicate course cloned_quiz = cloned_course.quiz_set.all()[0] |