def setUp(self): self.app = Flask('Cors') self.app.config['TESTING'] = True self.client = self.app.test_client() register_resource(self.app, CorsResource, url="cors") self.db_client = MongoClient('localhost', 27017) self.db = self.db_client['test_slither'] self._load_fixtures()
def test_empty(self): """The authentication is_authenticated method does not exist""" class MyAuth: pass BaseResource.authentication = MyAuth register_resource(self.app, BaseResource, url="authentications") r = self.client.get('/authentications') self.assertEquals(r.status_code, 200, "No authentication")
def setUp(self): self.app = Flask('Minimal') self.app.config['TESTING'] = True self.app.config['DB_NAME'] = 'testing_slither' self.client = self.app.test_client() register_resource(self.app, MinimalResource) self.db_client = MongoClient('localhost', 27017) self.db = self.db_client[self.app.config['DB_NAME']] self._load_fixtures()
def test_record_ref(self): """The authorization method returns True if the url record is found""" class MyAuth: def is_authorized(self, **kwargs): return hasattr(g, '_resource_instance') BaseResource.authentication = MyAuth register_resource(self.app, BaseResource, url="authorizations") r = self.client.delete('/authorizations/1') self.assertEquals(r.status_code, 204, "Successful authorization")
def test_fail(self): """The authorization method returns False""" class MyAuth: def is_authorized(self, **kwargs): return False BaseResource.authentication = MyAuth register_resource(self.app, BaseResource, url="authorizations") r = self.client.get('/authorizations') self.assertEquals(r.status_code, 403, "Unsuccessful authorization")
def test_success(self): """The authentication method returns True""" class MyAuth: def is_authenticated(self): return True BaseResource.authentication = MyAuth register_resource(self.app, BaseResource, url="authentications") r = self.client.get('/authentications') self.assertEquals(r.status_code, 200, "Successful Authentication")
def test_none(self): """The authentication method is set to None""" BaseResource.authentication = None register_resource(self.app, BaseResource, url="authentications") r = self.client.get('/authentications') self.assertEquals(r.status_code, 200, "No authentication")
def test_undefined(self): """No authentication method is defined""" delattr(BaseResource, 'authentication') register_resource(self.app, BaseResource, url="authentications") r = self.client.get('/authentications') self.assertEquals(r.status_code, 200, "No authentication")
def _register(self, method): BaseResource.allowed_methods = [method.upper()] register_resource(self.app, BaseResource, url="types")