Пример #1
0
def test_get_time_pass_through():
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=UTC)
    assert_equals("Mar 12, 1992 at 15:03 UTC", get_time_display(test_time))
    assert_equals("Mar 12, 1992 at 15:03 UTC",
                  get_time_display(test_time, None))
    assert_equals("Mar 12, 1992 at 15:03 UTC",
                  get_time_display(test_time, "%"))
Пример #2
0
def test_get_time_display():
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=UTC)
    assert_equals("dummy text", get_time_display(test_time, 'dummy text'))
    assert_equals("Mar 12 1992", get_time_display(test_time, '%b %d %Y'))
    assert_equals("Mar 12 1992 UTC", get_time_display(test_time,
                                                      '%b %d %Y %Z'))
    assert_equals("Mar 12 15:03", get_time_display(test_time, '%b %d %H:%M'))
 def _now_formatted_date(self):
     """Retrieve the formatted current date. """
     return get_time_display(
         datetime.datetime.now(UTC),
         DEFAULT_SHORT_DATE_FORMAT,
         settings.TIME_ZONE
     )
Пример #4
0
    def test_gitlog_date(self):
        """
        Make sure the date is timezone-aware and being converted/formatted
        properly.
        """

        tz_names = [
            'America/New_York',  # UTC - 5
            'Asia/Pyongyang',    # UTC + 9
            'Europe/London',     # UTC
            'Canada/Yukon',      # UTC - 8
            'Europe/Moscow',     # UTC + 4
        ]
        tz_format = DEFAULT_DATE_TIME_FORMAT

        self._setstaff_login()
        self._mkdir(settings.GIT_REPO_DIR)

        self._add_edx4edx()
        date = CourseImportLog.objects.first().created.replace(tzinfo=UTC)

        for timezone in tz_names:
            with (override_settings(TIME_ZONE=timezone)):
                date_text = get_time_display(date, tz_format, settings.TIME_ZONE)
                response = self.client.get(reverse('gitlogs'))
                self.assertIn(date_text, response.content.decode('UTF-8'))

        self._rm_edx4edx()
Пример #5
0
    def test_save_valid_data(self):
        user = UserFactory.create(is_staff=True, is_superuser=True)
        user.save()
        course = CourseFactory.create()
        expiration = datetime(2015, 10, 20, 1, 10, 23, tzinfo=timezone(settings.TIME_ZONE))

        data = {
            'course_id': unicode(course.id),
            'mode_slug': 'professional',
            'mode_display_name': 'professional',
            'min_price': 10,
            'currency': 'usd',
            'expiration_datetime_0': expiration.date(),  # due to django admin datetime widget passing as seperate vals
            'expiration_datetime_1': expiration.time(),

        }

        self.client.login(username=user.username, password='******')

        # creating new course mode from django admin page
        response = self.client.post(reverse('admin:course_modes_coursemode_add'), data=data)
        self.assertRedirects(response, reverse('admin:course_modes_coursemode_changelist'))

        # verifying that datetime is appearing on list page
        response = self.client.get(reverse('admin:course_modes_coursemode_changelist'))
        self.assertContains(response, get_time_display(expiration, '%B %d, %Y, %H:%M  %p'))

        # verifiying the on edit page datetime value appearing without any modifications
        resp = self.client.get(reverse('admin:course_modes_coursemode_change', args=(1,)))
        self.assertContains(resp, expiration.date())
        self.assertContains(resp, expiration.time())

        # checking the values in db. comparing values without tzinfo
        course_mode = CourseMode.objects.get(pk=1)
        self.assertEqual(course_mode.expiration_datetime.replace(tzinfo=None), expiration.replace(tzinfo=None))
Пример #6
0
    def test_save_valid_data(self):
        user = UserFactory.create(is_staff=True, is_superuser=True)
        user.save()
        course = CourseFactory.create()
        expiration = datetime(2015, 10, 20, 1, 10, 23, tzinfo=timezone(settings.TIME_ZONE))

        data = {
            'course_id': unicode(course.id),
            'mode_slug': 'professional',
            'mode_display_name': 'professional',
            'min_price': 10,
            'currency': 'usd',
            'expiration_datetime_0': expiration.date(),  # due to django admin datetime widget passing as seperate vals
            'expiration_datetime_1': expiration.time(),

        }

        self.client.login(username=user.username, password='******')

        # creating new course mode from django admin page
        response = self.client.post(reverse('admin:course_modes_coursemode_add'), data=data)
        self.assertRedirects(response, reverse('admin:course_modes_coursemode_changelist'))

        # verifying that datetime is appearing on list page
        response = self.client.get(reverse('admin:course_modes_coursemode_changelist'))
        self.assertContains(response, get_time_display(expiration, '%B %d, %Y, %H:%M  %p'))

        # verifiying the on edit page datetime value appearing without any modifications
        resp = self.client.get(reverse('admin:course_modes_coursemode_change', args=(1,)))
        self.assertContains(resp, expiration.date())
        self.assertContains(resp, expiration.time())

        # checking the values in db. comparing values without tzinfo
        course_mode = CourseMode.objects.get(pk=1)
        self.assertEqual(course_mode.expiration_datetime.replace(tzinfo=None), expiration.replace(tzinfo=None))
