-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/python3.10' of github.com:DOAJ/doaj into featur…
…e/python3.10
- Loading branch information
Showing
1 changed file
with
21 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
from flask import Response | ||
|
||
from doajtest import helpers | ||
from doajtest.helpers import DoajTestCase, with_es | ||
from doajtest.helpers import DoajTestCase | ||
from portality import models | ||
from portality.core import load_account_for_login_manager | ||
from portality.decorators import api_key_required, api_key_optional | ||
|
@@ -13,19 +13,27 @@ def setUpClass(cls): | |
super(TestAPIClient, cls).setUpClass() | ||
helpers.initialise_index() | ||
|
||
# Turn off debug so we're allowed to add these routes after the app has been used in other tests | ||
# Turn off debug and so we're allowed to add these routes after the app has been used in other tests | ||
cls.app_test.debug = False | ||
|
||
with cls.app_test.app_context(): | ||
@cls.app_test.route('/hello') | ||
@api_key_required | ||
def hello_world(): | ||
return Response("hello, world!") | ||
|
||
@cls.app_test.route('/helloopt') | ||
@api_key_optional | ||
def hello_world_opt(): | ||
return Response("hello, world!") | ||
cls.app_test.testing = False | ||
|
||
"""This is a lie, but it allows us to circumnavigate a check to prevent routes being added after first request: | ||
AssertionError: The setup method 'route' can no longer be called on the application. It has already handled its | ||
first request, any changes will not be applied consistently. | ||
Make sure all imports, decorators, functions, etc. needed to set up the application are done before running it. | ||
""" | ||
cls.app_test._got_first_request = False | ||
|
||
@cls.app_test.route('/hello') | ||
@api_key_required | ||
def hello_world(): | ||
return Response("hello, world!") | ||
|
||
@cls.app_test.route('/helloopt') | ||
@api_key_optional | ||
def hello_world_opt(): | ||
return Response("hello, world!") | ||
|
||
# Reinstate debug | ||
cls.app_test.debug = True | ||
|
@@ -37,7 +45,6 @@ def tearDownClass(cls) -> None: | |
# put debug back on | ||
cls.app_test.debug = True | ||
|
||
#@with_es(indices=[models.Account.__type__]) | ||
def test_01_api_role(self): | ||
"""test the new roles added for the API""" | ||
a1 = models.Account.make_account(email="[email protected]", username="a1_user", name="a1_name", | ||
|
@@ -56,7 +63,6 @@ def test_01_api_role(self): | |
a1.remove_role('api') | ||
assert a1.api_key is None | ||
|
||
#@with_es(indices=[models.Account.__type__]) | ||
def test_02_api_required_decorator(self): | ||
"""test the api_key_required decorator""" | ||
a1 = models.Account.make_account(email="[email protected]", username="a1_user", name="a1_name", | ||
|
@@ -79,7 +85,6 @@ def test_02_api_required_decorator(self): | |
response_denied = t_client.get('/hello?api_key=' + a2_key) | ||
assert response_denied.status_code == 401 | ||
|
||
#@with_es(indices=[models.Account.__type__, models.Journal.__type__, models.Article.__type__]) | ||
def test_03_api_optional_decorator(self): | ||
"""test the api_key_optional decorator""" | ||
a1 = models.Account.make_account(email="[email protected]", username="a1_user", name="a1_name", | ||
|