Esempio n. 1
0
 def test_resource_as_function(self):
     bar = Bar(name=str(uuid.uuid4())[:8])
     bar.save()
     get_detail = self.factory.get('/{0}/{0}/'.format(
         bar.__class__.__name__, bar.id))
     response = self.resource_as_func.view(get_detail, *[], **{})
     self.assertEqual(response['success'], True)
 def test_get_resource_uri_pkfield_override(self):
     bar = Bar(name=str(uuid.uuid4())[:8])
     bar.save()
     resource_uri = self.resource._get_resource_uri(obj=bar)
     self.assertEqual(
         resource_uri,
         '/api/{0}/custom_pk/{1}/'.format(self.resource.Meta.api.name,
                                          bar.name))
    def test_add_resource_uri(self):
        bar = Bar(name='new bar')
        bar.save()
        kwargs = {
            'pub': ['get', 'list'],
            'bundles': [{
                'obj': bar,
                'response_data': {}
            }]
        }
        get_list = self.factory.get('/bar/')
        request, args, kwargs = self.resource.add_resource_uri(get_list, [], **kwargs)

        data = kwargs['bundles'][0]['response_data']
        self.assertEqual(data['resource_uri'], '/api/{0}/bar/{1}/'.format(self.resource.Meta.api.name, bar.pk))
    def test_add_resource_uri(self):
        bar = Bar(name='new bar')
        bar.save()
        kwargs = {
            'pub': ['get', 'list'],
            'bundles': [{
                'obj': bar,
                'response_data': {}
            }]
        }
        get_list = self.factory.get('/bar/')
        request, args, kwargs = self.resource.add_resource_uri(
            get_list, [], **kwargs)

        data = kwargs['bundles'][0]['response_data']
        self.assertEqual(
            data['resource_uri'],
            '/api/{0}/bar/{1}/'.format(self.resource.Meta.api.name, bar.pk))
 def test_update_objs_from_data_pkfield_override(self):
     bar = Bar( name=str( uuid.uuid4() )[:8] )
     bar.save()
     put_detail = self.factory.put('/custom_pk/{0}/'.format(bar.name), {})
     kwargs = {
         'pub': ['put', 'detail'],
         'bundles': [
             {
                 'obj': bar,
                 'request_data': {
                     'name': '{0}'.format(bar.name),
                     'resource_uri': '/api/v1/custom_pk/{0}'.format(bar.name),
                 }
             }
         ]
     }
     request, args, kwargs = self.resource.update_objs_from_data( put_detail, **kwargs )
     # if the above didn't raise an error on pkfield
     # lookup, then we are good, but assert name anyhow
     self.assertEqual(kwargs['bundles'][0]['obj'].name, '{0}'.format(bar.name))
 def test_update_objs_from_data_pkfield_override(self):
     bar = Bar(name=str(uuid.uuid4())[:8])
     bar.save()
     put_detail = self.factory.put('/custom_pk/{0}/'.format(bar.name), {})
     kwargs = {
         'pub': ['put', 'detail'],
         'bundles': [{
             'obj': bar,
             'request_data': {
                 'name': '{0}'.format(bar.name),
                 'resource_uri': '/api/v1/custom_pk/{0}'.format(bar.name),
             }
         }]
     }
     request, args, kwargs = self.resource.update_objs_from_data(
         put_detail, **kwargs)
     # if the above didn't raise an error on pkfield
     # lookup, then we are good, but assert name anyhow
     self.assertEqual(kwargs['bundles'][0]['obj'].name,
                      '{0}'.format(bar.name))
 def test_get_resource_uri_pkfield_override(self):
     bar = Bar( name=str( uuid.uuid4() )[:8] )
     bar.save()
     resource_uri = self.resource._get_resource_uri( obj=bar )
     self.assertEqual(resource_uri, '/api/{0}/custom_pk/{1}/'.format(self.resource.Meta.api.name, bar.name))
 def test_resource_as_mixin(self):
     bar = Bar( name=str( uuid.uuid4() )[:8] )  
     bar.save()
     get_detail = self.factory.get('/{0}/{0}/'.format(bar.__class__.__name__,bar.id))
     response = self.resource_as_mixin.view( get_detail, *[], **{} )
     self.assertEqual(response['success'], True)