Пример #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>')
Пример #2
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>')
Пример #3
0
 def test_as_python_object(self):
     entity = SirenEntity(['blah'], [])
     siren_class = entity.as_python_object()
     self.assertTrue(hasattr(siren_class, 'get_entities'))
Пример #4
0
 def test_as_python_object(self):
     entity = SirenEntity(['blah'], [])
     siren_class = entity.as_python_object()
     self.assertTrue(hasattr(siren_class, 'get_entities'))