Example #1
0
 def macro(self, content, arguments, page_url, alternative):
     if arguments is None:
         tm = None
     else:
         stamp = arguments[0]
         tm = self.parse_time(stamp)
     return show_time.format_date(tm)
Example #2
0
    def test_macro(self):
        flaskg.user.valid = True  # show_time creates ISO 8601 dates if user is not logged in
        flaskg.user.timezone = 'GMT'
        flaskg.user.locale = 'en'
        flaskg.user.iso_8601 = False

        macro_obj = Macro()
        # when arguments is None
        result = macro_obj.macro('content', None, 'page_url', 'alternative')
        test_time = time.time()
        test_time = format_date(datetime.utcfromtimestamp(test_time))
        assert result == test_time

        arguments = ['2011-08-07T11:11:11+0533', 'argument2']
        result = macro_obj.macro('content', arguments, 'page_url',
                                 'alternative')
        expected = 'Aug 7, 2011'
        assert result == expected

        flaskg.user.timezone = 'UTC'
        flaskg.user.iso_8601 = True
        result = macro_obj.macro('content', arguments, 'page_url',
                                 'alternative')
        expected = '2011-08-07z'
        assert result == expected

        flaskg.user.timezone = 'US/Arizona'
        result = macro_obj.macro('content', arguments, 'page_url',
                                 'alternative')
        expected = '2011-08-07'
        assert result == expected
Example #3
0
 def test_show_time_datetime(self):
     """ users who are not logged-in get ISO 8601 Zulu dates """
     formatted_date = show_time.format_date(utc_dt=0)
     assert formatted_date == '1970-01-01z'
     formatted_time = show_time.format_time(utc_dt=0)
     assert formatted_time == '00:00:00z'
     formatted_date_time = show_time.format_date_time(utc_dt=0)
     assert formatted_date_time == '1970-01-01 00:00:00z'
Example #4
0
 def test_show_time_datetime_logged_in_local(self):
     """users who are logged-in, unchecked ISO-8601 get dates based on locale and timezone"""
     flaskg.user.valid = True
     flaskg.user.locale = 'en'
     flaskg.user.iso_8601 = False
     flaskg.user.timezone = 'US/Arizona'
     formatted_date = show_time.format_date(utc_dt=0)
     assert formatted_date == 'Dec 31, 1969'
     formatted_time = show_time.format_time(utc_dt=0)
     assert formatted_time == '5:00:00 PM'
     formatted_date_time = show_time.format_date_time(utc_dt=0)
     assert formatted_date_time == 'Dec 31, 1969, 5:00:00 PM'
Example #5
0
 def test_show_time_datetime_logged_in_utc(self):
     """users who are logged-in, selected UTC timezone and checked ISO-8601 get ISO 8601 Zulu dates"""
     flaskg.user.valid = True
     flaskg.user.timezone = 'UTC'
     flaskg.user.locale = 'en'
     flaskg.user.iso_8601 = True
     formatted_date = show_time.format_date(utc_dt=0)
     assert formatted_date == '1970-01-01z'
     formatted_time = show_time.format_time(utc_dt=0)
     assert formatted_time == '00:00:00z'
     formatted_date_time = show_time.format_date_time(utc_dt=0)
     assert formatted_date_time == '1970-01-01 00:00:00z'