예제 #1
0
    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
예제 #2
0
    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']
예제 #3
0
    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']
예제 #4
0
    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']
예제 #5
0
    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
예제 #6
0
    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)
예제 #7
0
    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
예제 #8
0
    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
예제 #9
0
    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']
예제 #10
0
    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)