def test_format_datetime(self):
        serializer = Serializer()
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')

        serializer = Serializer(datetime_formatting='iso-8601')
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')

        serializer = Serializer(datetime_formatting='iso-8601-strict')
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33, 10)), '2010-12-16T02:31:33')

        serializer = Serializer(datetime_formatting='rfc-2822')
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u'Thu, 16 Dec 2010 02:31:33 -0600')

        serializer = Serializer(datetime_formatting='random-garbage')
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')

        with self.settings(TASTYPIE_DATETIME_FORMATTING='iso-8601'):
            serializer = Serializer()
            self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')

        with self.settings(TASTYPIE_DATETIME_FORMATTING='iso-8601-strict'):
            serializer = Serializer()
            self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33, 10)), '2010-12-16T02:31:33')

        with self.settings(TASTYPIE_DATETIME_FORMATTING='rfc-2822'):
            serializer = Serializer()
            self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u'Thu, 16 Dec 2010 02:31:33 -0600')

        with self.settings(TASTYPIE_DATETIME_FORMATTING='random-garbage'):
            serializer = Serializer()
            self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
Esempio n. 2
0
    def test_format_datetime(self):
        serializer = Serializer()
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')

        serializer = Serializer(datetime_formatting='iso-8601')
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')

        serializer = Serializer(datetime_formatting='rfc-2822')
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u'Thu, 16 Dec 2010 02:31:33 -0600')

        serializer = Serializer(datetime_formatting='random-garbage')
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')

        # Stow.
        old_format = getattr(settings, 'TASTYPIE_DATETIME_FORMATTING', 'iso-8601')

        settings.TASTYPIE_DATETIME_FORMATTING = 'iso-8601'
        serializer = Serializer()
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')

        settings.TASTYPIE_DATETIME_FORMATTING = 'rfc-2822'
        serializer = Serializer()
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u'Thu, 16 Dec 2010 02:31:33 -0600')

        settings.TASTYPIE_DATETIME_FORMATTING = 'random-garbage'
        serializer = Serializer()
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')

        # Restore.
        settings.TASTYPIE_DATETIME_FORMATTING = old_format
Esempio n. 3
0
 def test_format_datetime(self):
     serializer = Serializer()
     self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
     
     serializer = Serializer(datetime_formatting='iso-8601')
     self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
     
     serializer = Serializer(datetime_formatting='rfc-2822')
     self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u'Thu, 16 Dec 2010 02:31:33 -0600')
     
     serializer = Serializer(datetime_formatting='random-garbage')
     self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
     
     # Stow.
     old_format = getattr(settings, 'TASTYPIE_DATETIME_FORMATTING', 'iso-8601')
     
     settings.TASTYPIE_DATETIME_FORMATTING = 'iso-8601'
     serializer = Serializer()
     self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
     
     settings.TASTYPIE_DATETIME_FORMATTING = 'rfc-2822'
     serializer = Serializer()
     self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u'Thu, 16 Dec 2010 02:31:33 -0600')
     
     settings.TASTYPIE_DATETIME_FORMATTING = 'random-garbage'
     serializer = Serializer()
     self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), '2010-12-16T02:31:33')
     
     # Restore.
     settings.TASTYPIE_DATETIME_FORMATTING = old_format
Esempio n. 4
0
    def test_format_datetime(self):
        serializer = Serializer()
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), "2010-12-16T02:31:33")

        serializer = Serializer(datetime_formatting="iso-8601")
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), "2010-12-16T02:31:33")

        serializer = Serializer(datetime_formatting="rfc-2822")
        self.assertEqual(
            serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u"Thu, 16 Dec 2010 02:31:33 -0600"
        )

        serializer = Serializer(datetime_formatting="random-garbage")
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), "2010-12-16T02:31:33")

        # Stow.
        old_format = getattr(settings, "TASTYPIE_DATETIME_FORMATTING", "iso-8601")

        settings.TASTYPIE_DATETIME_FORMATTING = "iso-8601"
        serializer = Serializer()
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), "2010-12-16T02:31:33")

        settings.TASTYPIE_DATETIME_FORMATTING = "rfc-2822"
        serializer = Serializer()
        self.assertEqual(
            serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), u"Thu, 16 Dec 2010 02:31:33 -0600"
        )

        settings.TASTYPIE_DATETIME_FORMATTING = "random-garbage"
        serializer = Serializer()
        self.assertEqual(serializer.format_datetime(datetime.datetime(2010, 12, 16, 2, 31, 33)), "2010-12-16T02:31:33")

        # Restore.
        settings.TASTYPIE_DATETIME_FORMATTING = old_format
Esempio n. 5
0
 def convert_date_time_to_tastypie(self, dt):
     serializer = Serializer()
     return serializer.format_datetime(dt)