-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from joegasewicz/models_to_init
Add Models to JWTRoutes class & init_app method #119
- Loading branch information
Showing
9 changed files
with
108 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ pytest = "*" | |
twine = "*" | ||
pyjwt = "*" | ||
Flask-SQLAlchemy = "*" | ||
Sphinx = "*" | ||
|
||
[packages] | ||
flask = "*" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,37 @@ | ||
from flask_jwt_router._jwt_routes import JwtRoutes | ||
from flask_jwt_router._extensions import Extensions | ||
from tests.fixtures.model_fixtures import MockEntityModel | ||
|
||
|
||
class TestExtension: | ||
IGNORED_ROUTES = [ | ||
("GET", "/"), | ||
("GET", "/ignore"), | ||
] | ||
WHITE_LIST_ROUTES = [ | ||
("GET", "/test"), | ||
] | ||
|
||
def test_config(self): | ||
IGNORED_ROUTES = [ | ||
("GET", "/"), | ||
("GET", "/ignore"), | ||
] | ||
WHITE_LIST_ROUTES = [ | ||
("GET", "/test"), | ||
] | ||
class App: | ||
config = { | ||
config = { | ||
"IGNORED_ROUTES": IGNORED_ROUTES, | ||
"WHITE_LIST_ROUTES": WHITE_LIST_ROUTES, | ||
"SECRET_KEY": "a sectrect key", | ||
"JWT_ROUTER_API_NAME": "api/v1", | ||
"ENTITY_KEY": "user_id", | ||
} | ||
def before_request(self, t): | ||
pass | ||
flask_jwt_router = JwtRoutes(App()) | ||
assert flask_jwt_router.extensions.ignored_routes == IGNORED_ROUTES | ||
assert flask_jwt_router.extensions.whitelist_routes == WHITE_LIST_ROUTES | ||
flask_jwt = JwtRoutes() | ||
flask_jwt.init_app(App()) | ||
assert flask_jwt.extensions.ignored_routes == IGNORED_ROUTES | ||
assert flask_jwt.extensions.whitelist_routes == WHITE_LIST_ROUTES | ||
|
||
def test_init_extensions(self, MockEntityModel): | ||
extensions = Extensions() | ||
config = extensions.init_extensions(self.config, entity_models=[MockEntityModel]) | ||
|
||
assert config.whitelist_routes == self.WHITE_LIST_ROUTES | ||
assert config.ignored_routes == self.IGNORED_ROUTES | ||
assert config.entity_models == [MockEntityModel] | ||
assert config.entity_key == "user_id" | ||
assert config.api_name == "api/v1" | ||
|
||
config = {**self.config, "ENTITY_MODELS": [MockEntityModel]} | ||
con = extensions.init_extensions(config) | ||
|
||
assert con.entity_models == [MockEntityModel] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from flask import Flask | ||
|
||
|
||
from flask_jwt_router._jwt_routes import JwtRoutes | ||
from tests.fixtures.model_fixtures import MockEntityModel | ||
|
||
|
||
class TestJwtRoutes: | ||
|
||
app = Flask(__name__) | ||
|
||
def test_init_app(self, MockEntityModel): | ||
jwt = JwtRoutes(self.app, entity_models=[MockEntityModel]) | ||
assert jwt.extensions.entity_models[0] == MockEntityModel | ||
assert jwt.app == self.app | ||
|
||
jwt = JwtRoutes() | ||
jwt.init_app(self.app, entity_models=[MockEntityModel]) | ||
assert jwt.extensions.entity_models[0] == MockEntityModel | ||
assert jwt.app == self.app | ||
|
||
jwt = JwtRoutes(self.app) | ||
jwt.init_app(entity_models=[MockEntityModel]) | ||
assert jwt.extensions.entity_models[0] == MockEntityModel | ||
assert jwt.app == self.app | ||
|
||
jwt = JwtRoutes(entity_models=[MockEntityModel]) | ||
jwt.init_app(self.app) | ||
assert jwt.extensions.entity_models[0] == MockEntityModel | ||
assert jwt.app == self.app | ||
|
||
self.app.config["ENTITY_MODELS"] = [MockEntityModel] | ||
jwt = JwtRoutes() | ||
jwt.init_app(self.app) | ||
assert jwt.extensions.entity_models[0] == MockEntityModel | ||
assert jwt.app == self.app |