def test_make_images_creates_attribute(self): # Expect that make_images will create an attribute with key name result = GiphyImage() img = {'original': FAKE_DATA['images']['original']} assert not hasattr(result, 'original') result._make_images(img) assert hasattr(result, 'original')
def test_make_images_creates_subattr(self): result = GiphyImage() img = {'fixed_width': FAKE_DATA['images']['fixed_width'], 'fixed_width_still': FAKE_DATA['images']['fixed_width_still']} assert not hasattr(result, 'fixed_width') result._make_images(img) assert hasattr(result, 'fixed_width') assert hasattr(result.fixed_width, 'still')
def test_make_images_doesnt_subattr(self): # If there is a single underscore, don't subattr result = GiphyImage() img = {'fixed_width': FAKE_DATA['images']['fixed_width']} assert not hasattr(result, 'fixed') assert not hasattr(result, 'fixed_width') result._make_images(img) assert not hasattr(result, 'fixed') assert hasattr(result, 'fixed_width')
def test_normalize(self): result = GiphyImage() norm = result._normalized({ 'width': '200', 'height': 300, 'something': 'foo', 'frames': '100', 'size': '1234567890' }) assert isinstance(norm['width'], int) assert isinstance(norm['height'], int) assert isinstance(norm['frames'], int) assert isinstance(norm['size'], int) assert isinstance(norm['something'], str)
def test_original_properties(self): result = GiphyImage() img = {'original': FAKE_DATA['images']['original']} props = { 'media_url': 'url', 'frames': 'frames', 'width': 'width', 'height': 'height', 'filesize': 'size' } for prop in props: self.assertRaises(AttributeError, lambda: getattr(result, prop)) result._make_images(img) for prop, attr in props.items(): assert getattr(result, prop) == getattr(result.original, attr)