def test_register_page_use_register_template(self, mock_render, mock_StudentListForm, mock_get_user, mock_Course, rf): request = rf.get('fake') mock_get_user.return_value = ANY request.user = Mock() mock_course = mock_Course.objects.get.return_value mock_course.finish_date = timezone.now().date() mock_course.start_date = timezone.now().date() register(request, ANY) template = self.template(mock_render.call_args) assert 'register.html' == template
def test_register_sends_course(self, mock_render, mock_StudentListForm, mock_get_user, mock_Course, rf): request = rf.get('fake') request.user = Mock() mock_get_user.return_value = ANY mock_course = mock_Course.objects.get.return_value mock_course.finish_date = timezone.now().date() mock_course.start_date = timezone.now().date() register(request, ANY) context = self.context(mock_render.call_args) assert mock_course == context['course']
def test_register_sends_message_if_the_courses_is_not_started(self, mock_render, mock_StudentListForm, mock_get_user, mock_Course, rf): request = rf.get('fake') request.user = Mock() mock_get_user.return_value = ANY mock_course = mock_Course.objects.get.return_value mock_course.finish_date = timezone.now().date() + datetime.timedelta(days=1) mock_course.start_date = timezone.now().date() + datetime.timedelta(days=1) register(request, ANY) context = self.context(mock_render.call_args) assert NOT_STARTED_COURSE_MESSAGE == context['NOT_STARTED_COURSE_MESSAGE']
def test_register_call_save_of_valid_form(self, mock_messages, mock_render, mock_StudentListForm, mock_get_user, mock_Course, rf): request = rf.post('fake') request.user = Mock() mock_get_user.return_value = ANY mock_student_list_form = mock_StudentListForm.return_value mock_student_list_form.is_valid.return_value = True mock_course = mock_Course.objects.get.return_value mock_course.finish_date = timezone.now().date() mock_course.start_date = timezone.now().date() register(request, ANY) assert mock_student_list_form.save.call_count == 1
def test_register_call_add_message_in_valid_form(self, mock_messages, mock_render, mock_StudentListForm, mock_get_user, mock_Course, rf): request = rf.post('fake') request.user = Mock() mock_get_user.return_value = ANY mock_student_list_form = mock_StudentListForm.return_value mock_student_list_form.is_valid.return_value = True mock_course = mock_Course.objects.get.return_value mock_course.finish_date = timezone.now().date() mock_course.start_date = timezone.now().date() register(request, ANY) mock_messages.info.assert_called_with(request, SUCCESS_MESSAGE)
def test_register_sends_message_if_the_courses_is_finished( self, mock_render, mock_StudentListForm, mock_get_user, mock_Course, rf): request = rf.get('fake') request.user = Mock() mock_get_user.return_value = ANY mock_course = mock_Course.objects.get.return_value mock_course.finish_date = timezone.now().date() - datetime.timedelta( days=2) mock_course.start_date = timezone.now().date() - datetime.timedelta( days=2) register(request, ANY) context = self.context(mock_render.call_args) assert FINISHED_COURSE_MESSAGE == context['FINISHED_COURSE_MESSAGE']