Skip to content
This repository has been archived by the owner on Mar 28, 2021. It is now read-only.

Commit

Permalink
test twitter.process_extended_attributes()
Browse files Browse the repository at this point in the history
  • Loading branch information
thraxil committed Feb 21, 2016
1 parent 6dcdefb commit 58e04b2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Empty file.
50 changes: 50 additions & 0 deletions spokehub/twitter/tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import unittest
from spokehub.twitter import process_extended_attributes


class Dummy(object):
pass


class MockNP(object):
def __init__(self):
self.saved = False

def save(self):
self.saved = True


class TestProcessExtendedAttributes(unittest.TestCase):
def test_no_ext_entities(self):
m = MockNP()
process_extended_attributes(None, m)
self.assertFalse(m.saved)

def test_no_media(self):
m = MockNP()
ee = dict()
d = Dummy()
d.extended_entities = ee
process_extended_attributes(d, m)
self.assertFalse(m.saved)
ee = dict(media=[])
d.extended_entities = ee
process_extended_attributes(d, m)
self.assertFalse(m.saved)

def test_with_media(self):
ee = dict(
media=[
{
'media_url': 'test',
'sizes': {'large': {'w': 400, 'h': 500}}
}
])
d = Dummy()
d.extended_entities = ee
m = MockNP()
process_extended_attributes(d, m)
self.assertTrue(m.saved)
self.assertEqual(m.image_url, 'test')
self.assertEqual(m.image_width, 400)
self.assertEqual(m.image_height, 500)

0 comments on commit 58e04b2

Please sign in to comment.