示例#1
0
    def test_timestamp_in_dataclass(self):
        @dataclass(repr=False)
        class C(SerialisableDataclass):
            v: Timestamp

        c = C(Timestamp.from_string('2019-01-01T12:00:00Z'))
        with self.subTest('No conversion in asdict'):
            self.assertIsInstance(c.asdict()['v'], Timestamp)
        with self.subTest('Conversion in str'):
            self.assertEqual(str(c), '{"v": "2019-01-01T12:00:00Z"}')
示例#2
0
    def __post_init__(self):
        self.added_at = Timestamp.from_string(self.added_at)
        self.added_by = PublicUser(**self.added_by)

        if self.video_thumbnail is not None:
            self.video_thumbnail = Image(**self.video_thumbnail)

        if self.track is not None:
            if self.is_local:
                self.track = LocalTrack(**self.track)
            else:
                self.track = FullTrack(**self.track)
示例#3
0
    def __post_init__(self):
        self.track = FullTrack(**self.track)
        self.played_at = Timestamp.from_string(self.played_at)

        if self.context is not None:
            self.context = Context(**self.context)
示例#4
0
 def __post_init__(self):
     self.added_at = Timestamp.from_string(self.added_at)
     self.show = SimpleShow(**self.show)
示例#5
0
 def __post_init__(self):
     self.added_at = Timestamp.from_string(self.added_at)
     self.album = FullAlbum(**self.album)
示例#6
0
 def __post_init__(self):
     self.added_at = Timestamp.from_string(self.added_at)
     self.track = FullTrack(**self.track)
示例#7
0
 def test_initialisable_with_millisecond_precision(self):
     Timestamp.from_string('2019-01-01T12:00:00.00Z')
示例#8
0
 def test_timestamp_formatted_back_to_string(self):
     time_str = '2019-01-01T12:00:00Z'
     t = Timestamp.from_string(time_str)
     self.assertEqual(str(t), time_str)
示例#9
0
 def test_incorrect_format_raises(self):
     with self.assertRaises(ValueError):
         Timestamp.from_string('2019-01-01')
示例#10
0
 def test_timestamp_initialisable_from_string(self):
     Timestamp.from_string('2019-01-01T12:00:00Z')
示例#11
0
    def test_timestamp_encoded_is_quoted_str(self):
        t = Timestamp.from_string('2019-01-01T12:00:00Z')
        encoded = JSONEncoder().encode(t)

        self.assertEqual(encoded, f'"{str(t)}"')