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())
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)
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, {})
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, {})
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, {})
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)
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')
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')
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)
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())
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, {})
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)
def test_put_checks(self): """ Tests that put checks for permissions """ with self.assertRaises(PermissionError): apre = api.APIResource() apre.put(self.never_can(), None, {})
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)
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')
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)