def test_post_groups_published_raises_error(self): testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start') testgroup1 = mommy.make('core.AssignmentGroup', parentnode=testassignment) testgroup2 = mommy.make('core.AssignmentGroup', parentnode=testassignment) group_mommy.feedbackset_first_attempt_published(group=testgroup1) group_mommy.feedbackset_first_attempt_unpublished(group=testgroup2) testuser = self._get_admin_user(testassignment.parentnode) mommy.make('core.Examiner', assignmentgroup=testgroup1, relatedexaminer__user=testuser) mommy.make('core.Examiner', assignmentgroup=testgroup2, relatedexaminer__user=testuser) new_deadline = timezone.now() + timezone.timedelta(days=3) new_deadline = new_deadline.replace(microsecond=0) with self.assertRaises(http.Http404): self.mock_http302_postrequest( cradmin_role=testassignment, cradmin_instance=self._get_mock_instance(testassignment), cradmin_app=self._get_mock_app(user=testuser), requestuser=testuser, viewkwargs={ 'deadline': datetimeutils.datetime_to_url_string(testassignment.first_deadline), 'handle_deadline': self.handle_deadline }, requestkwargs={ 'data': { 'new_deadline': isoformat_withseconds(timezone.localtime(new_deadline)), 'comment_text': 'You have been given a new attempt.', 'selected_items': [testgroup1.id, testgroup2.id] } } ) self.assertEqual(2, group_models.FeedbackSet.objects.count())
def test_post_groups_published_raises_error(self): testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start') testgroup1 = mommy.make('core.AssignmentGroup', parentnode=testassignment) testgroup2 = mommy.make('core.AssignmentGroup', parentnode=testassignment) group_mommy.feedbackset_first_attempt_published(group=testgroup1) group_mommy.feedbackset_first_attempt_unpublished(group=testgroup2) testuser = self._get_admin_user(testassignment.parentnode) mommy.make('core.Examiner', assignmentgroup=testgroup1, relatedexaminer__user=testuser) mommy.make('core.Examiner', assignmentgroup=testgroup2, relatedexaminer__user=testuser) new_deadline = timezone.now() + timezone.timedelta(days=3) new_deadline = new_deadline.replace(microsecond=0) with self.assertRaises(http.Http404): self.mock_http302_postrequest( cradmin_role=testassignment, cradmin_instance=self._get_mock_instance(testassignment), cradmin_app=self._get_mock_app(user=testuser), requestuser=testuser, viewkwargs={ 'deadline': datetimeutils.datetime_to_url_string(testassignment.first_deadline), 'handle_deadline': self.handle_deadline }, requestkwargs={ 'data': { 'new_deadline': isoformat_withseconds(timezone.localtime(new_deadline)), 'comment_text': 'You have been given a new attempt.', 'selected_items': [testgroup1.id, testgroup2.id] } } ) self.assertEquals(2, group_models.FeedbackSet.objects.count())
def test_post_new_attempt(self): testassignment = mommy.make_recipe( 'devilry.apps.core.assignment_activeperiod_start') testgroup1 = mommy.make('core.AssignmentGroup', parentnode=testassignment) group_mommy.feedbackset_first_attempt_published(group=testgroup1) testgroup2 = mommy.make('core.AssignmentGroup', parentnode=testassignment) group_mommy.feedbackset_first_attempt_published(group=testgroup2) testuser = self._get_admin_user(testassignment.parentnode) mommy.make('core.Examiner', assignmentgroup=testgroup1, relatedexaminer__user=testuser) mommy.make('core.Examiner', assignmentgroup=testgroup2, relatedexaminer__user=testuser) new_deadline = timezone.now() + timezone.timedelta(days=3) new_deadline = new_deadline.replace(microsecond=0) self.mock_postrequest( cradmin_role=testassignment, cradmin_instance=self._get_mock_instance(testassignment), cradmin_app=self._get_mock_app(user=testuser), requestuser=testuser, viewkwargs={ 'deadline': datetimeutils.datetime_to_url_string( testassignment.first_deadline), 'handle_deadline': 'new-attempt' }, requestkwargs={ 'data': { 'new_deadline': isoformat_withseconds(timezone.localtime(new_deadline)), 'comment_text': 'You have been given a new attempt.', 'selected_items': [testgroup1.id, testgroup2.id] } }) self.assertEqual(4, group_models.FeedbackSet.objects.count()) self.assertEqual(2, group_models.GroupComment.objects.count()) group_comments = group_models.GroupComment.objects.all() last_feedbackset_group1 = AssignmentGroupCachedData.objects.get( group_id=testgroup1.id).last_feedbackset last_feedbackset_group2 = AssignmentGroupCachedData.objects.get( group_id=testgroup2.id).last_feedbackset self.assertEqual(last_feedbackset_group1.deadline_datetime, new_deadline) self.assertEqual(last_feedbackset_group2.deadline_datetime, new_deadline) self.assertEqual(last_feedbackset_group1.last_updated_by, testuser) self.assertEqual(last_feedbackset_group2.last_updated_by, testuser) self.assertEqual('You have been given a new attempt.', group_comments[0].text) self.assertEqual('You have been given a new attempt.', group_comments[1].text)
def test_get_render_formfields(self): testperiod = mommy.make('core.Period', long_name='Test period', short_name='testperiod', start_time=ACTIVE_PERIOD_START, end_time=ACTIVE_PERIOD_END) mockresponse = self.mock_http200_getrequest_htmls( cradmin_role=testperiod) self.assertEqual( 'Test period', mockresponse.selector.one('input[name=long_name]')['value']) self.assertEqual( 'testperiod', mockresponse.selector.one('input[name=short_name]')['value']) self.assertEqual( datetimeutils.isoformat_withseconds(ACTIVE_PERIOD_START), mockresponse.selector.one('input[name=start_time]')['value']) self.assertEqual( datetimeutils.isoformat_withseconds(ACTIVE_PERIOD_END), mockresponse.selector.one('input[name=end_time]')['value'])
def test_post_new_attempt(self): testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start') testgroup1 = mommy.make('core.AssignmentGroup', parentnode=testassignment) group_mommy.feedbackset_first_attempt_published(group=testgroup1) testgroup2 = mommy.make('core.AssignmentGroup', parentnode=testassignment) group_mommy.feedbackset_first_attempt_published(group=testgroup2) testuser = self._get_admin_user(testassignment.parentnode) mommy.make('core.Examiner', assignmentgroup=testgroup1, relatedexaminer__user=testuser) mommy.make('core.Examiner', assignmentgroup=testgroup2, relatedexaminer__user=testuser) new_deadline = timezone.now() + timezone.timedelta(days=3) new_deadline = new_deadline.replace(microsecond=0) self.mock_postrequest( cradmin_role=testassignment, cradmin_instance=self._get_mock_instance(testassignment), cradmin_app=self._get_mock_app(user=testuser), requestuser=testuser, viewkwargs={ 'deadline': datetimeutils.datetime_to_url_string(testassignment.first_deadline), 'handle_deadline': 'new-attempt' }, requestkwargs={ 'data': { 'new_deadline': isoformat_withseconds(timezone.localtime(new_deadline)), 'comment_text': 'You have been given a new attempt.', 'selected_items': [testgroup1.id, testgroup2.id] } } ) self.assertEqual(4, group_models.FeedbackSet.objects.count()) self.assertEqual(2, group_models.GroupComment.objects.count()) group_comments = group_models.GroupComment.objects.all() last_feedbackset_group1 = AssignmentGroupCachedData.objects.get(group_id=testgroup1.id).last_feedbackset last_feedbackset_group2 = AssignmentGroupCachedData.objects.get(group_id=testgroup2.id).last_feedbackset self.assertEqual(last_feedbackset_group1.deadline_datetime, new_deadline) self.assertEqual(last_feedbackset_group2.deadline_datetime, new_deadline) self.assertEqual(last_feedbackset_group1.last_updated_by, testuser) self.assertEqual(last_feedbackset_group2.last_updated_by, testuser) self.assertEqual('You have been given a new attempt.', group_comments[0].text) self.assertEqual('You have been given a new attempt.', group_comments[1].text)
def __get_string_formatted_datetime(self, datetime_obj): return datetimeutils.isoformat_withseconds(datetime_obj)
def test_before_year_1900(self): self.assertEqual( '0030-12-24 14:30:12', datetimeutils.isoformat_withseconds(datetimeutils.default_timezone_datetime(30, 12, 24, 14, 30, 12)))
def test_sanity(self): self.assertEqual( '2015-12-24 17:42:12', datetimeutils.isoformat_withseconds(datetimeutils.default_timezone_datetime(2015, 12, 24, 17, 42, 12)))