示例#1
0
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>')
示例#3
0
 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': {}
         })
示例#4
0
 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)
示例#5
0
 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': {}})
示例#6
0
 def test_as_json(self):
     entity = SirenEntity(['blah'], [])
     json_string = entity.as_json()
     self.assertIsInstance(json_string, six.string_types)
示例#7
0
 def test_get_primary_classname(self):
     entity = SirenEntity(['blah'], None)
     self.assertEqual(entity.get_primary_classname(), 'blah')
示例#8
0
 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'])
示例#9
0
 def test_get_entity_no_entities(self):
     entity = SirenEntity(['blah'], None)
     self.assertEqual(entity.get_entities('sakdf'), [])
示例#10
0
 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'), [])
示例#11
0
 def test_get_link_no_links(self):
     entity = SirenEntity(['blah'], None)
     self.assertIsNone(entity.get_links('sakdf'))
示例#12
0
 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'), [])
示例#13
0
 def test_as_python_object(self):
     entity = SirenEntity(['blah'], [])
     siren_class = entity.as_python_object()
     self.assertTrue(hasattr(siren_class, 'get_entities'))
示例#14
0
 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'])
示例#15
0
 def test_get_primary_classname(self):
     entity = SirenEntity(['blah'], None)
     self.assertEqual(entity.get_primary_classname(), 'blah')
示例#16
0
 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'), [])
示例#17
0
 def test_get_entity_no_entities(self):
     entity = SirenEntity(['blah'], None)
     self.assertEqual(entity.get_entities('sakdf'), [])
示例#18
0
 def test_as_json(self):
     entity = SirenEntity(['blah'], [])
     json_string = entity.as_json()
     self.assertIsInstance(json_string, six.string_types)
示例#19
0
 def test_as_python_object(self):
     entity = SirenEntity(['blah'], [])
     siren_class = entity.as_python_object()
     self.assertTrue(hasattr(siren_class, 'get_entities'))
示例#20
0
 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'), [])
示例#21
0
 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'), [])