def store_in_database(self, vote_start_datetime, vote_end_date, semester): assert not self.errors # This is safe because the user's email address is checked before in the importer (see #953) responsible_dbobj = UserProfile.objects.get( email=self.responsible_email) course = Course( name_de=self.name_de, name_en=self.name_en, type=self.course_type, semester=semester, ) course.save() course.responsibles.set([responsible_dbobj]) course.degrees.set(self.degrees) evaluation = Evaluation( vote_start_datetime=vote_start_datetime, vote_end_date=vote_end_date, course=course, wait_for_grade_upload_before_publishing=self.is_graded, ) evaluation.save() evaluation.contributions.create( evaluation=evaluation, contributor=responsible_dbobj, role=Contribution.Role.EDITOR, textanswer_visibility=Contribution.TextAnswerVisibility. GENERAL_TEXTANSWERS, )
def store_in_database(self, vote_start_datetime, vote_end_date, semester): course_type = CourseType.objects.get(name_de=self.type_name) # This is safe because the user's email address is checked before in the importer (see #953) responsible_dbobj = UserProfile.objects.get( email=self.responsible_email) course = Course( name_de=self.name_de, name_en=self.name_en, type=course_type, is_graded=self.is_graded, semester=semester, ) course.save() course.responsibles.set([responsible_dbobj]) for degree_name in self.degree_names: course.degrees.add(Degree.objects.get(name_de=degree_name)) evaluation = Evaluation( vote_start_datetime=vote_start_datetime, vote_end_date=vote_end_date, course=course, ) evaluation.save() evaluation.contributions.create( contributor=responsible_dbobj, evaluation=evaluation, can_edit=True, textanswer_visibility=Contribution.TextAnswerVisibility. GENERAL_TEXTANSWERS)
def test_in_evaluation_to_reviewed(self): # Course is "fully reviewed" as no open text_answers are present by default, course = mommy.make(Course, state='in_evaluation', vote_end_date=date.today() - timedelta(days=1)) Course.update_courses() course = Course.objects.get(pk=course.pk) self.assertEqual(course.state, 'reviewed')
def test_in_evaluation_to_evaluated(self): course = mommy.make(Course, state='in_evaluation', vote_end_date=date.today() - timedelta(days=1)) with patch('evap.evaluation.models.Course.is_fully_reviewed') as mock: mock.__get__ = Mock(return_value=False) Course.update_courses() course = Course.objects.get(pk=course.pk) self.assertEqual(course.state, 'evaluated')
def test_approved_to_in_evaluation_sends_emails(self): """ Regression test for #945 """ participant = mommy.make(UserProfile, email='*****@*****.**') course = mommy.make(Course, state='approved', vote_start_datetime=datetime.now(), participants=[participant]) Course.update_courses() course = Course.objects.get(pk=course.pk) self.assertEqual(len(mail.outbox), 1) self.assertEqual(course.state, 'in_evaluation')
def store_in_database(self, vote_start_date, vote_end_date, semester): course = Course(name_de=self.name_de, name_en=self.name_en, kind=self.kind, vote_start_date=vote_start_date, vote_end_date=vote_end_date, semester=semester, degree=self.degree) course.save() return course
def test_evaluation_ends_soon(self): course = mommy.make(Course, state='in_evaluation', vote_start_datetime=datetime.now() - timedelta(days=2), vote_end_date=date.today() - timedelta(hours=24), is_graded=False) Course.update_courses() self.assertTrue(course.evaluation_ends_soon())
def test_approved_to_in_evaluation(self): course = mommy.make(Course, state='approved', vote_start_date=date.today()) with patch('evap.evaluation.models.EmailTemplate.send_evaluation_started_notifications') as mock: Course.update_courses() mock.assert_called_once_with([course], None) course = Course.objects.get(pk=course.pk) self.assertEqual(course.state, 'in_evaluation')
def test_approved_to_in_evaluation(self): course = mommy.make(Course, state='approved', vote_start_date=date.today()) with patch('evap.evaluation.models.EmailTemplate.send_evaluation_started_notifications') as mock: Course.update_courses() mock.assert_called_once_with([course]) course = Course.objects.get(pk=course.pk) self.assertEqual(course.state, 'in_evaluation')
def test_in_evaluation_to_published(self): # Course is "fully reviewed" and not graded, thus gets published immediately. course = mommy.make(Course, state='in_evaluation', vote_end_date=date.today() - timedelta(days=1), is_graded=False) with patch('evap.evaluation.tools.send_publish_notifications') as mock: Course.update_courses() mock.assert_called_once_with([course]) course = Course.objects.get(pk=course.pk) self.assertEqual(course.state, 'published')
def test_approved_to_in_evaluation(self): course = mommy.make(Course, state='approved', vote_start_datetime=datetime.now()) with patch('evap.evaluation.models.EmailTemplate.send_to_users_in_courses') as mock: Course.update_courses() template = EmailTemplate.objects.get(name=EmailTemplate.EVALUATION_STARTED) mock.assert_called_once_with(template, [course], [EmailTemplate.ALL_PARTICIPANTS], use_cc=False, request=None) course = Course.objects.get(pk=course.pk) self.assertEqual(course.state, 'in_evaluation')
def test_evaluation_ended(self): # Course is out of evaluation period. mommy.make(Course, state='in_evaluation', vote_start_datetime=datetime.now() - timedelta(days=2), vote_end_date=date.today() - timedelta(days=1), is_graded=False) # This course is not. mommy.make(Course, state='in_evaluation', vote_start_datetime=datetime.now() - timedelta(days=2), vote_end_date=date.today(), is_graded=False) with patch('evap.evaluation.models.Course.evaluation_end') as mock: Course.update_courses() self.assertEqual(mock.call_count, 1)
def store_in_database(self, vote_start_date, vote_end_date, semester): course = Course(name_de=self.name_de, name_en=self.name_en, type=self.type, is_graded=self.is_graded, vote_start_date=vote_start_date, vote_end_date=vote_end_date, semester=semester) course.save() responsible_dbobj = UserProfile.objects.get(email=self.responsible_email) course.contributions.create(contributor=responsible_dbobj, course=course, responsible=True, can_edit=True, comment_visibility=Contribution.ALL_COMMENTS) for degree_name in self.degree_names: course.degrees.add(Degree.objects.get(name_de=degree_name))
def store_in_database(self, vote_start_date, vote_end_date, semester): course = Course( name_de=self.name_de, name_en=self.name_en, kind=self.kind, is_graded=self.is_graded, vote_start_date=vote_start_date, vote_end_date=vote_end_date, semester=semester, degree=self.degree, ) course.save() responsible_dbobj = UserProfile.objects.get(email=self.responsible_email) course.contributions.create(contributor=responsible_dbobj, course=course, responsible=True, can_edit=True)
def store_in_database(self, vote_start_datetime, vote_end_date, semester): course_type = CourseType.objects.get(name_de=self.type_name) course = Course(name_de=self.name_de, name_en=self.name_en, type=course_type, is_graded=self.is_graded, vote_start_datetime=vote_start_datetime, vote_end_date=vote_end_date, semester=semester) course.save() # This is safe because the user's email address is checked before in the importer (see #953) responsible_dbobj = UserProfile.objects.get(email=self.responsible_email) course.contributions.create(contributor=responsible_dbobj, course=course, responsible=True, can_edit=True, comment_visibility=Contribution.ALL_COMMENTS) for degree_name in self.degree_names: course.degrees.add(Degree.objects.get(name_de=degree_name))
def course_create(request, semester_id): semester = get_object_or_404(Semester, id=semester_id) raise_permission_denied_if_archived(semester) course = Course(semester=semester) InlineContributionFormset = inlineformset_factory( Course, Contribution, formset=ContributionFormSet, form=ContributionForm, extra=1) form = CourseForm(request.POST or None, instance=course) formset = InlineContributionFormset(request.POST or None, instance=course, form_kwargs={'course': course}) if form.is_valid() and formset.is_valid(): form.save(user=request.user) formset.save() messages.success(request, _("Successfully created course.")) return redirect('staff:semester_view', semester_id) else: return render( request, "staff_course_form.html", dict(semester=semester, form=form, formset=formset, staff=True))
def test_single_result_form_saves_participant_and_voter_count(self): responsible = mommy.make(UserProfile) course_type = mommy.make(CourseType) course = Course(semester=mommy.make(Semester)) form_data = { "name_de": "qwertz", "name_en": "qwertz", "type": course_type.pk, "degrees": ["1"], "event_date": "2014-01-01", "responsible": responsible.pk, "answer_1": 6, "answer_2": 0, "answer_3": 2, "answer_4": 0, "answer_5": 2, "semester": course.semester.pk } form = SingleResultForm(form_data, instance=course) self.assertTrue(form.is_valid()) form.save(user=mommy.make(UserProfile)) course = Course.objects.get() self.assertEqual(course.num_participants, 10) self.assertEqual(course.num_voters, 10)
def test_single_result_form_can_change_responsible(self): responsible = mommy.make(UserProfile) course_type = mommy.make(CourseType) course = Course(semester=mommy.make(Semester)) form_data = { "name_de": "qwertz", "name_en": "qwertz", "type": course_type.pk, "degrees": ["1"], "event_date": "2014-01-01", "responsible": responsible.pk, "answer_1": 6, "answer_2": 0, "answer_3": 2, "answer_4": 0, "answer_5": 2, "semester": course.semester.pk } form = SingleResultForm(form_data, instance=course) self.assertTrue(form.is_valid()) form.save(user=mommy.make(UserProfile)) self.assertEqual(course.responsible_contributors[0], responsible) new_responsible = mommy.make(UserProfile) form_data["responsible"] = new_responsible.pk form = SingleResultForm(form_data, instance=course) self.assertTrue(form.is_valid()) form.save(user=mommy.make(UserProfile)) self.assertEqual(course.responsible_contributors[0], new_responsible)
def course_create(request, semester_id): semester = get_object_or_404(Semester, id=semester_id) course = Course(semester=semester) ContributionFormset = inlineformset_factory(Course, Contribution, formset=ContributorFormSet, form=ContributionForm, extra=1, exclude=('course', )) form = CourseForm(request.POST or None, instance=course) formset = ContributionFormset(request.POST or None, instance=course) if form.is_valid() and formset.is_valid(): form.save(user=request.user) formset.save() messages.add_message(request, messages.INFO, _("Successfully created course.")) return redirect('evap.fsr.views.semester_view', semester_id) else: return render_to_response("fsr_course_form.html", dict(semester=semester, form=form, formset=formset), context_instance=RequestContext(request))
def store_in_database(self, vote_start_date, vote_end_date, semester): course = Course(name_de=self.name_de, name_en=self.name_en, type=self.type, is_graded=self.is_graded, vote_start_date=vote_start_date, vote_end_date=vote_end_date, semester=semester) course.save() responsible_dbobj = UserProfile.objects.get( email=self.responsible_email) course.contributions.create( contributor=responsible_dbobj, course=course, responsible=True, can_edit=True, comment_visibility=Contribution.ALL_COMMENTS) for degree_name in self.degree_names: course.degrees.add(Degree.objects.get(name_de=degree_name))
def store_in_database(self, vote_start_datetime, vote_end_date, semester): course_type = CourseType.objects.get(name_de=self.type_name) course = Course(name_de=self.name_de, name_en=self.name_en, type=course_type, is_graded=self.is_graded, vote_start_datetime=vote_start_datetime, vote_end_date=vote_end_date, semester=semester) course.save() # This is safe because the user's email address is checked before in the importer (see #953) responsible_dbobj = UserProfile.objects.get( email=self.responsible_email) course.contributions.create( contributor=responsible_dbobj, course=course, responsible=True, can_edit=True, comment_visibility=Contribution.ALL_COMMENTS) for degree_name in self.degree_names: course.degrees.add(Degree.objects.get(name_de=degree_name))
def test_grant_reward_points(self): """ submits several requests that trigger the reward point granting and checks that the reward point granting works as expected for the different requests. """ user = UserProfile.objects.get(pk=5) reward_points_before_end = reward_points_of_user(user) response = self.app.get(reverse("evap.student.views.vote", args=[9]), user="******") form = lastform(response) for key, value in form.fields.items(): if key is not None and "question" in key: form.set(key, 6) response = form.submit() self.assertRedirects(response, reverse('evap.student.views.index')) # semester is not activated --> number of reward points should not increase self.assertEqual(reward_points_before_end, reward_points_of_user(user)) # reset course for another try course = Course.objects.get(pk=9) course.voters = [] # activate semester activation = SemesterActivation.objects.get(semester=course.semester) activation.is_active = True activation.save() # create a new course new_course = Course(semester=course.semester, name_de="bhabda", name_en="dsdsfds") new_course.save() new_course.participants.add(user) new_course.save() response = form.submit() self.assertRedirects(response, reverse('evap.student.views.index')) # user also has other courses this semester --> number of reward points should not increase self.assertEqual(reward_points_before_end, reward_points_of_user(user)) course.voters = [] course.save() new_course.participants.remove(user) new_course.save() # last course of user so he may get reward points response = form.submit() self.assertRedirects(response, reverse('evap.student.views.index')) # if this test fails because of this assertion check that the user is allowed to receive reward points! self.assertEqual(reward_points_before_end + settings.REWARD_POINTS_PER_SEMESTER, reward_points_of_user(user)) # test behaviour if user already got reward points course.voters = [] course.save() response = form.submit() self.assertRedirects(response, reverse('evap.student.views.index')) self.assertEqual(reward_points_before_end + settings.REWARD_POINTS_PER_SEMESTER, reward_points_of_user(user))
def store_in_database(self, vote_start_datetime, vote_end_date, semester): course_type = CourseType.objects.get(name_de=self.type_name) # This is safe because the user's email address is checked before in the importer (see #953) responsible_dbobj = UserProfile.objects.get(email=self.responsible_email) course = Course( name_de=self.name_de, name_en=self.name_en, type=course_type, is_graded=self.is_graded, semester=semester, ) course.save() course.responsibles.set([responsible_dbobj]) for degree_name in self.degree_names: course.degrees.add(Degree.objects.get(name_de=degree_name)) evaluation = Evaluation( vote_start_datetime=vote_start_datetime, vote_end_date=vote_end_date, course=course, ) evaluation.save() evaluation.contributions.create(contributor=responsible_dbobj, evaluation=evaluation, can_edit=True, textanswer_visibility=Contribution.GENERAL_TEXTANSWERS)
def single_result_create(request, semester_id): semester = get_object_or_404(Semester, id=semester_id) raise_permission_denied_if_archived(semester) course = Course(semester=semester) form = SingleResultForm(request.POST or None, instance=course) if form.is_valid(): form.save(user=request.user) messages.success(request, _("Successfully created single result.")) return redirect('staff:semester_view', semester_id) else: return render(request, "staff_single_result_form.html", dict(semester=semester, form=form))
def update_courses(self): """ Updates courses state, when evaluation time begins/ends.""" Course.update_courses()
def handle(self, *args, **options): Course.update_courses()