Example #1
0
    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()
Example #2
0
    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")
Example #3
0
    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()
Example #4
0
    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()
Example #5
0
    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")
Example #6
0
    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")
Example #7
0
    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")
Example #8
0
    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")
Example #9
0
    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")
Example #10
0
    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")
Example #11
0
    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")
Example #12
0
 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")
Example #13
0
 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")
Example #14
0
 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")
Example #15
0
 def _register(self, method):
     BaseResource.allowed_methods = [method.upper()]
     register_resource(self.app, BaseResource, url="types")
Example #16
0
 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")
Example #17
0
 def _register(self, method):
     BaseResource.allowed_methods = [method.upper()]
     register_resource(self.app, BaseResource, url="types")