def test_post_start_time_before_end_time(self): testperiod = mommy.make('core.Period') mockresponse = self.mock_http200_postrequest_htmls( cradmin_role=testperiod, requestkwargs={ 'data': { 'long_name': 'Test period', 'short_name': 'testperiod', 'start_time': datetimeutils.isoformat_noseconds(ACTIVE_PERIOD_END), 'end_time': datetimeutils.isoformat_noseconds(ACTIVE_PERIOD_START), } }) self.assertEqual( 'Start time must be before end time.', mockresponse.selector.one('.alert-danger').alltext_normalized)
def test_post_missing_long_name(self): testperiod = mommy.make('core.Period') mockresponse = self.mock_http200_postrequest_htmls( cradmin_role=testperiod, requestkwargs={ 'data': { 'long_name': '', 'short_name': 'testperiod', 'start_time': datetimeutils.isoformat_noseconds(ACTIVE_PERIOD_START), 'end_time': datetimeutils.isoformat_noseconds(ACTIVE_PERIOD_END), } }) self.assertEqual( 'This field is required.', mockresponse.selector.one('#error_1_id_long_name').alltext_normalized)
def test_post_copy_with_passing_grade_from_another_assignment_same_group_structure(self): period = mommy.make_recipe('devilry.apps.core.period_active') other_assignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start', parentnode=period) group = mommy.make('core.AssignmentGroup', parentnode=other_assignment) relatedstudent_user1 = mommy.make(settings.AUTH_USER_MODEL) relatedstudent_user2 = mommy.make(settings.AUTH_USER_MODEL) mommy.make('core.Candidate', assignment_group=group, relatedstudent__period=period, relatedstudent__user=relatedstudent_user1) mommy.make('core.Candidate', assignment_group=group, relatedstudent__period=period, relatedstudent__user=relatedstudent_user2) devilry_group_mommy_factories.feedbackset_first_attempt_published( grading_points=1, group=group) self.mock_http302_postrequest( cradmin_role=period, requestkwargs={ 'data': { 'long_name': 'Test assignment', 'short_name': 'testassignment', 'first_deadline': datetimeutils.isoformat_noseconds(ACTIVE_PERIOD_END), 'student_import_option': '{}_passed'.format(other_assignment.id) } }) self.assertEqual(Assignment.objects.filter(short_name='testassignment').count(), 1) created_assignment = Assignment.objects.get(short_name='testassignment') self.assertEqual(created_assignment.assignmentgroups.count(), 1) created_group = created_assignment.assignmentgroups.get() self.assertEqual(Candidate.objects.filter(assignment_group=created_group).count(), 2) self.assertTrue( Candidate.objects.filter( assignment_group=created_group, relatedstudent__user=relatedstudent_user1).exists()) self.assertTrue( Candidate.objects.filter( assignment_group=created_group, relatedstudent__user=relatedstudent_user2).exists())
def test_post_copy_all_students_from_another_assignment(self): period = mommy.make_recipe('devilry.apps.core.period_active') other_assignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start', parentnode=period) relatedstudent_user1 = mommy.make(settings.AUTH_USER_MODEL) relatedstudent_user2 = mommy.make(settings.AUTH_USER_MODEL) mommy.make('core.Candidate', assignment_group__parentnode=other_assignment, relatedstudent__period=period, relatedstudent__user=relatedstudent_user1) mommy.make('core.Candidate', assignment_group__parentnode=other_assignment, relatedstudent__period=period, relatedstudent__user=relatedstudent_user2) self.mock_http302_postrequest( cradmin_role=period, requestkwargs={ 'data': { 'long_name': 'Test assignment', 'short_name': 'testassignment', 'first_deadline': datetimeutils.isoformat_noseconds(ACTIVE_PERIOD_END), 'student_import_option': '{}_all'.format(other_assignment.id) } }) self.assertEqual(Assignment.objects.filter(short_name='testassignment').count(), 1) created_assignment = Assignment.objects.get(short_name='testassignment') self.assertEqual(created_assignment.assignmentgroups.count(), 2) self.assertEqual( Candidate.objects.filter( assignment_group__parentnode=created_assignment, relatedstudent__user=relatedstudent_user1).count(), 1) self.assertEqual( Candidate.objects.filter( assignment_group__parentnode=created_assignment, relatedstudent__user=relatedstudent_user2).count(), 1)
def test_post_import_all_students_on_semester(self): period = mommy.make_recipe('devilry.apps.core.period_active') relatedstudent1 = mommy.make('core.RelatedStudent', period=period) relatedstudent2 = mommy.make('core.RelatedStudent', period=period) relatedstudent3 = mommy.make('core.RelatedStudent', period=period) self.mock_http302_postrequest( cradmin_role=period, requestkwargs={ 'data': { 'long_name': 'Test assignment', 'short_name': 'testassignment', 'first_deadline': datetimeutils.isoformat_noseconds(ACTIVE_PERIOD_END), 'student_import_option': 'all' } }) self.assertEqual(Assignment.objects.count(), 1) created_assignment = Assignment.objects.get() self.assertEqual( Candidate.objects .filter(assignment_group__parentnode=created_assignment, relatedstudent=relatedstudent1) .count(), 1) self.assertEqual( Candidate.objects .filter(assignment_group__parentnode=created_assignment, relatedstudent=relatedstudent2) .count(), 1) self.assertEqual( Candidate.objects .filter(assignment_group__parentnode=created_assignment, relatedstudent=relatedstudent3) .count(), 1)
def __valid_post_request(self, testperiod, start_time=ACTIVE_PERIOD_START, end_time=ACTIVE_PERIOD_END, **kwargs): mockresponse = self.mock_http302_postrequest( cradmin_role=testperiod, requestkwargs={ 'data': { 'long_name': 'Test period', 'short_name': 'testperiod', 'start_time': datetimeutils.isoformat_noseconds(start_time), 'end_time': datetimeutils.isoformat_noseconds(end_time), } }, **kwargs) updated_period = Period.objects.get(id=testperiod.id) return updated_period, mockresponse
def test_periodlist_itemrendering_start_time(self): testsubject = mommy.make('core.Subject') mommy.make_recipe('devilry.apps.core.period_active', parentnode=testsubject) with self.settings(DATETIME_FORMAT=datetimeutils.ISODATETIME_DJANGOFORMAT, USE_L10N=False): mockresponse = self.mock_http200_getrequest_htmls(cradmin_role=testsubject) self.assertEqual(datetimeutils.isoformat_noseconds(ACTIVE_PERIOD_START), mockresponse.selector.one( '.devilry-cradmin-perioditemvalue-start-time-value').alltext_normalized)
def __valid_post_request(self, subject=None, start_time=ACTIVE_PERIOD_START, end_time=ACTIVE_PERIOD_END): if not subject: subject = mommy.make('core.Subject') mockresponse = self.mock_http302_postrequest( cradmin_role=subject, requestkwargs={ 'data': { 'long_name': 'Test period', 'short_name': 'testperiod', 'start_time': datetimeutils.isoformat_noseconds(start_time), 'end_time': datetimeutils.isoformat_noseconds(end_time), } }) created_period = Period.objects.get(short_name='testperiod') return created_period, mockresponse
def test_assignmentlist_itemrendering_first_deadline(self): testperiod = mommy.make_recipe('devilry.apps.core.period_active') mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start', parentnode=testperiod) with self.settings(DATETIME_FORMAT=datetimeutils.ISODATETIME_DJANGOFORMAT, USE_L10N=False): mockresponse = self.mock_http200_getrequest_htmls(cradmin_role=testperiod) self.assertEqual(datetimeutils.isoformat_noseconds(ASSIGNMENT_ACTIVEPERIOD_START_FIRST_DEADLINE), mockresponse.selector.one( '.devilry-admin-period-overview-assignment-first-deadline-value').alltext_normalized)
def test_assignmentlist_itemrendering_first_deadline(self): testperiod = mommy.make_recipe('devilry.apps.core.period_active') periodadmin_user = self.__make_period_admin_user(period=testperiod) mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start', parentnode=testperiod) with self.settings(DATETIME_FORMAT=datetimeutils.ISODATETIME_DJANGOFORMAT, USE_L10N=False): mockresponse = self.mock_http200_getrequest_htmls(cradmin_role=testperiod, requestuser=periodadmin_user) self.assertEqual(datetimeutils.isoformat_noseconds(ASSIGNMENT_ACTIVEPERIOD_START_FIRST_DEADLINE), mockresponse.selector.one( '.devilry-admin-period-overview-assignment-first-deadline-value').alltext_normalized)
def test_post_missing_long_name(self): period = mommy.make_recipe("devilry.apps.core.period_active") first_deadline_isoformat = datetimeutils.isoformat_noseconds(OLD_PERIOD_START) mockresponse = self.mock_http200_postrequest_htmls( cradmin_role=period, requestkwargs={ "data": {"long_name": "", "short_name": "testassignment", "first_deadline": first_deadline_isoformat} }, ) self.assertEqual(Assignment.objects.count(), 0) self.assertEqual( "This field is required.", mockresponse.selector.one("#error_1_id_long_name").alltext_normalized )
def test_periodlist_itemrendering_end_time(self): testsubject = mommy.make('core.Subject') testperiod = mommy.make_recipe('devilry.apps.core.period_active', parentnode=testsubject) testuser = mommy.make(settings.AUTH_USER_MODEL) periodpermissiongroup = mommy.make('devilry_account.PeriodPermissionGroup', period=testperiod) mommy.make('devilry_account.PermissionGroupUser', user=testuser, permissiongroup=periodpermissiongroup.permissiongroup) with self.settings(DATETIME_FORMAT=datetimeutils.ISODATETIME_DJANGOFORMAT, USE_L10N=False): mockresponse = self.mock_http200_getrequest_htmls(cradmin_role=testsubject, requestuser=testuser) self.assertEqual(datetimeutils.isoformat_noseconds(ACTIVE_PERIOD_END), mockresponse.selector.one( '.devilry-cradmin-perioditemvalue-end-time-value').alltext_normalized)
def test_assignmentlist_itemrendering_publishing_time(self): testperiod = mommy.make_recipe('devilry.apps.core.period_active') mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start', parentnode=testperiod) with self.settings( DATETIME_FORMAT=datetimeutils.ISODATETIME_DJANGOFORMAT, USE_L10N=False): mockresponse = self.mock_http200_getrequest_htmls( cradmin_role=testperiod) self.assertEqual( datetimeutils.isoformat_noseconds(ACTIVE_PERIOD_START), mockresponse.selector.one( '.devilry-admin-period-overview-assignment-publishing-time-value' ).alltext_normalized)
def test_periodlist_itemrendering_start_time(self): testsubject = mommy.make('core.Subject') mommy.make_recipe('devilry.apps.core.period_active', parentnode=testsubject) with self.settings( DATETIME_FORMAT=datetimeutils.ISODATETIME_DJANGOFORMAT, USE_L10N=False): mockresponse = self.mock_http200_getrequest_htmls( cradmin_role=testsubject) self.assertEqual( datetimeutils.isoformat_noseconds(ACTIVE_PERIOD_START), mockresponse.selector.one( '.devilry-cradmin-perioditemvalue-start-time-value'). alltext_normalized)
def __valid_post_request(self, period=None, first_deadline=ACTIVE_PERIOD_END, publishing_time_delay_minutes=60): if not period: period = mommy.make_recipe("devilry.apps.core.period_active") with self.settings(DEVILRY_ASSIGNMENT_PUBLISHING_TIME_DELAY_MINUTES=publishing_time_delay_minutes): mockresponse = self.mock_http302_postrequest( cradmin_role=period, requestkwargs={ "data": { "long_name": "Test assignment", "short_name": "testassignment", "first_deadline": datetimeutils.isoformat_noseconds(first_deadline), } }, ) created_assignment = Assignment.objects.get(short_name="testassignment") return created_assignment, mockresponse
def test_post_missing_student_import_option(self): period = mommy.make_recipe('devilry.apps.core.period_active') mockresponse = self.mock_http200_postrequest_htmls( cradmin_role=period, requestkwargs={ 'data': { 'long_name': 'Test assignment', 'short_name': 'testassignment', 'first_deadline': datetimeutils.isoformat_noseconds(OLD_PERIOD_START), 'student_import_option': '' } }) self.assertEqual(Assignment.objects.count(), 0) self.assertEqual( 'This field is required.', mockresponse.selector.one('#error_1_id_student_import_option').alltext_normalized)
def test_post_first_deadline_outside_period(self): period = mommy.make_recipe('devilry.apps.core.period_active') first_deadline_isoformat = datetimeutils.isoformat_noseconds(FUTURE_PERIOD_END) mockresponse = self.mock_http200_postrequest_htmls( cradmin_role=period, requestkwargs={ 'data': { 'long_name': 'Test assignment', 'short_name': 'testassignment', 'first_deadline': first_deadline_isoformat, } }) self.assertEqual(Assignment.objects.count(), 0) self.assertTrue(mockresponse.selector.exists('#error_1_id_first_deadline')) self.assertIn('First deadline must be within', mockresponse.selector.one('#error_1_id_first_deadline').alltext_normalized)
def test_post_import_no_students(self): period = mommy.make_recipe('devilry.apps.core.period_active') mommy.make('core.RelatedStudent', period=period, _quantity=10) self.mock_http302_postrequest( cradmin_role=period, requestkwargs={ 'data': { 'long_name': 'Test assignment', 'short_name': 'testassignment', 'first_deadline': datetimeutils.isoformat_noseconds(ACTIVE_PERIOD_END), 'student_import_option': 'none' } }) self.assertEqual(Assignment.objects.count(), 1) created_assignment = Assignment.objects.get() self.assertFalse(Candidate.objects.filter(assignment_group__parentnode=created_assignment).exists()) self.assertFalse(AssignmentGroup.objects.filter(parentnode=created_assignment).exists())
def test_post_first_deadline_before_publishing_time_minutes(self): period = mommy.make_recipe('devilry.apps.core.period_active') first_deadline_isoformat = datetimeutils.isoformat_noseconds(timezone.now()) with self.settings(DEVILRY_ASSIGNMENT_PUBLISHING_TIME_DELAY_MINUTES=30): mockresponse = self.mock_http200_postrequest_htmls( cradmin_role=period, requestkwargs={ 'data': { 'long_name': 'Test assignment', 'short_name': 'testassignment', 'first_deadline': first_deadline_isoformat, } }) self.assertEqual(Assignment.objects.count(), 0) self.assertTrue(mockresponse.selector.exists('#error_1_id_first_deadline')) self.assertEqual('First deadline must be at least 30 minutes from now.', mockresponse.selector.one('#error_1_id_first_deadline').alltext_normalized)
def __valid_post_request(self, period=None, first_deadline=ACTIVE_PERIOD_END, publishing_time_delay_minutes=60, student_import_option='all'): if not period: period = mommy.make_recipe('devilry.apps.core.period_active') with self.settings(DEVILRY_ASSIGNMENT_PUBLISHING_TIME_DELAY_MINUTES=publishing_time_delay_minutes): mockresponse = self.mock_http302_postrequest( cradmin_role=period, requestkwargs={ 'data': { 'long_name': 'Test assignment', 'short_name': 'testassignment', 'first_deadline': datetimeutils.isoformat_noseconds(first_deadline), 'student_import_option': student_import_option } }) created_assignment = Assignment.objects.get(short_name='testassignment') return created_assignment, mockresponse
def test_post_first_deadline_outside_period(self): period = mommy.make_recipe("devilry.apps.core.period_active") first_deadline_isoformat = datetimeutils.isoformat_noseconds(FUTURE_PERIOD_END) mockresponse = self.mock_http200_postrequest_htmls( cradmin_role=period, requestkwargs={ "data": { "long_name": "Test assignment", "short_name": "testassignment", "first_deadline": first_deadline_isoformat, } }, ) self.assertEqual(Assignment.objects.count(), 0) self.assertTrue(mockresponse.selector.exists("#error_1_id_first_deadline")) self.assertIn( "First deadline must be within", mockresponse.selector.one("#error_1_id_first_deadline").alltext_normalized )
def test_post_first_deadline_before_publishing_time_minutes(self): period = mommy.make_recipe("devilry.apps.core.period_active") first_deadline_isoformat = datetimeutils.isoformat_noseconds(timezone.now()) with self.settings(DEVILRY_ASSIGNMENT_PUBLISHING_TIME_DELAY_MINUTES=30): mockresponse = self.mock_http200_postrequest_htmls( cradmin_role=period, requestkwargs={ "data": { "long_name": "Test assignment", "short_name": "testassignment", "first_deadline": first_deadline_isoformat, } }, ) self.assertEqual(Assignment.objects.count(), 0) self.assertTrue(mockresponse.selector.exists("#error_1_id_first_deadline")) self.assertEqual( "First deadline must be at least 30 minutes from now.", mockresponse.selector.one("#error_1_id_first_deadline").alltext_normalized, )
def test_post_copy_with_passing_grade_from_another_examiners_copied(self): period = mommy.make_recipe('devilry.apps.core.period_active') other_assignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start', parentnode=period) group = mommy.make('core.AssignmentGroup', parentnode=other_assignment) devilry_group_mommy_factories.feedbackset_first_attempt_published( grading_points=1, group=group) self.mock_http302_postrequest( cradmin_role=period, requestkwargs={ 'data': { 'long_name': 'Test assignment', 'short_name': 'testassignment', 'first_deadline': datetimeutils.isoformat_noseconds(ACTIVE_PERIOD_END), 'student_import_option': '{}_passed'.format(other_assignment.id) } }) self.assertEqual(Assignment.objects.filter(short_name='testassignment').count(), 1) created_assignment = Assignment.objects.get(short_name='testassignment') self.assertEqual(created_assignment.assignmentgroups.count(), 1) self.assertEqual(Examiner.objects.filter(assignmentgroup__parentnode=created_assignment).count(), 1)
def devilry_isoformat_datetime(datetimeobject): """ Isoformat the given ``datetimeobject`` as ``YYYY-MM-DD hh:mm``. """ return datetimeutils.isoformat_noseconds(datetimeobject)
def test_sanity(self): self.assertEqual( '2015-12-24 17:42', datetimeutils.isoformat_noseconds(datetimeutils.default_timezone_datetime(2015, 12, 24, 17, 42)))
def test_before_year_1900(self): self.assertEqual( '0030-12-24 14:30', datetimeutils.isoformat_noseconds(datetimeutils.default_timezone_datetime(30, 12, 24, 14, 30)))
def test_no_seconds(self): self.assertEqual( '2015-12-24 17:42', datetimeutils.isoformat_noseconds(datetime(2015, 12, 24, 17, 42, 41)))