def test_api_calls(self): network = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY) cursor = CursorFactory.get_personal_stream_cursor(network, self.USER_ID) cursor.next_items() json = cursor.previous_items() self.assertTrue(json)
def test_build_collection_types(self): site = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY).get_site(self.SITE_ID, self.SITE_KEY) collection = site.build_comments_collection(self.TITLE, self.ARTICLE_ID, self.URL) self.assertTrue(collection) self.assertEquals(collection.data.type, CollectionType.COMMENTS) collection = site.build_chat_collection(self.TITLE, self.ARTICLE_ID, self.URL) self.assertTrue(collection) self.assertEquals(collection.data.type, CollectionType.CHAT) collection = site.build_blog_collection(self.TITLE, self.ARTICLE_ID, self.URL) self.assertTrue(collection) self.assertEquals(collection.data.type, CollectionType.BLOG) collection = site.build_counting_collection(self.TITLE, self.ARTICLE_ID, self.URL) self.assertTrue(collection) self.assertEquals(collection.data.type, CollectionType.COUNTING) collection = site.build_ratings_collection(self.TITLE, self.ARTICLE_ID, self.URL) self.assertTrue(collection) self.assertEquals(collection.data.type, CollectionType.RATINGS) collection = site.build_reviews_collection(self.TITLE, self.ARTICLE_ID, self.URL) self.assertTrue(collection) self.assertEquals(collection.data.type, CollectionType.REVIEWS) collection = site.build_sidenotes_collection(self.TITLE, self.ARTICLE_ID, self.URL) self.assertTrue(collection) self.assertEquals(collection.data.type, CollectionType.SIDENOTES) collection = site.build_collection(CollectionType.COMMENTS, self.TITLE, self.ARTICLE_ID, self.URL) self.assertTrue(collection) self.assertEquals(collection.data.type, CollectionType.COMMENTS)
def test_build_cursor(self): network = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY) date = datetime.datetime.now() cursor = TimelineCursor(network, CursorData("resource", 50, date)) self.assertTrue(cursor) cursor.data.set_cursor_time(date) self.assertTrue(cursor.data.cursor_time) if pyver < 2.7: pass elif pyver < 3.0: with self.assertRaisesRegexp(AssertionError, 'resource is missing'): TimelineCursor.init(network, None, 50, datetime.datetime.now()) with self.assertRaisesRegexp(AssertionError, 'limit is missing'): TimelineCursor.init(network, 'resource', None, datetime.datetime.now()) with self.assertRaisesRegexp(AssertionError, 'cursor_time is missing'): TimelineCursor.init(network, 'resource', 50, None) else: with self.assertRaisesRegex(AssertionError, 'resource is missing'): TimelineCursor.init(network, None, 50, datetime.datetime.now()) with self.assertRaisesRegex(AssertionError, 'limit is missing'): TimelineCursor.init(network, 'resource', None, datetime.datetime.now()) with self.assertRaisesRegex(AssertionError, 'cursor_time is missing'): TimelineCursor.init(network, 'resource', 50, None)
def test_personal_stream_cursor(self): network = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY) date = datetime.datetime.now() ps_resource = 'urn:livefyre:{0}:user={1}:personalStream'.format(network.data.name, self.USER_ID) cursor = CursorFactory.get_personal_stream_cursor(network, self.USER_ID) self.assertEqual(ps_resource, cursor.data.resource) cursor = CursorFactory.get_personal_stream_cursor(network, self.USER_ID, self.LIMIT, date) self.assertEqual(ps_resource, cursor.data.resource) self.assertEqual(self.LIMIT, cursor.data.limit)
def test_set_user_sync_url(self): network = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY) if pyver < 2.7: pass elif pyver < 3.0: with self.assertRaisesRegexp(AssertionError, 'url_template should have {id}.'): network.set_user_sync_url('http://thisisa.test.url/') else: with self.assertRaisesRegex(AssertionError, 'url_template should have {id}.'): network.set_user_sync_url('http://thisisa.test.url/') network.set_user_sync_url('http://answers.livefyre.com/{id}') network.sync_user('user')
def test_topic_stream_cursor(self): network = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY) date = datetime.datetime.now() topic_id = 'topic' label = 'label' ts_resource = 'urn:livefyre:{0}:topic={1}:topicStream'.format(network.data.name, topic_id) topic = Topic.create(network, topic_id, label) cursor = CursorFactory.get_topic_stream_cursor(network, topic) self.assertEqual(ts_resource, cursor.data.resource) cursor = CursorFactory.get_topic_stream_cursor(network, topic, self.LIMIT, date) self.assertEqual(ts_resource, cursor.data.resource) self.assertEqual(self.LIMIT, cursor.data.limit)
def test_func(self): topic = Topic(self.ID, self.LABEL, self.CREATED_AT, self.MODIFIED_AT) self.assertEqual(self.DICT, topic.to_dict()) topic2 = Topic.serialize_from_json(self.DICT) self.assertEqual(self.ID, topic2.topic_id) self.assertEqual(self.LABEL, topic2.label) self.assertEqual(self.CREATED_AT, topic2.created_at) self.assertEqual(self.MODIFIED_AT, topic2.modified_at) topic3 = json.dumps(topic2) self.assertEqual(json.dumps(self.DICT), topic3) topic = topic.create(Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY), "ID", "LABEL") self.assertEqual(topic.truncated_id, "ID")
def test_build_collection__fail(self): site = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY).get_site(self.SITE_ID, self.SITE_KEY) if pyver < 2.7: pass elif pyver < 3.0: with self.assertRaisesRegexp(AssertionError, 'url must be a full domain. ie. http://livefyre.com'): site.build_comments_collection('title', 'articleId', 'url.com') with self.assertRaisesRegexp(AssertionError, 'title\'s length should be under 255 char'): site.build_comments_collection('1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456', 'article_id', 'http://url.com') else: with self.assertRaisesRegex(AssertionError, 'url must be a full domain. ie. http://livefyre.com'): site.build_comments_collection('title', 'articleId', 'url.com') with self.assertRaisesRegex(AssertionError, 'title\'s length should be under 255 char'): site.build_comments_collection('1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456', 'article_id', 'http://url.com') if pyver >= 2.7: with self.assertRaises(AssertionError): site.build_collection('bad type', self.TITLE, self.ARTICLE_ID, self.URL)
def test_build_site(self): network = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY) data = SiteData(self.SITE_ID, self.SITE_KEY) site = Site(network, data) self.assertEquals(network, site.network) self.assertEquals(data, site.data) Site.init(network, self.SITE_ID, self.SITE_KEY) if pyver < 2.7: pass elif pyver < 3.0: with self.assertRaisesRegexp(AssertionError, 'id is missing'): Site.init(network, None, self.SITE_KEY) with self.assertRaisesRegexp(AssertionError, 'key is missing'): Site.init(network, self.SITE_ID, None) else: with self.assertRaisesRegex(AssertionError, 'id is missing'): Site.init(network, None, self.SITE_KEY) with self.assertRaisesRegex(AssertionError, 'key is missing'): Site.init(network, self.SITE_ID, None)
def test_build_validate_user_token(self): network = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY) if pyver < 2.7: pass elif pyver < 3.0: with self.assertRaisesRegexp(AssertionError, 'userId is not alphanumeric\. Ensure the following regex pattern is respected \^\[a\-zA\-Z0\-9\_\\\.\-\]\+\$'): network.build_user_auth_token('system@blah', 'testName', 86400.0) with self.assertRaisesRegexp(AssertionError, 'expires should be a number'): network.build_user_auth_token('blah', 'blah', '100') else: with self.assertRaisesRegex(AssertionError, 'userId is not alphanumeric\. Ensure the following regex pattern is respected \^\[a\-zA\-Z0\-9\_\\\.\-\]\+\$'): network.build_user_auth_token('system@blah', 'testName', 86400.0) with self.assertRaisesRegex(AssertionError, 'expires should be a number'): network.build_user_auth_token('blah', 'blah', '100') token = network.build_livefyre_token() self.assertTrue(token) self.assertTrue(network.validate_livefyre_token(token))
def setUp(self): super(PersonalizedStreamsTestCase, self).setUp() self.network = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY) self.site = self.network.get_site(self.SITE_ID, self.SITE_KEY)
def setUp(self): super(DomainTestCase, self).setUp() self.network = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY) self.site = self.network.get_site(self.SITE_ID, self.SITE_KEY) self.collection = self.site.build_comments_collection("TITLE", self.ARTICLE_ID, self.URL)
def test_get_urn(self): site = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY).get_site(self.SITE_ID, self.SITE_KEY) self.assertEquals(site.network.urn+':site='+self.SITE_ID, site.urn)
def test_urn(self): network = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY) self.assertEquals('urn:livefyre:'+self.NETWORK_NAME, network.urn) self.assertEquals(network.urn+':user='+self.USER_ID, network.get_urn_for_user(self.USER_ID))
def setUp(self): super(CollectionTestCase, self).setUp() self.network = Livefyre.get_network(self.NETWORK_NAME, self.NETWORK_KEY) self.site = self.network.get_site(self.SITE_ID, self.SITE_KEY)