def test_get_suggested_deadlines_render_values_previous_deadline_in_the_past(self):
        period = mommy.make_recipe('devilry.apps.core.period_active')

        # Ignored by the suggestion system
        mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start',
                          parentnode=period)

        # This should be the one that is used for suggestions
        mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start',
                          parentnode=period,
                          first_deadline=default_timezone_datetime(2015, 9, 2, 13, 30))  # Wed

        timezonemock = mock.MagicMock()
        timezonemock.now.return_value = default_timezone_datetime(2015, 9, 10, 22, 18)  # Thursday
        with mock.patch('devilry.devilry_admin.views.period.createassignment.timezone', timezonemock):
            mockresponse = self.mock_http200_getrequest_htmls(
                cradmin_role=period)
        suggested_deadline_elements = mockresponse.selector.list(
            '.devilry-admin-createassignment-suggested-deadline')
        suggested_deadline_values = [element['django-cradmin-setfieldvalue']
                                     for element in suggested_deadline_elements]
        self.assertEqual(suggested_deadline_values, [
            '2015-09-16 13:30',
            '2015-09-23 13:30',
            '2015-09-30 13:30',
            '2015-10-07 13:30',
        ])
    def test_get_suggested_deadlines_render_labels(self):
        period = mommy.make_recipe('devilry.apps.core.period_active')

        # Ignored by the suggestion system
        mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start',
                          parentnode=period)

        # This should be the one that is used for suggestions
        mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start',
                          parentnode=period,
                          first_deadline=default_timezone_datetime(3500, 9, 5, 13, 30))

        with self.settings(DATETIME_FORMAT='D M j Y H:i', USE_L10N=False):
            mockresponse = self.mock_http200_getrequest_htmls(
                cradmin_role=period)
        suggested_deadline_elements = mockresponse.selector.list(
            '.devilry-admin-createassignment-suggested-deadline')
        suggested_deadline_labels = [element.alltext_normalized
                                     for element in suggested_deadline_elements]
        self.assertEqual([
            'Wed Sep 12 3500 13:30',
            'Wed Sep 19 3500 13:30',
            'Wed Sep 26 3500 13:30',
            'Wed Oct 3 3500 13:30',
        ], suggested_deadline_labels)
Example #3
0
 def test_published_row_buttons_when_already_published(self):
     assignment = mommy.make('core.Assignment', publishing_time=default_timezone_datetime(2000, 1, 1))
     mockresponse = self.mock_http200_getrequest_htmls(cradmin_role=assignment)
     self.assertFalse(
         mockresponse.selector.exists(
             "#devilry_admin_assignment_published_publishnow_form")
     )
Example #4
0
 def test_published_row_buttons_when_already_published(self):
     assignment = mommy.make('core.Assignment', publishing_time=default_timezone_datetime(2000, 1, 1))
     mockresponse = self.mock_http200_getrequest_htmls(cradmin_role=assignment)
     self.assertFalse(
         mockresponse.selector.exists(
             "#devilry_admin_assignment_published_publishnow_form")
     )
Example #5
0
 def test_settings_row_first_deadline_description(self):
     assignment = mommy.make('core.Assignment', first_deadline=default_timezone_datetime(2000, 1, 1))
     mockresponse = self.mock_http200_getrequest_htmls(cradmin_role=assignment)
     self.assertEqual(
         mockresponse.selector.one(
             '#devilry_admin_assignment_overview_settings_first_deadline p').alltext_normalized,
         "The first deadline is Saturday January 1, 2000, 00:00. This deadline is common for all "
         "students unless a new deadline have been provided to a group.")
Example #6
0
 def test_settings_row_first_deadline_description(self):
     assignment = mommy.make('core.Assignment', first_deadline=default_timezone_datetime(2000, 1, 1))
     mockresponse = self.mock_http200_getrequest_htmls(cradmin_role=assignment)
     self.assertEqual(
         mockresponse.selector.one(
             '#devilry_admin_assignment_overview_settings_first_deadline p').alltext_normalized,
         "The first deadline is Saturday January 1, 2000, 00:00. This deadline is common for all "
         "students unless a new deadline have been provided to a group.")
Example #7
0
 def test_published_row_published_time_in_future(self):
     assignment = mommy.make('core.Assignment',
                             publishing_time=default_timezone_datetime(
                                 3000, 1, 1))
     mockresponse = self.mock_http200_getrequest_htmls(
         cradmin_role=assignment)
     self.assertEqual(
         mockresponse.selector.one(
             '#devilry_admin_assignment_overview_published h3').
         alltext_normalized, "Will be published: Jan 1 3000, 00:00")
Example #8
0
 def test_published_row_buttons(self):
     assignment = mommy.make('core.Assignment', publishing_time=default_timezone_datetime(3000, 1, 1))
     mockresponse = self.mock_http200_getrequest_htmls(cradmin_role=assignment)
     self.assertEqual(
         mockresponse.selector.one(
             '#devilry_admin_assignment_published_publishnow_form input[type="submit"]')['value'],
         'Publish now'
     )
     self.assertEqual(
         mockresponse.selector.one(
             "#devilry_admin_assignment_published_buttonrow a").alltext_normalized,
         'Edit publishing time'
     )
