Ejemplo n.º 1
0
 def test_statistics_with_total(self):
     """ Tests that dictionary with data returned if otherwise """
     model_name = 'User'
     apre = api.APIResource()
     apre.model = self.obj().set(__name__=model_name)
     api.stats.KindStat(kind_name=model_name).put()
     self.assertIn('total', apre.statistics())
Ejemplo n.º 2
0
 def test_parse_args_limit_types(self):
     """ Tests that parse_args only accepts dictionaries and booleans """
     apre = api.APIResource()
     api.parser = self.obj().set(
         parse=lambda *args: {'fields': 'invalid type'})
     with self.assertRaises(BadValueError):
         apre.parse_args(None, None)
Ejemplo n.º 3
0
 def test_delete_invoked(self):
     """ Tests that delete is invoked """
     apre = api.APIResource()
     apre.model = self.always_can()
     apre.model.key = self.obj().set(delete=self.raise_error)
     with self.assertRaises(TestingError):
         apre.delete(apre.model, None, {})
Ejemplo n.º 4
0
 def test_index(self):
     """ Tests that index checks for result """
     apre = api.APIResource()
     apre.model = self.obj().set(can=lambda *args, **kwargs: None,
                                 query=lambda: None)
     with self.assertRaises(PermissionError):
         apre.index(None, {})
Ejemplo n.º 5
0
 def test_post_checks(self):
     """ Tests that post checks for permissions """
     apre = api.APIResource()
     apre.model = self.never_can()
     apre.new_entity = lambda *args, **kwargs: '_'
     with self.assertRaises(PermissionError):
         apre.post(None, {})
Ejemplo n.º 6
0
 def test_apiresource_get_instance(self):
     """ Tests that get_instance checks permissions """
     apre = api.APIResource()
     with self.assertRaises(PermissionError):
         apre.model = self.obj().set(
             get_by_id=lambda *args: self.never_can())
         apre.get_instance('some_key', None)
Ejemplo n.º 7
0
 def test_put_effects_change(self):
     """ Tests that put updates the obj"""
     obj = self.always_can()
     obj.put = lambda: '_'
     obj.var = 'a'
     data = {'var': 'b'}
     apre = api.APIResource()
     apre.put(obj, None, data)
     self.assertEqual(obj.var, 'b')
Ejemplo n.º 8
0
 def test_put_without_change(self):
     """ Tests that if there is no change, there is no put"""
     obj = self.always_can()
     obj.put = self.raise_error
     obj.var = 'a'
     apre = api.APIResource()
     apre.put(obj, None, {})
     assert True  # put was not invoked
     self.assertEqual(obj.var, 'a')
Ejemplo n.º 9
0
 def test_put_with_change(self):
     """ Tests that if there is change, there is put"""
     obj = self.always_can()
     obj.put = self.raise_error
     obj.var = 'a'
     data = {'var': 'b'}
     apre = api.APIResource()
     with self.assertRaises(TestingError):
         apre.put(obj, None, data)
Ejemplo n.º 10
0
 def test_statistics_blank(self):
     """ Tests that empty dictionary returned if stat is none """
     apre = api.APIResource()
     apre.model = lambda: '_'
     self.assertNotIn('total', apre.statistics())
Ejemplo n.º 11
0
 def test_delete_checks(self):
     """ Tests that post checks for permissions """
     apre = api.APIResource()
     apre.model = self.never_can()
     with self.assertRaises(PermissionError):
         apre.delete(None, None, {})
Ejemplo n.º 12
0
 def test_put_check_blank_val(self):
     """ Tests that put does not set invalid fields """
     apre = api.APIResource()
     status, message = apre.put(self.always_can(), None, {'funny': 'beans'})
     self.assertEqual(400, status)
Ejemplo n.º 13
0
 def test_put_checks(self):
     """ Tests that put checks for permissions """
     with self.assertRaises(PermissionError):
         apre = api.APIResource()
         apre.put(self.never_can(), None, {})
Ejemplo n.º 14
0
 def test_apiresource_http_not_specified(self):
     """ Tests that http method is checked for existence """
     with self.assertRaises(IncorrectHTTPMethodError):
         apre = api.APIResource()
         apre.methods = {'multiply': {'methods': set(['PUT', 'GET'])}}
         apre.call_method('multiply', None, None)
Ejemplo n.º 15
0
 def test_apiresource_http_required(self):
     """ Tests that constraints function """
     with self.assertRaises(IncorrectHTTPMethodError):
         apre = api.APIResource()
         apre.methods = {'multiply': {'methods': set(['PUT', 'GET'])}}
         apre.call_method('multiply', None, 'POST')
Ejemplo n.º 16
0
 def test_apiresource_call_method_invalid_method(self):
     """ Tests that invalid method is intercepted """
     with self.assertRaises(BadMethodError):
         apre = api.APIResource()
         apre.call_method('dne', None, None)