def test_items(self): video = Video("http://www.youtube.com/watch?v=J_DV9b0x7v4") # Make sure items can be iterated over and that there's one # for every field. for i, item in enumerate(video.items()): self.assertEqual(item[0], Video._all_fields[i])
def test_serialize__files(self): """ Tests that a video with associated files can still be serialized and deserialized. """ video = Video("http://www.youtube.com/watch?v=J_DV9b0x7v4") now = datetime.datetime.now() video.files = [VideoFile(url='http://google.com', expires=now, length=100, width=50, height=50, mime_type="video/x-flv"), VideoFile(url='http://xkcd.com', expires=now, length=75, width=80, height=80, mime_type="application/x-shockwave-flash"),] data = video.serialize() # verify that the data we expect is in the serialized version. self.assertEqual(data['files'][0]['url'], "http://google.com") self.assertEqual(data['files'][1]['mime_type'], "application/x-shockwave-flash") self.assertEqual(data['files'][0]['expires'], now.isoformat()) # Verify that the data can be deserialized as a video. new_video = Video.deserialize(data) self.assertEqual(dict(video.items()), dict(new_video.items()))
def test_items_with_fields(self): fields = ['title', 'user'] video = Video("http://www.youtube.com/watch?v=J_DV9b0x7v4", fields=fields) # Make sure items can be iterated over and that there's one # for every field. for i, item in enumerate(video.items()): self.assertEqual(item[0], fields[i])
def test_serialize(self): video = Video("http://www.youtube.com/watch?v=J_DV9b0x7v4") # we load the video data this way to avoid depending on the network video_data = CARAMELL_DANSEN_API_DATA.copy() video_data['tags'] = list(video_data['tags']) video._apply(video_data) data = video.serialize() # verify that the data we expect is in the serialized version. self.assertEqual(data['url'], video.url) self.assertEqual(data['title'], video.title) self.assertEqual(data['publish_datetime'], video.publish_datetime.isoformat()) # Verify that the data can be deserialized as a video. new_video = Video.deserialize(data) self.assertEqual(video.url, new_video.url) self.assertEqual(dict(video.items()), dict(new_video.items()))
def test_serialize__partial(self): """ Tests that a video with only some fields can still be serialized and deserialized. """ video = Video("http://www.youtube.com/watch?v=J_DV9b0x7v4", fields=('title', 'embed_code')) # we load the video data this way to avoid depending on the network video_data = CARAMELL_DANSEN_API_DATA.copy() video._apply(video_data) data = video.serialize() # verify that the data we expect is in the serialized version. self.assertEqual(data['url'], video.url) self.assertEqual(data['title'], video.title) self.assertEqual(data['embed_code'], video.embed_code) # Verify that the data can be deserialized as a video. new_video = Video.deserialize(data) self.assertEqual(video.url, new_video.url) self.assertEqual(dict(video.items()), dict(new_video.items()))