コード例 #1
0
ファイル: cors-test.py プロジェクト: biocode/flask_slither
    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()
コード例 #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")
コード例 #3
0
ファイル: minimal-test.py プロジェクト: biocode/flask_slither
    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()
コード例 #4
0
ファイル: minimal-test.py プロジェクト: gevious/flask_slither
    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()
コード例 #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")
コード例 #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")
コード例 #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")
コード例 #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")
コード例 #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")
コード例 #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")
コード例 #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")
コード例 #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")
コード例 #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")
コード例 #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")
コード例 #15
0
 def _register(self, method):
     BaseResource.allowed_methods = [method.upper()]
     register_resource(self.app, BaseResource, url="types")
コード例 #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")
コード例 #17
0
 def _register(self, method):
     BaseResource.allowed_methods = [method.upper()]
     register_resource(self.app, BaseResource, url="types")