def test_as_python_object(): """Integration test of using hard-coded siren to create the hypermedia rest-client. This will attempt to contact the url.""" base_url = 'http://127.0.0.1:5000/codex/views' classnames = ['view'] properties = {'view_id': '1', 'url': 'http://slashdot.org', 'time_fetched': '1409067477'} actions = [SirenAction(name='update-view', href='{}/1/'.format(base_url), type='application/json', fields=[{'type': 'text', 'name': 'url'}, {"type": "text","name": "time_fetched"},], title=None, method='PUT'), SirenAction(name='create-view', href=base_url, type='application/json', fields=[{'type': 'text', 'name': 'url'}, {"type": "text", "name": "time_fetched"},], title=None, method='POST'),] links = [SirenLink(rel=['self'], href='http://127.0.0.1/views/1')] so = SirenEntity(classnames=classnames, properties=properties, actions=actions, links=links) view = so.as_python_object() assert type(view).__name__ == 'view' assert view.view_id == '1' assert view.url == 'http://slashdot.org' assert view.time_fetched == '1409067477' view.update_view(url='blank', time_fetched='2014-08-26 14:05:26', body='<html>TEST</html>')
def test_as_python_object(): """Integration test of using hard-coded siren to create the hypermedia rest-client. This will attempt to contact the url.""" base_url = 'http://127.0.0.1:5000/codex/views' classnames = ['view'] properties = { 'view_id': '1', 'url': 'http://slashdot.org', 'time_fetched': '1409067477' } actions = [ SirenAction(name='update-view', href='{}/1/'.format(base_url), type='application/json', fields=[ { 'type': 'text', 'name': 'url' }, { "type": "text", "name": "time_fetched" }, ], title=None, method='PUT'), SirenAction(name='create-view', href=base_url, type='application/json', fields=[ { 'type': 'text', 'name': 'url' }, { "type": "text", "name": "time_fetched" }, ], title=None, method='POST'), ] links = [SirenLink(rel=['self'], href='http://127.0.0.1/views/1')] so = SirenEntity(classnames=classnames, properties=properties, actions=actions, links=links) view = so.as_python_object() assert type(view).__name__ == 'view' assert view.view_id == '1' assert view.url == 'http://slashdot.org' assert view.time_fetched == '1409067477' view.update_view(url='blank', time_fetched='2014-08-26 14:05:26', body='<html>TEST</html>')
def test_as_siren(self): entity = SirenEntity(['blah'], []) siren_dict = entity.as_siren() self.assertIsInstance(siren_dict, dict) self.assertDictEqual( siren_dict, { 'class': ['blah'], 'links': [], 'entities': [], 'actions': [], 'properties': {} })
def test_create_python_method_name(self): original_expected = [ ('original', 'original',), ('original func', 'originalfunc',), ('original-func', 'original_func',), ('%bd#$%#$)@c', 'bdc'), ] for original, expected in original_expected: actual = SirenEntity._create_python_method_name(original) self.assertEqual(actual, expected)
def test_as_siren(self): entity = SirenEntity(['blah'], []) siren_dict = entity.as_siren() self.assertIsInstance(siren_dict, dict) self.assertDictEqual(siren_dict, {'class': ['blah'], 'links': [], 'entities': [], 'actions': [], 'properties': {}})
def test_as_json(self): entity = SirenEntity(['blah'], []) json_string = entity.as_json() self.assertIsInstance(json_string, six.string_types)
def test_get_primary_classname(self): entity = SirenEntity(['blah'], None) self.assertEqual(entity.get_primary_classname(), 'blah')
def test_get_base_classnames(self): entity = SirenEntity(['blah'], None) self.assertListEqual(entity.get_base_classnames(), []) entity = SirenEntity(['blah', 'second'], None) self.assertListEqual(entity.get_base_classnames(), ['second'])
def test_get_entity_no_entities(self): entity = SirenEntity(['blah'], None) self.assertEqual(entity.get_entities('sakdf'), [])
def test_get_entities(self): ent = mock.Mock(rel=['myrel']) entity = SirenEntity(['blah'], [ent]) resp = entity.get_links('myrel') self.assertEqual([ent], resp) self.assertEqual(entity.get_entities('badrel'), [])
def test_get_link_no_links(self): entity = SirenEntity(['blah'], None) self.assertIsNone(entity.get_links('sakdf'))
def test_get_link(self): link = mock.Mock(rel=['myrel']) entity = SirenEntity(['blah'], [link]) resp = entity.get_links('myrel') self.assertEqual([link], resp) self.assertListEqual(entity.get_links('badrel'), [])
def test_as_python_object(self): entity = SirenEntity(['blah'], []) siren_class = entity.as_python_object() self.assertTrue(hasattr(siren_class, 'get_entities'))
def test_get_entities(self): ent = SirenEntity(['blah'], [], rel=['myrel']) entity = SirenEntity(['builderah'], [], entities=[ent]) resp = entity.get_entities('myrel') self.assertEqual([ent], resp) self.assertEqual(entity.get_entities('badrel'), [])