Example #1
0
 def setUp(self):
     self.site = ResourceSite()
     self.site.register_builtin_media_types()
     
     self.user = User.objects.get_or_create(username='******', is_staff=True, is_active=True, is_superuser=True)[0]
     self.resource = self.register_resource()
     
     self.factory = SuperUserRequestFactory(user=self.user, HTTP_ACCEPT='text/html')
     
     self.resolver = GenericURLResolver(r'^', self.site.get_urls())
     
     self.patch_reverse(self.resolver)
Example #2
0
 def setUp(self):
     self.site = ResourceSite()
     self.site.register_builtin_media_types()
     
     self.user = User.objects.get_or_create(username='******', is_staff=True, is_active=True, is_superuser=True)[0]
     self.resource = self.register_resource()
     self.factory = SuperUserRequestFactory(user=self.user, HTTP_ACCEPT='application/vnd.Collection+JSON')
     
     self.resolver = GenericURLResolver(r'^', self.site.get_urls())
     
     def reverse(name, *args, **kwargs):
         ret = self.resolver.reverse(name, *args, **kwargs)
         return ret
     
     self.site.reverse = reverse
class ResourceTestCase(unittest.TestCase):
    def setUp(self):
        self.site = ResourceSite()
        self.site.register_builtin_media_types()
        
        self.user = User.objects.get_or_create(username='******', is_staff=True, is_active=True, is_superuser=True)[0]
        self.resource = self.register_resource()
        
        self.factory = SuperUserRequestFactory(user=self.user, HTTP_ACCEPT='text/html')
        
        self.resolver = GenericURLResolver(r'^', self.site.get_urls())
        
        def reverse(name, *args, **kwargs):
            ret = self.resolver.reverse(name, *args, **kwargs)
            return ret
        
        original_fork = self.site.fork
        
        def fork(**kwargs):
            ret = original_fork(**kwargs)
            ret.reverse = reverse
            return ret
        
        self.site.fork = fork
        self.site.reverse = reverse
    
    def get_api_request(self, **kwargs):
        kwargs.setdefault('site', self.site)
        kwargs.setdefault('user', self.user)
        kwargs.setdefault('params', {})
        kwargs.setdefault('method', 'GET')
        kwargs.setdefault('payload', {})
        kwargs.setdefault('request', self.factory.get('/'))
        api_request = InternalAPIRequest(**kwargs)
        
        api_request.generate_response = MagicMock(return_value=HttpResponse())
        
        return api_request
    
    def register_resource(self):
        raise NotImplementedError
 def setUp(self):
     self.site = ResourceSite()
     self.site.register_builtin_media_types()
     
     self.user = User.objects.get_or_create(username='******', is_staff=True, is_active=True, is_superuser=True)[0]
     self.resource = self.register_resource()
     
     self.factory = SuperUserRequestFactory(user=self.user, HTTP_ACCEPT='text/html')
     
     self.resolver = GenericURLResolver(r'^', self.site.get_urls())
     
     def reverse(name, *args, **kwargs):
         ret = self.resolver.reverse(name, *args, **kwargs)
         return ret
     
     original_fork = self.site.fork
     
     def fork(**kwargs):
         ret = original_fork(**kwargs)
         ret.reverse = reverse
         return ret
     
     self.site.fork = fork
     self.site.reverse = reverse