コード例 #1
0
ファイル: siren.py プロジェクト: timmartin19/pypermedia
 def test_add_rel(self):
     link = SirenLink(['blah'], 'blah')
     self.assertListEqual(link.rel, ['blah'])
     link.add_rel('two')
     self.assertListEqual(['blah', 'two'], link.rel)
     link.add_rel('two')
     self.assertListEqual(['blah', 'two'], link.rel)
コード例 #2
0
ファイル: siren.py プロジェクト: timmartin19/pypermedia
 def test_as_python_object(self):
     """
     Mostly just an explosion test.
     """
     link = SirenLink('blah', 'blah')
     with mock.patch.object(link, 'make_request') as make_request:
         with mock.patch.object(link, 'from_api_response') as from_api_respons:
             resp = link.as_python_object()
             self.assertEqual(make_request.call_count, 1)
             self.assertEqual(from_api_respons.call_count, 1)
コード例 #3
0
 def test_as_python_object(self):
     """
     Mostly just an explosion test.
     """
     link = SirenLink('blah', 'blah')
     with mock.patch.object(link, 'make_request') as make_request:
         with mock.patch.object(link,
                                'from_api_response') as from_api_respons:
             resp = link.as_python_object()
             self.assertEqual(make_request.call_count, 1)
             self.assertEqual(from_api_respons.call_count, 1)
コード例 #4
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>')
コード例 #5
0
 def test_add_rel(self):
     link = SirenLink(['blah'], 'blah')
     self.assertListEqual(link.rel, ['blah'])
     link.add_rel('two')
     self.assertListEqual(['blah', 'two'], link.rel)
     link.add_rel('two')
     self.assertListEqual(['blah', 'two'], link.rel)
コード例 #6
0
ファイル: siren.py プロジェクト: timmartin19/pypermedia
 def test_make_request(self):
     link = SirenLink(['blah'], 'http://notreal.com')
     session = mock.MagicMock()
     resp = link.make_request(_session=session)
     self.assertEqual(session.send.call_count, 1)
コード例 #7
0
ファイル: siren.py プロジェクト: timmartin19/pypermedia
 def test_as_request(self):
     href = 'http://notreal.com/'
     link = SirenLink(['blah'], 'http://notreal.com')
     req = link.as_request()
     self.assertIsInstance(req, PreparedRequest)
     self.assertEqual(href, req.url)
コード例 #8
0
ファイル: siren.py プロジェクト: timmartin19/pypermedia
 def test_as_json(self):
     link = SirenLink(['blah'], 'href')
     self.assertIsInstance(link.as_json(), six.string_types)
コード例 #9
0
ファイル: siren.py プロジェクト: timmartin19/pypermedia
 def test_as_siren(self):
     link = SirenLink(['blah'], 'href')
     self.assertDictEqual(link.as_siren(), dict(rel=['blah'], href='href'))
コード例 #10
0
ファイル: siren.py プロジェクト: timmartin19/pypermedia
 def test_rem_rel(self):
     link = SirenLink(['blah'], 'blah')
     link.rem_rel('notreal')
     self.assertListEqual(link.rel, ['blah'])
     link.rem_rel('blah')
     self.assertListEqual(link.rel, [])
コード例 #11
0
 def test_make_request(self):
     link = SirenLink(['blah'], 'http://notreal.com')
     session = mock.MagicMock()
     resp = link.make_request(_session=session)
     self.assertEqual(session.send.call_count, 1)
コード例 #12
0
 def test_as_request(self):
     href = 'http://notreal.com/'
     link = SirenLink(['blah'], 'http://notreal.com')
     req = link.as_request()
     self.assertIsInstance(req, PreparedRequest)
     self.assertEqual(href, req.url)
コード例 #13
0
 def test_as_json(self):
     link = SirenLink(['blah'], 'href')
     self.assertIsInstance(link.as_json(), six.string_types)
コード例 #14
0
 def test_as_siren(self):
     link = SirenLink(['blah'], 'href')
     self.assertDictEqual(link.as_siren(), dict(rel=['blah'], href='href'))
コード例 #15
0
 def test_rem_rel(self):
     link = SirenLink(['blah'], 'blah')
     link.rem_rel('notreal')
     self.assertListEqual(link.rel, ['blah'])
     link.rem_rel('blah')
     self.assertListEqual(link.rel, [])
コード例 #16
0
 def test_init_rel_string(self):
     siren_link = SirenLink('blah', 'href')
     self.assertEqual(['blah'], siren_link.rel)