コード例 #1
0
    def test_serialize__pickle(self):
        """
        Tests that serialized videos can be pickled and unpickled.

        """
        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()
        new_data = pickle.loads(pickle.dumps(data, pickle.HIGHEST_PROTOCOL))
        self.assertEqual(new_data, data)
コード例 #2
0
    def test_serialize__json(self):
        """
        Tests that serialized videos can be transformed to and from json.

        """
        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()
        new_data = json.loads(json.dumps(data))
        self.assertEqual(new_data, data)
コード例 #3
0
    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()))
コード例 #4
0
    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()))