diff --git a/atst/app.py b/atst/app.py index 0d74ce47..9d8ddc00 100644 --- a/atst/app.py +++ b/atst/app.py @@ -15,6 +15,7 @@ from atst.api_client import ApiClient ENV = os.getenv("TORNADO_ENV", "dev") + def make_app(config): authz_client = ApiClient(config["default"]["AUTHZ_BASE_URL"]) @@ -22,7 +23,12 @@ def make_app(config): routes = [ url(r"/", Home, {"page": "login"}, name="main"), - url(r"/login", Login, {"page": "login"}, name="login"), + url( + r"/login", + Login, + {"authnid_client": authnid_client}, + name="login", + ), url(r"/home", MainHandler, {"page": "home"}, name="home"), url( r"/workspaces", @@ -54,16 +60,18 @@ def make_app(config): cookie_secret=config["default"]["COOKIE_SECRET"], debug=config['default'].getboolean('DEBUG') ) - app.authnid_client = authnid_client return app def make_config(): - BASE_CONFIG_FILENAME = os.path.join(os.path.dirname(__file__), "../config/base.ini") + BASE_CONFIG_FILENAME = os.path.join( + os.path.dirname(__file__), + "../config/base.ini" + ) ENV_CONFIG_FILENAME = os.path.join( os.path.dirname(__file__), "../config/", - "{}.ini".format(ENV.lower()), + "{}.ini".format(ENV.lower()) ) config = ConfigParser() diff --git a/atst/handler.py b/atst/handler.py index b79cfbc3..26595b3d 100644 --- a/atst/handler.py +++ b/atst/handler.py @@ -1,5 +1,4 @@ import os -import functools from webassets import Environment, Bundle import tornado.web from atst.home import home diff --git a/atst/handlers/login.py b/atst/handlers/login.py index 80c96fdf..3a141340 100644 --- a/atst/handlers/login.py +++ b/atst/handlers/login.py @@ -4,8 +4,8 @@ from atst.handler import BaseHandler class Login(BaseHandler): - def initialize(self, page): - self.page = page + def initialize(self, authnid_client): + self.authnid_client = authnid_client @tornado.gen.coroutine def get(self): @@ -24,7 +24,7 @@ class Login(BaseHandler): @tornado.gen.coroutine def _validate_login_token(self, token): try: - response = yield self.application.authnid_client.post( + response = yield self.authnid_client.post( "/api/v1/validate", json={"token": token} ) return response.code == 200 diff --git a/tests/test_auth.py b/tests/test_auth.py index 50d0acf7..cc16fe5a 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -4,13 +4,6 @@ import tornado.web from concurrent.futures import ThreadPoolExecutor -class MockApiResponse(): - - def __init__(self, code, json): - self.code = code - self.json = json - - @pytest.mark.gen_test def test_redirects_when_not_logged_in(http_client, base_url): response = yield http_client.fetch(