How to use the rbtools.api.factory.create_resource function in RBTools

To help you get started, we’ve selected a few RBTools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github reviewboard / rbtools / rbtools / api / tests.py View on Github external
def test_no_token_guessing(self):
        """Testing constructing without guessing the resource token"""
        r = create_resource(self.transport, self.item_payload, '',
                            guess_token=False)
        self.assertTrue('resource_token' in r)
        self.assertTrue('field1' not in r)
        self.assertTrue('field1' in r.resource_token)

        r = create_resource(self.transport, self.list_payload, '',
                            guess_token=False)
        self.assertTrue('resource_token' in r)
github reviewboard / rbtools / rbtools / api / tests.py View on Github external
def test_extra_data_rewriting_create(self):
        """Testing rewriting of extra_data__ parameters to create"""
        r = create_resource(self.transport, self.list_payload, '')
        request = r.create(extra_data__foo='bar')
        self.assertTrue('extra_data.foo' in request._fields)
        self.assertEqual(request._fields['extra_data.foo'], 'bar')
github reviewboard / rbtools / rbtools / api / tests.py View on Github external
def test_resource_specific_base_class(self):
        """Testing constructing a resource with a specific base class"""
        r = create_resource(self.transport, self.root_payload, '')
        self.assertFalse(isinstance(r, RootResource))
        r = create_resource(
            self.transport,
            self.root_payload,
            '',
            mime_type='application/vnd.reviewboard.org.root+json')
        self.assertTrue(isinstance(r, RootResource))
github reviewboard / rbtools / rbtools / api / tests.py View on Github external
def test_resource_dict_field_iteration(self):
        """Testing iterating sub-fields of a dictionary field"""
        r = create_resource(self.transport, self.item_payload, '')

        field = r.nested_field
        iterated_fields = set(f for f in field.iterfields())
        nested_fields = set(
            f for f in self.item_payload['resource_token']['nested_field'])

        self.assertEqual(set(),
                         nested_fields.symmetric_difference(iterated_fields))
github reviewboard / rbtools / rbtools / api / tests.py View on Github external
def test_extra_data_rewriting_update(self):
        """Testing rewriting of exta_data__ parameters to update"""
        r = create_resource(self.transport, self.item_payload, '')
        request = r.update(extra_data__foo='bar')
        self.assertTrue('extra_data.foo' in request._fields)
        self.assertEqual(request._fields['extra_data.foo'], 'bar')
github reviewboard / rbtools / rbtools / api / tests.py View on Github external
def test_item_resource_links(self):
        """Testing item resource link generation"""
        r = create_resource(self.transport, self.item_payload, '')

        self.assertTrue(hasattr(r, 'get_self'))
        self.assertTrue(callable(r.get_self))
        request = r.get_self()
        self.assertTrue(isinstance(request, HttpRequest))
        self.assertEqual(request.method, 'GET')
        self.assertEqual(request.url,
                         self.item_payload['links']['self']['href'])

        self.assertTrue(hasattr(r, 'update'))
        self.assertTrue(callable(r.update))
        request = r.update()
        self.assertTrue(isinstance(request, HttpRequest))
        self.assertEqual(request.method, 'PUT')
        self.assertEqual(request.url,
                         self.item_payload['links']['update']['href'])
github reviewboard / rbtools / rbtools / api / tests.py View on Github external
def test_resource_dict_field(self):
        """Testing access of a dictionary field"""
        r = create_resource(self.transport, self.item_payload, '')

        field = r.nested_field

        self.assertTrue(isinstance(field, ResourceDictField))
        self.assertEqual(
            field.nested1,
            self.item_payload['resource_token']['nested_field']['nested1'])
github reviewboard / rbtools / rbtools / api / tests.py View on Github external
def test_getattr_with_expanded_list_resource(self):
        """Testing ItemResource.__getattr__ with field as expanded list
        resource
        """
        r = create_resource(transport=self.transport,
                            payload=self.expanded_list_payload,
                            url='')

        self.assertIsInstance(r['list1'], ResourceListField)
        self.assertIsInstance(r['list1'][0], ExpandedItemResource)
        self.assertIsInstance(r['list2'], ResourceListField)
        self.assertIsInstance(r['list2'][0], ResourceDictField)
        self.assertIsInstance(r['other-list'], ResourceListField)
        self.assertIsInstance(r['other-list'][0], ResourceDictField)
github reviewboard / rbtools / rbtools / api / transport / sync.py View on Github external
logging.debug('Making HTTP %s request to %s' % (request.method,
                                                        request.url))

        rsp = self.server.make_request(request)
        info = rsp.info()
        mime_type = info['Content-Type']
        item_content_type = info.get('Item-Content-Type', None)

        if request.method == 'DELETE':
            # DELETE calls don't return any data. Everything else should.
            return None
        else:
            payload = rsp.read()
            payload = decode_response(payload, mime_type)

            return create_resource(self, payload, request.url,
                                   mime_type=mime_type,
                                   item_mime_type=item_content_type)
github reviewboard / rbtools / rbtools / api / resource.py View on Github external
def __getitem__(self, key):
        payload = self._item_list[key]

        # TODO: Should try and guess the url based on the parent url,
        # and the id number if the self link doesn't exist.
        try:
            url = payload['links']['self']['href']
        except KeyError:
            url = ''

        # We need to import this here because of the mutual imports.
        from rbtools.api.factory import create_resource

        return create_resource(self._transport,
                               payload,
                               url,
                               mime_type=self._item_mime_type,
                               guess_token=False)