Пример #7
0
    def test_gitlog_date(self):
        """
        Make sure the date is timezone-aware and being converted/formatted
        properly.
        """

        tz_names = [
            'America/New_York',  # UTC - 5
            'Asia/Pyongyang',  # UTC + 9
            'Europe/London',  # UTC
            'Canada/Yukon',  # UTC - 8
            'Europe/Moscow',  # UTC + 4
        ]
        tz_format = DEFAULT_DATE_TIME_FORMAT

        self._setstaff_login()
        self._mkdir(getattr(settings, 'GIT_REPO_DIR'))

        self._add_edx4edx()
        date = CourseImportLog.objects.first().created.replace(tzinfo=UTC)

        for timezone in tz_names:
            with (override_settings(TIME_ZONE=timezone)):
                date_text = get_time_display(date, tz_format,
                                             settings.TIME_ZONE)
                response = self.client.get(reverse('gitlogs'))
                self.assertIn(date_text, response.content.decode('UTF-8'))

        self._rm_edx4edx()
 def _now_formatted_date(self):
     """Retrieve the formatted current date. """
     return get_time_display(
         datetime.datetime.now(UTC),
         DEFAULT_SHORT_DATE_FORMAT,
         settings.TIME_ZONE
     )
Пример #9
0
    def test_expiration_timezone(self):
        # Test that expiration datetimes are saved and retrieved with the timezone set to UTC.
        # This verifies the fix for a bug in which the date displayed to users was different
        # than the date in Django admin.
        user = UserFactory.create(is_staff=True, is_superuser=True)
        user.save()
        course = CourseFactory.create()
        expiration = datetime(2015,
                              10,
                              20,
                              1,
                              10,
                              23,
                              tzinfo=timezone(settings.TIME_ZONE))
        CourseOverview.load_from_module_store(course.id)

        data = {
            'course': six.text_type(course.id),
            'mode_slug': 'verified',
            'mode_display_name': 'verified',
            'min_price': 10,
            'currency': 'usd',
            '_expiration_datetime_0': expiration.date(
            ),  # due to django admin datetime widget passing as separate vals
            '_expiration_datetime_1': expiration.time(),
        }

        self.client.login(username=user.username, password='******')

        # Create a new course mode from django admin page
        response = self.client.post(
            reverse('admin:course_modes_coursemode_add'), data=data)
        self.assertRedirects(
            response, reverse('admin:course_modes_coursemode_changelist'))

        # Verify that datetime is appears on list page
        response = self.client.get(
            reverse('admin:course_modes_coursemode_changelist'))
        self.assertContains(
            response, get_time_display(expiration, '%B %d, %Y, %H:%M  %p'))

        # Verify that on the edit page the datetime value appears as UTC.
        course_mode = CourseMode.objects.last()
        resp = self.client.get(
            reverse('admin:course_modes_coursemode_change',
                    args=(course_mode.id, )))
        self.assertContains(resp, expiration.date())
        self.assertContains(resp, expiration.time())

        # Verify that the expiration datetime is the same as what we set
        # (hasn't changed because of a timezone translation).
        self.assertEqual(course_mode.expiration_datetime.replace(tzinfo=None),
                         expiration.replace(tzinfo=None))
Пример #10
0
def test_get_time_display_coerce():
    test_time_standard = datetime(1992, 1, 12, 15, 3, 30, tzinfo=UTC)
    test_time_daylight = datetime(1992, 7, 12, 15, 3, 30, tzinfo=UTC)
    assert_equals(
        "Jan 12, 1992 at 07:03 PST",
        get_time_display(test_time_standard, None, coerce_tz="US/Pacific"))
    assert_equals(
        "Jan 12, 1992 at 15:03 UTC",
        get_time_display(test_time_standard, None, coerce_tz="NONEXISTENTTZ"))
    assert_equals(
        "Jan 12 07:03",
        get_time_display(test_time_standard,
                         '%b %d %H:%M',
                         coerce_tz="US/Pacific"))
    assert_equals(
        "Jul 12, 1992 at 08:03 PDT",
        get_time_display(test_time_daylight, None, coerce_tz="US/Pacific"))
    assert_equals(
        "Jul 12, 1992 at 15:03 UTC",
        get_time_display(test_time_daylight, None, coerce_tz="NONEXISTENTTZ"))
    assert_equals(
        "Jul 12 08:03",
        get_time_display(test_time_daylight,
                         '%b %d %H:%M',
                         coerce_tz="US/Pacific"))
Пример #11
0
def test_get_time_display_coerce():
    test_time_standard = datetime(1992, 1, 12, 15, 3, 30, tzinfo=utc)
    test_time_daylight = datetime(1992, 7, 12, 15, 3, 30, tzinfo=utc)
    assert get_time_display(test_time_standard, None, coerce_tz="US/Pacific") == "Jan 12, 1992 at 07:03 PST"
    assert get_time_display(test_time_standard, None, coerce_tz="NONEXISTENTTZ") == "Jan 12, 1992 at 15:03 UTC"
    assert get_time_display(test_time_standard, '%b %d %H:%M', coerce_tz="US/Pacific") == "Jan 12 07:03"
    assert get_time_display(test_time_daylight, None, coerce_tz="US/Pacific") == "Jul 12, 1992 at 08:03 PDT"
    assert get_time_display(test_time_daylight, None, coerce_tz="NONEXISTENTTZ") == "Jul 12, 1992 at 15:03 UTC"
    assert get_time_display(test_time_daylight, '%b %d %H:%M', coerce_tz="US/Pacific") == "Jul 12 08:03"