Example #9
0
 def test_published_row_buttons(self):
     assignment = mommy.make('core.Assignment', publishing_time=default_timezone_datetime(3000, 1, 1))
     mockresponse = self.mock_http200_getrequest_htmls(cradmin_role=assignment)
     self.assertEqual(
         mockresponse.selector.one(
             '#devilry_admin_assignment_published_publishnow_form input[type="submit"]')['value'],
         'Publish now'
     )
     self.assertEqual(
         mockresponse.selector.one(
             "#devilry_admin_assignment_published_buttonrow a").alltext_normalized,
         'Edit publishing time'
     )
    def test_get_suggested_deadlines_render_values_previous_deadline_in_the_future(self):
        period = mommy.make_recipe('devilry.apps.core.period_active')

        # Ignored by the suggestion system
        mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start',
                          parentnode=period)

        # This should be the one that is used for suggestions
        mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start',
                          parentnode=period,
                          first_deadline=default_timezone_datetime(3500, 9, 5, 13, 30))

        mockresponse = self.mock_http200_getrequest_htmls(
            cradmin_role=period)
        suggested_deadline_elements = mockresponse.selector.list(
            '.devilry-admin-createassignment-suggested-deadline')
        suggested_deadline_values = [element['django-cradmin-setfieldvalue']
                                     for element in suggested_deadline_elements]
        self.assertEqual(suggested_deadline_values, [
            '3500-09-12 13:30',
            '3500-09-19 13:30',
            '3500-09-26 13:30',
            '3500-10-03 13:30',
        ])
Example #11
0
 def test_sanity(self):
     self.assertEqual(
         '2015-12-24 17:42',
         datetimeutils.isoformat_noseconds(datetimeutils.default_timezone_datetime(2015, 12, 24, 17, 42)))
Example #12
0
 def test_target_weekday_same_as_source(self):
     self.assertEqual(
         datetimeutils.default_timezone_datetime(2015, 9, 30, 12, 30),  # Wed week after target
         datetimeutils.datetime_with_same_day_of_week_and_time(
             weekdayandtimesource_datetime=datetimeutils.default_timezone_datetime(2015, 9, 16, 12, 30),  # Wed
             target_datetime=datetimeutils.default_timezone_datetime(2015, 9, 23, 0, 0)))   # Wed
Example #13
0
 def test_target_weekday_larger_than_source_test2(self):
     self.assertEqual(
         datetimeutils.default_timezone_datetime(2015, 9, 29, 12, 30),  # Tue week after target
         datetimeutils.datetime_with_same_day_of_week_and_time(
             weekdayandtimesource_datetime=datetimeutils.default_timezone_datetime(2015, 9, 15, 12, 30),  # Tue
             target_datetime=datetimeutils.default_timezone_datetime(2015, 9, 23, 0, 0)))   # Wed
Example #14
0
 def test_target_weekday_smaller_than_source(self):
     self.assertEqual(
         datetimeutils.default_timezone_datetime(2015, 9, 25, 12, 30),  # Fri same week as target
         datetimeutils.datetime_with_same_day_of_week_and_time(
             weekdayandtimesource_datetime=datetimeutils.default_timezone_datetime(2015, 9, 18, 12, 30),  # Fri
             target_datetime=datetimeutils.default_timezone_datetime(2015, 9, 23, 0, 0)))   # Wed
Example #15
0
 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)))
Example #16
0
 def test_published_row_published_time_in_future(self):
     assignment = mommy.make('core.Assignment', publishing_time=default_timezone_datetime(3000, 1, 1))
     mockresponse = self.mock_http200_getrequest_htmls(cradmin_role=assignment)
     self.assertEqual(
         mockresponse.selector.one('#devilry_admin_assignment_overview_published h3').alltext_normalized,
         "Will be published: Jan 1 3000, 00:00")
Example #17
0
from model_mommy import recipe

from devilry.apps.core.models import Period, Assignment
#: The ``start_time`` of the period created by the :obj:`.period_old` recipe.
from devilry.utils.datetimeutils import default_timezone_datetime

#
#
# Constants for old periods and assignments
#
#

OLD_PERIOD_START = default_timezone_datetime(1000, 1, 1, 0, 0)

#: The ``end_time`` of the period created by the :obj:`.period_old` recipe.
OLD_PERIOD_END = default_timezone_datetime(1999, 12, 31, 23, 59)

#: The ``first_deadline`` of the assignment created by the
#: :obj:`.assignment_activeperiod_start`.
ASSIGNMENT_OLDPERIOD_START_FIRST_DEADLINE = default_timezone_datetime(1000, 1, 15, 23, 59)

#: The ``publishing_time`` of the assignment created by the
#: :obj:`.assignment_oldperiod_end`.
ASSIGNMENT_OLDPERIOD_MIDDLE_PUBLISHING_TIME = default_timezone_datetime(1500, 1, 1, 0, 0)

#: The ``publishing_time`` of the assignment created by the
#: :obj:`.assignment_oldperiod_end`.
ASSIGNMENT_OLDPERIOD_MIDDLE_FIRST_DEADLINE = default_timezone_datetime(1500, 1, 15, 23, 59)

#: The ``publishing_time`` of the assignment created by the
#: :obj:`.assignment_oldperiod_end`.