Skip to content

Commit

Permalink
Merge branch 'feature/python3.10' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven-Eardley committed Nov 22, 2024
2 parents 0f099fd + 55022c0 commit e23737c
Show file tree
Hide file tree
Showing 163 changed files with 3,179 additions and 48,039 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
build-and-test:

docker:
- image: cimg/python:3.8.10
- image: cimg/python:3.10
environment:
DOAJENV: test
- image: cimg/redis:6.2.14
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
gen_docs:
name: generate DOAJ documentation and fuctional tests and push to the docs repo
name: generate DOAJ documentation and functional tests and push to the docs repo
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -16,22 +16,22 @@ jobs:

steps:
- name: checkout the branch of interest
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: doaj

- name: checkout the documentation repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: doaj-docs
repository: DOAJ/doaj-docs
token: ${{ secrets.STEVE_PAT_DOAJ_ACTIONS_DOCS }}
fetch-depth: 0

- name: set up a python 3.8 environment
uses: actions/setup-python@v4.4.0
- name: set up a python 3.10 environment
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: '3.10'

- name: install elasticsearch
uses: getong/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.10
3.10
14 changes: 0 additions & 14 deletions doajtest/clonelive.py

This file was deleted.

8 changes: 3 additions & 5 deletions doajtest/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ def create_app_patch(cls):
'CMS_BUILD_ASSETS_ON_STARTUP': False,
"UR_CONCURRENCY_TIMEOUT": 0,
'UPLOAD_ASYNC_DIR': paths.create_tmp_path(is_auto_mkdir=True).as_posix(),
'HUEY_IMMEDIATE': True,
'HUEY_ASYNC_DELAY': 0
}

@classmethod
Expand All @@ -180,11 +182,7 @@ def setUpClass(cls) -> None:
# some unittest will capture log for testing, therefor log level must be DEBUG
cls.app_test.logger.setLevel(logging.DEBUG)

# always_eager has been replaced by immediate
# for huey version > 2
# https://huey.readthedocs.io/en/latest/guide.html
main_queue.always_eager = True
long_running.always_eager = True
# Run huey jobs straight away
main_queue.immediate = True
long_running.immediate = True

Expand Down
16 changes: 11 additions & 5 deletions doajtest/unit/api_tests/test_api_account.py
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
Expand All @@ -13,8 +13,17 @@ 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
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
Expand All @@ -36,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",
Expand All @@ -55,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",
Expand All @@ -78,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",
Expand Down
15 changes: 13 additions & 2 deletions doajtest/unit/api_tests/test_apiv3_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_03_applications(self):
acc.save(blocking=True)

# now run some queries
with self._make_and_push_test_context(acc=acc):
with self._make_and_push_test_context_manager(acc=acc):
# 1. a general query that should hit everything
res = DiscoveryApi.search("application", acc, "Test", 1, 2)
assert res.data.get('total', 0) == 5
Expand Down Expand Up @@ -359,7 +359,7 @@ def test_03_applications(self):
# 13. A search with an account that isn't either of the ones in the dataset
other = models.Account()
other.set_id("other")
with self._make_and_push_test_context(acc=other):
with self._make_and_push_test_context_manager(acc=other):
res = DiscoveryApi.search("application", other, "Test", 1, 10, "created_date:desc")
assert res.data.get('total', 0) == 0

Expand Down Expand Up @@ -466,3 +466,14 @@ def test_07_query_escaper(self):

for t in test_tuples:
assert escape(t[0]) == t[1], "expected {0} got {1}".format(t[1], t[0])

def test_08_exception_thrown_invalid_model(self):
""" Going for 100% test coverage by validating the DiscoveryException caused by scrolling e.g. accounts"""
with self.assertRaises(DiscoveryException):
_ = DiscoveryApi.search('account', None, None, 0, 0)

with self.assertRaises(DiscoveryException):
g = DiscoveryApi.scroll('account', None, None, 0, 0)
next(g)


Loading

0 comments on commit e23737c

Please sign in to comment.