Пример #12
0
    def test_expiration_timezone(self):
        # Test that expiration datetimes are saved and retrieved with the timezone set to UTC.
        # This verifies the fix for a bug in which the date displayed to users was different
        # than the date in Django admin.
        user = UserFactory.create(is_staff=True, is_superuser=True)
        user.save()
        course = CourseFactory.create()
        expiration = datetime(2015, 10, 20, 1, 10, 23, tzinfo=timezone(settings.TIME_ZONE))

        data = {
            'course_id': unicode(course.id),
            'mode_slug': 'verified',
            'mode_display_name': 'verified',
            'min_price': 10,
            'currency': 'usd',
            'expiration_datetime_0': expiration.date(),  # due to django admin datetime widget passing as seperate vals
            'expiration_datetime_1': expiration.time(),

        }

        self.client.login(username=user.username, password='******')

        # Create a new course mode from django admin page
        response = self.client.post(reverse('admin:course_modes_coursemode_add'), data=data)
        self.assertRedirects(response, reverse('admin:course_modes_coursemode_changelist'))

        # Verify that datetime is appears on list page
        response = self.client.get(reverse('admin:course_modes_coursemode_changelist'))
        self.assertContains(response, get_time_display(expiration, '%B %d, %Y, %H:%M  %p'))

        # Verify that on the edit page the datetime value appears as UTC.
        resp = self.client.get(reverse('admin:course_modes_coursemode_change', args=(1,)))
        self.assertContains(resp, expiration.date())
        self.assertContains(resp, expiration.time())

        # Verify that the expiration datetime is the same as what we set
        # (hasn't changed because of a timezone translation).
        course_mode = CourseMode.objects.get(pk=1)
        self.assertEqual(course_mode.expiration_datetime.replace(tzinfo=None), expiration.replace(tzinfo=None))
Пример #13
0
def test_get_time_disp_ret_empty():
    assert get_time_display(None) == ""
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=utc)
    assert get_time_display(test_time, "") == ""
Пример #14
0
def test_get_time_disp_ret_empty():
    assert_equals("", get_time_display(None))
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=utc)
    assert_equals("", get_time_display(test_time, ""))
Пример #15
0
def test_get_time_display():
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=utc)
    assert get_time_display(test_time, 'dummy text') == "dummy text"
    assert get_time_display(test_time, '%b %d %Y') == "Mar 12 1992"
    assert get_time_display(test_time, '%b %d %Y %Z') == "Mar 12 1992 UTC"
    assert get_time_display(test_time, '%b %d %H:%M') == "Mar 12 15:03"
Пример #16
0
def test_get_time_disp_ret_empty():
    assert get_time_display(None) == ""
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=utc)
    assert get_time_display(test_time, "") == ""
Пример #17
0
def test_get_time_pass_through():
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=utc)
    assert_equals("Mar 12, 1992 at 15:03 UTC", get_time_display(test_time))
    assert_equals("Mar 12, 1992 at 15:03 UTC", get_time_display(test_time, None))
    assert_equals("Mar 12, 1992 at 15:03 UTC", get_time_display(test_time, "%"))
Пример #18
0
def test_get_time_display():
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=utc)
    assert_equals("dummy text", get_time_display(test_time, 'dummy text'))
    assert_equals("Mar 12 1992", get_time_display(test_time, '%b %d %Y'))
    assert_equals("Mar 12 1992 UTC", get_time_display(test_time, '%b %d %Y %Z'))
    assert_equals("Mar 12 15:03", get_time_display(test_time, '%b %d %H:%M'))
Пример #19
0
 def expiration_datetime_custom(self, obj):
     """adding custom column to show the expiry_datetime"""
     if obj.expiration_datetime:
         return get_time_display(obj.expiration_datetime,
                                 '%B %d, %Y, %H:%M  %p')
Пример #20
0
def test_get_time_disp_ret_empty():
    assert_equals("", get_time_display(None))
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=UTC)
    assert_equals("", get_time_display(test_time, ""))
Пример #21
0
def test_get_time_pass_through():
    test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=utc)
    assert get_time_display(test_time) == "Mar 12, 1992 at 15:03 UTC"
    assert get_time_display(test_time, None) == "Mar 12, 1992 at 15:03 UTC"
    assert get_time_display(test_time, "%") == "Mar 12, 1992 at 15:03 UTC"
Пример #22
0
 def expiration_datetime_custom(self, obj):
     """adding custom column to show the expiry_datetime"""
     if obj.expiration_datetime:
         return get_time_display(obj.expiration_datetime, '%B %d, %Y, %H:%M  %p')