def test_resource_fetch(self, mock_session):
        mock_session.configure_mock(base_url=self.BASE)

        mock_session.fqname_to_id.side_effect = HttpError(http_status=404)
        r = Resource('foo', fq_name='domain:bar:foo')
        with self.assertRaises(ResourceNotFound):
            r.fetch()

        mock_session.fqname_to_id.side_effect = [
            "07eeb3c0-42f5-427c-9409-6ae45b376aa2"
        ]
        mock_session.get_json.return_value = {
            'foo': {
                'uuid': '07eeb3c0-42f5-427c-9409-6ae45b376aa2',
                'fq_name': ['domain', 'bar', 'foo']
            }
        }
        r = Resource('foo', fq_name='domain:bar:foo')
        r.fetch()
        self.assertEqual(r.uuid, '07eeb3c0-42f5-427c-9409-6ae45b376aa2')
        mock_session.get_json.assert_called_with(r.href)

        r.fetch(exclude_children=True)
        mock_session.get_json.assert_called_with(r.href, exclude_children=True)

        r.fetch(exclude_back_refs=True)
        mock_session.get_json.assert_called_with(r.href,
                                                 exclude_back_refs=True)
Esempio n. 2
0
 def post(url, json):
     if json['uuid'] == 'a5a1b67b-4246-4e2d-aa24-479d8d47435d':
         return {
             'type': 'foo_bar',
             'fq_name': ['domain', 'foo', 'uuid']
         }
     else:
         raise HttpError(http_status=404)
 def post(url, data=None, headers=None):
     data = json.loads(data)
     result = mock.Mock()
     if data['type'] == "foo":
         result.json.return_value = {
             "uuid": "ec1afeaa-8930-43b0-a60a-939f23a50724"
         }
         return result
     if data['type'] == "bar":
         raise HttpError(http_status=404)
Esempio n. 4
0
    def test_resource_check(self, mock_session):
        mock_session.configure_mock(base_url=BASE)

        mock_session.id_to_fqname.side_effect = HttpError()
        r = Resource('bar', uuid='57ef609c-6c9b-4b91-a542-26c61420c37b')
        self.assertFalse(r.exists)

        mock_session.id_to_fqname.side_effect = [FQName('domain:bar')]
        r = Resource('bar', uuid='57ef609c-6c9b-4b91-a542-26c61420c37b')
        self.assertTrue(r.exists)

        mock_session.fqname_to_id.side_effect = HttpError()
        r = Resource('bar', fq_name='domain:foo')
        self.assertFalse(r.exists)

        mock_session.fqname_to_id.side_effect = [
            '588e1a17-ae50-4b67-8078-95f061d833ca'
        ]
        self.assertTrue(r.exists)
    def test_not_found(self, mock_session):
        mock_session.id_to_fqname.side_effect = HttpError(http_status=404)
        mock_document = mock.Mock()
        mock_document.get_word_before_cursor.return_value = 'foo'
        mock_document.configure_mock(text='ls foo')

        comp = ShellCompleter()
        try:
            Resource('foo', uuid='dda4574d-96bc-43fd-bdf7-12ac776f754c', check=True)
        except ResourceNotFound:
            pass
        completions = list(comp.get_completions(mock_document, None))
        self.assertEqual(len(completions), 0)
    def test_not_found(self, mock_session):
        mock_session.id_to_fqname.side_effect = HttpError(http_status=404)
        mock_document = Document(text='cat foo')

        comp = ShellCompleter()
        try:
            Resource('foo',
                     uuid='dda4574d-96bc-43fd-bdf7-12ac776f754c',
                     check=True)
        except ResourceNotFound:
            pass
        completions = list(comp.get_completions(mock_document, None))
        self.assertEqual(len(completions), 0)
    def test_resource_parent(self, mock_session):
        mock_session.configure_mock(base_url=self.BASE)

        p = Resource('bar', uuid='57ef609c-6c9b-4b91-a542-26c61420c37b')
        r = Resource('foo', fq_name='domain:foo', parent=p)
        self.assertEqual(p, r.parent)

        mock_session.id_to_fqname.side_effect = HttpError(http_status=404)
        with self.assertRaises(ResourceNotFound):
            p = Resource('foobar', uuid='1fe29f52-28dc-44a5-90d0-43de1b02cbd8')
            Resource('foo', fq_name='domain:foo', parent=p)

        with self.assertRaises(ResourceMissing):
            r = Resource('foo', fq_name='domain:foo')
            r.parent
 def test_collection_not_found(self, mock_session):
     mock_session.get_json.side_effect = HttpError(http_status=404)
     with self.assertRaises(CollectionNotFound):
         Collection('foo', fetch=True)