diff --git a/.github/workflows/docker_build.yml b/.github/workflows/docker_build.yml index c4389f9..01eb974 100644 --- a/.github/workflows/docker_build.yml +++ b/.github/workflows/docker_build.yml @@ -12,24 +12,17 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Docker meta id: docker_meta - uses: crazy-max/ghaction-docker-meta@v1 + uses: docker/metadata-action@v3 with: images: wipac/${{ github.event.repository.name }} tag-semver: | {{version}} {{major}}.{{minor}} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub + - name: Login to DockerHub if: github.event_name != 'pull_request' uses: docker/login-action@v1 with: diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index fbf85d3..4ac9828 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -11,11 +11,11 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.8 - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - name: Set up Python 3.9 + uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.9 - name: Install dependencies run: | python -m pip install --upgrade pip @@ -33,26 +33,6 @@ jobs: - name: Coverage run: | coverage run -m pytest tests - - name: Coverage html - run: | - coverage html - cd htmlcov && tar -zcf ../htmlcov.tar.gz * - - name: Upload html coverage results - env: - USER: ${{ secrets.DOCS_USERNAME }} - PASS: ${{ secrets.DOCS_PASSWORD }} - run: | - curl --data-binary "@htmlcov.tar.gz" -XPUT "https://$USER:$PASS@docs.icecube.aq/api/upload?path=$GITHUB_REPOSITORY/${{ github.head_ref }}/${{ github.sha }}" - - uses: actions/github-script@v3 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - github.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: "Coverage report available on https://docs.icecube.aq/" + context.repo.owner + "/" + context.repo.repo + "/${{ github.head_ref }}/${{ github.sha }}" - }) - name: Coverage Text Report run: | coverage report -m --fail-under=50 diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index e9ae7d7..8facec2 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -13,11 +13,11 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.8 - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - name: Set up Python 3.9 + uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: 3.9 - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/Dockerfile b/Dockerfile index 861a8bc..05323f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.8 +FROM python:3.9 RUN useradd -m -U app diff --git a/pubs/__init__.py b/pubs/__init__.py index 016e01b..02160a8 100644 --- a/pubs/__init__.py +++ b/pubs/__init__.py @@ -13,6 +13,7 @@ "proceeding": "Conference Proceeding", "thesis": "Thesis", "other": "Other", + "internal": "Internal Report", } PROJECTS = { diff --git a/pubs/server.py b/pubs/server.py index a64faa4..f39e6b2 100644 --- a/pubs/server.py +++ b/pubs/server.py @@ -13,7 +13,8 @@ import itertools from tornado.web import RequestHandler, HTTPError -from rest_tools.server import RestServer, from_environment, catch_error +from rest_tools.server import RestServer, catch_error +from wipac_dev_tools import from_environment import motor.motor_asyncio import pymongo from bson.objectid import ObjectId @@ -216,6 +217,7 @@ async def post(self): doc = { 'title': self.get_argument('new_title').strip(), 'authors': [a.strip() for a in self.get_argument('new_authors').split('\n') if a.strip()], + 'abstract': self.get_argument('new_abstract', ''), 'date': self.get_argument('new_date'), 'pub_type': self.get_argument('new_type'), 'citation': self.get_argument('new_citation').strip(), @@ -229,6 +231,7 @@ async def post(self): doc = { 'title': self.get_argument('new_title').strip(), 'authors': [a.strip() for a in self.get_argument('new_authors').split('\n') if a.strip()], + 'abstract': self.get_argument('new_abstract', ''), 'date': self.get_argument('new_date'), 'pub_type': self.get_argument('new_type'), 'citation': self.get_argument('new_citation').strip(), @@ -320,7 +323,7 @@ def create_server(): create_indexes(db_url, db_name) users = {v.split(':')[0]: v.split(':')[1] for v in config['BASIC_AUTH'].split(',') if v} - logging.info(f'BASIC_AUTH users: {users.keys()}') + logging.info(f'BASIC_AUTH users: {list(users.keys())}') main_args = { 'debug': config['DEBUG'], diff --git a/pubs/static/external.js b/pubs/static/external.js index 1ef8127..39068cc 100644 --- a/pubs/static/external.js +++ b/pubs/static/external.js @@ -144,6 +144,7 @@ async function Pubs(id, baseurl = 'https://publications.icecube.aq', filters = { props: { title: String, authors: String, + abstract: String, type: String, citation: String, date: String, @@ -181,6 +182,7 @@ async function Pubs(id, baseurl = 'https://publications.icecube.aq', filters = {
({{ type }}) {{ citation }} {{ day_month_year }}
+
Abstract: {{ abstract }}
Download: {{ getDomain(link) }} diff --git a/pubs/templates/main.html b/pubs/templates/main.html index 22e969a..5b1203e 100644 --- a/pubs/templates/main.html +++ b/pubs/templates/main.html @@ -43,6 +43,9 @@

Selected Publications:

({{ PUBLICATION_TYPES[pub['type']] }}) {{ pub['citation'] }} {{ date_format(pub['date']) }}
+ {% if pub.get('abstract', '') %} +
Abstract: {{ pub['abstract'] }}
+ {% end %}
{% if pub['downloads'] %} Download: diff --git a/pubs/templates/manage.html b/pubs/templates/manage.html index 7d11f1b..9f09b7d 100644 --- a/pubs/templates/manage.html +++ b/pubs/templates/manage.html @@ -22,6 +22,7 @@

New Publication

{% end %}
+
@@ -101,6 +102,9 @@

Existing Publications:

({{ PUBLICATION_TYPES[pub['type']] }}) {{ pub['citation'] }} {{ date_format(pub['date']) }}
+ {% if pub.get('abstract', '') %} +
Abstract: {{ pub['abstract'] }}
+ {% end %}
{% if pub['downloads'] %} Download: @@ -189,8 +193,11 @@

Existing Publications:

} const pub_id = pub.find('input[name="pub_id"]').val(); + const abstract_text = Array.from(pub.find('.abstract').map(function(){return $(this).text()})).join(''); + console.log('title:'+title); console.log('authors:');console.log(authors); + console.log('abstract:');console.log(abstract_text); console.log('pub_type:'+pub_type); console.log('citation:'+citation); console.log('date:'+date); @@ -203,6 +210,7 @@

Existing Publications:

$('.new textarea[name="new_authors"]').val(authors.join('\n')); $('.new input[name="new_date"]').val(date); $('.new select[name="new_type"]').val(pub_type); + $('.new textarea[name="new_abstract"]').val(abstract_text); $('.new textarea[name="new_citation"]').val(citation); $('.new textarea[name="new_downloads"]').val(downloads.join('\n')); $('.new input[name="new_projects"]').val(projects); diff --git a/pubs/utils.py b/pubs/utils.py index d029c8b..7d1372b 100644 --- a/pubs/utils.py +++ b/pubs/utils.py @@ -37,12 +37,13 @@ def create_indexes(db_url, db_name, background=True): weights={'title': 10, 'authors': 5, 'citation': 1}, name='text_index', background=background) -def validate(title, authors, pub_type, citation, date, downloads, projects, sites): +def validate(title, authors, pub_type, abstract, citation, date, downloads, projects, sites): assert isinstance(title, str) assert isinstance(authors, list) for a in authors: assert isinstance(a, str) assert pub_type in PUBLICATION_TYPES + assert isinstance(abstract, str) assert isinstance(citation, str) assert isinstance(date, str) date_format(date) @@ -56,23 +57,24 @@ def validate(title, authors, pub_type, citation, date, downloads, projects, site for s in sites: assert s in SITES -async def add_pub(db, title, authors, pub_type, citation, date, downloads, projects, sites=None): +async def add_pub(db, title, authors, pub_type, abstract, citation, date, downloads, projects, sites=None): if not sites: sites = [] - validate(title, authors, pub_type, citation, date, downloads, projects, sites) + validate(title, authors, pub_type, abstract, citation, date, downloads, projects, sites) data = { "title": title, "authors": authors, "type": pub_type, "citation": citation, "date": date, + "abstract": abstract, "downloads": downloads, "projects": projects, "sites": sites, } await db.publications.insert_one(data) -async def edit_pub(db, mongo_id, title=None, authors=None, pub_type=None, citation=None, date=None, downloads=None, projects=None, sites=None): +async def edit_pub(db, mongo_id, title=None, authors=None, pub_type=None, abstract=None, citation=None, date=None, downloads=None, projects=None, sites=None): match = {'_id': ObjectId(mongo_id)} update = {} if title: @@ -86,6 +88,9 @@ async def edit_pub(db, mongo_id, title=None, authors=None, pub_type=None, citati if pub_type: assert pub_type in PUBLICATION_TYPES update['type'] = pub_type + if abstract: + assert isinstance(abstract, str) + update['abstract'] = abstract if citation: assert isinstance(citation, str) update['citation'] = citation @@ -139,7 +144,7 @@ def parse_csv(row): if isinstance(p['authors'], str): p['authors'] = [p['authors']] try: - validate(p['title'], p['authors'], p['type'], p['citation'], p['date'], p['downloads'], p['projects'], p['sites']) + validate(p['title'], p['authors'], p['type'], p.get('abstract', ''), p['citation'], p['date'], p['downloads'], p['projects'], p['sites']) except AssertionError: raise Exception(f'Error validating pub with title {p["title"][:100]}') diff --git a/requirements.txt b/requirements.txt index 6b7ffcc..7554c44 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,4 @@ motor pymysql unidecode beautifulsoup4 --e git+https://github.com/WIPACrepo/rest-tools@v0.2.0#egg=rest_tools +wipac-rest-tools diff --git a/tests/test_main.py b/tests/test_main.py index b5dc76e..426b260 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -10,7 +10,7 @@ async def get_pubs(*args, **kwargs): - s = AsyncSession(retries=0) + s = AsyncSession(retries=0, backoff_factor=1) r = await asyncio.wrap_future(s.get(*args, **kwargs)) r.raise_for_status() soup = BeautifulSoup(r.content, 'html.parser') @@ -27,7 +27,7 @@ async def test_no_pubs(server): async def test_single_pub(server): db, url = server - await add_pub(db, title='Test Title', authors=['auth'], + await add_pub(db, title='Test Title', authors=['auth'], abstract="An abstract", pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) @@ -35,21 +35,22 @@ async def test_single_pub(server): assert len(pubs) == 1 assert pubs[0].select('.title')[0].string == 'Test Title' assert pubs[0].select('.author')[0].string == 'auth' + assert pubs[0].select('.abstract')[0].string == 'An abstract' assert pubs[0].select('.project')[0].string == 'IceCube' @pytest.mark.asyncio async def test_multiple_pubs(server): db, url = server - await add_pub(db, title='Test Title', authors=['auth'], + await add_pub(db, title='Test Title', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) - await add_pub(db, title='Test Title2', authors=['auth'], + await add_pub(db, title='Test Title2', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) - await add_pub(db, title='Test Title3', authors=['auth'], + await add_pub(db, title='Test Title3', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) @@ -64,11 +65,11 @@ async def test_multiple_pubs(server): async def test_project(server): db, url = server - await add_pub(db, title='Test Title', authors=['auth'], + await add_pub(db, title='Test Title', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) - await add_pub(db, title='Test Title2', authors=['auth'], + await add_pub(db, title='Test Title2', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['hawc']) @@ -81,15 +82,15 @@ async def test_project(server): async def test_multi_project(server): db, url = server - await add_pub(db, title='Test Title', authors=['auth'], + await add_pub(db, title='Test Title', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) - await add_pub(db, title='Test Title2', authors=['auth'], + await add_pub(db, title='Test Title2', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['hawc']) - await add_pub(db, title='Test Title3', authors=['auth'], + await add_pub(db, title='Test Title3', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube','hawc']) @@ -102,11 +103,11 @@ async def test_multi_project(server): async def test_hide_projects(server): db, url = server - await add_pub(db, title='Test Title', authors=['auth'], + await add_pub(db, title='Test Title', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) - await add_pub(db, title='Test Title2', authors=['auth'], + await add_pub(db, title='Test Title2', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['hawc']) @@ -124,15 +125,15 @@ async def test_hide_projects(server): async def test_dates(server): db, url = server - await add_pub(db, title='Test Title1', authors=['auth'], + await add_pub(db, title='Test Title1', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date='2020-01-02', downloads=[], projects=['icecube']) - await add_pub(db, title='Test Title2', authors=['auth'], + await add_pub(db, title='Test Title2', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date='2020-02-03', downloads=[], projects=['icecube']) - await add_pub(db, title='Test Title3', authors=['auth'], + await add_pub(db, title='Test Title3', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date='2020-03-04', downloads=[], projects=['icecube']) @@ -160,15 +161,15 @@ async def test_dates(server): async def test_types(server): db, url = server - await add_pub(db, title='Test Title1', authors=['auth'], + await add_pub(db, title='Test Title1', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) - await add_pub(db, title='Test Title2', authors=['auth'], + await add_pub(db, title='Test Title2', authors=['auth'], abstract='', pub_type="proceeding", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) - await add_pub(db, title='Test Title3', authors=['auth'], + await add_pub(db, title='Test Title3', authors=['auth'], abstract='', pub_type="thesis", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) @@ -193,15 +194,15 @@ async def test_types(server): async def test_title(server): db, url = server - await add_pub(db, title='Test Title1', authors=['auth'], + await add_pub(db, title='Test Title1', authors=['auth'], abstract='', pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) - await add_pub(db, title='Test Title2', authors=['auth'], + await add_pub(db, title='Test Title2', authors=['auth'], abstract='', pub_type="proceeding", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) - await add_pub(db, title='Test Title3', authors=['auth'], + await add_pub(db, title='Test Title3', authors=['auth'], abstract='', pub_type="thesis", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) @@ -213,15 +214,15 @@ async def test_title(server): async def test_authors(server): db, url = server - await add_pub(db, title='Test Title1', authors=['auth1'], + await add_pub(db, title='Test Title1', authors=['auth1'], abstract='', pub_type="journal", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) - await add_pub(db, title='Test Title2', authors=['auth2'], + await add_pub(db, title='Test Title2', authors=['auth2'], abstract='', pub_type="proceeding", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) - await add_pub(db, title='Test Title3', authors=['auth1', 'auth3'], + await add_pub(db, title='Test Title3', authors=['auth1', 'auth3'], abstract='', pub_type="thesis", citation="TestJournal", date=nowstr(), downloads=[], projects=['icecube']) diff --git a/tests/test_util.py b/tests/test_util.py index 7af16f5..824907a 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,6 +1,6 @@ import asyncio -from rest_tools.server import from_environment +from wipac_dev_tools import from_environment import pytest from bson.objectid import ObjectId @@ -41,13 +41,14 @@ async def test_add_pub(mocker, sites): 'authors': ['auth1', 'auth2'], 'type': 'journal', 'citation': 'citation', + 'abstract': '', 'date': '2020-11-03T00:00:00', 'downloads': ['down1', 'down2'], 'projects': ['icecube', 'hawc'], 'sites': sites if sites else [] } await pubs.utils.add_pub(db, title=args['title'], authors=args['authors'], pub_type=args['type'], - citation=args['citation'], date=args['date'], downloads=args['downloads'], + abstract=args['abstract'], citation=args['citation'], date=args['date'], downloads=args['downloads'], projects=args['projects'], sites=sites) db.publications.insert_one.assert_called_once_with(args) @@ -55,29 +56,31 @@ async def test_add_pub(mocker, sites): @pytest.mark.parametrize('title', ['title', 123]) @pytest.mark.parametrize('authors', [['auth1', 'auth2'], [12], 'author']) @pytest.mark.parametrize('pub_type', ['journal', 'foo', 12]) +@pytest.mark.parametrize('abstract', [12]) @pytest.mark.parametrize('citation', ['citation', 12]) @pytest.mark.parametrize('date', ['2020-11-03T00:00:00', '2020-1111', 2020]) @pytest.mark.parametrize('downloads', [['down1', 'down2'], [12], 'down']) @pytest.mark.parametrize('projects', [['icecube','hawc'], [12], 12]) @pytest.mark.parametrize('sites', [[12], 12]) @pytest.mark.asyncio -async def test_add_pub_err(mocker, title, authors, pub_type, citation, date, downloads, projects, sites): +async def test_add_pub_err(mocker, title, authors, pub_type, abstract, citation, date, downloads, projects, sites): db = mocker.AsyncMock() with pytest.raises(Exception): - await pubs.utils.add_pub(db, title=title, authors=authors, pub_type=pub_type, + await pubs.utils.add_pub(db, title=title, authors=authors, pub_type=pub_type, abstract=abstract, citation=citation, date=date, downloads=downloads, projects=projects, sites=sites) @pytest.mark.parametrize('title', ['title', None]) @pytest.mark.parametrize('authors', [['auth1', 'auth2'], None]) @pytest.mark.parametrize('pub_type', ['journal', None]) +@pytest.mark.parametrize('abstract', ['This is an abstract', '', None]) @pytest.mark.parametrize('citation', ['citation', None]) @pytest.mark.parametrize('date', ['2020-11-03T00:00:00', None]) @pytest.mark.parametrize('downloads', [['down1', 'down2'], None]) @pytest.mark.parametrize('projects', [['icecube','hawc'], None]) @pytest.mark.parametrize('sites', [['icecube', 'wipac'], None]) @pytest.mark.asyncio -async def test_edit_pub(mocker, title, authors, pub_type, citation, date, downloads, projects, sites): +async def test_edit_pub(mocker, title, authors, pub_type, abstract, citation, date, downloads, projects, sites): mongo_id = ObjectId() args = {} if title: @@ -86,6 +89,8 @@ async def test_edit_pub(mocker, title, authors, pub_type, citation, date, downlo args['authors'] = authors if pub_type: args['type'] = pub_type + if abstract: + args['abstract'] = abstract if citation: args['citation'] = citation if date: @@ -98,7 +103,7 @@ async def test_edit_pub(mocker, title, authors, pub_type, citation, date, downlo args['sites'] = sites db = mocker.AsyncMock() - await pubs.utils.edit_pub(db, str(mongo_id), title=title, authors=authors, pub_type=pub_type, + await pubs.utils.edit_pub(db, str(mongo_id), title=title, authors=authors, pub_type=pub_type, abstract=abstract, citation=citation, date=date, downloads=downloads, projects=projects, sites=sites) db.publications.update_one.assert_called_once_with({'_id': mongo_id}, {'$set': args}) @@ -106,18 +111,19 @@ async def test_edit_pub(mocker, title, authors, pub_type, citation, date, downlo @pytest.mark.parametrize('title', [123, None]) @pytest.mark.parametrize('authors', [[12], 'author', None]) @pytest.mark.parametrize('pub_type', ['foo', 12, None]) +@pytest.mark.parametrize('abstract', [12, None]) @pytest.mark.parametrize('citation', [12, None]) @pytest.mark.parametrize('date', ['2020-1111', 2020, None]) @pytest.mark.parametrize('downloads', [[12], 'down', None]) @pytest.mark.parametrize('projects', [[12], 12, None]) @pytest.mark.parametrize('sites', [[12], 12]) @pytest.mark.asyncio -async def test_edit_pub_err(mocker, title, authors, pub_type, citation, date, downloads, projects, sites): +async def test_edit_pub_err(mocker, title, authors, pub_type, abstract, citation, date, downloads, projects, sites): mongo_id = ObjectId() db = mocker.AsyncMock() with pytest.raises(Exception): - await pubs.utils.edit_pub(db, str(mongo_id), title=title, authors=authors, pub_type=pub_type, + await pubs.utils.edit_pub(db, str(mongo_id), title=title, authors=authors, pub_type=pub_type, abstract=abstract, citation=citation, date=date, downloads=downloads, projects=projects, sites=sites) @pytest.mark.asyncio @@ -131,12 +137,20 @@ async def test_import_file_json(mocker): "date":"2020-11-03T00:00:00","downloads":["baz"],"projects":["icecube"],"sites":["icecube","wipac"]}]''' await pubs.utils.try_import_file(db, json_data) + json_data = '''[{"title":"foo","authors":["bar"],"type":"journal","citation":"cite","abstract":"This is an abstract", +"date":"2020-11-03T00:00:00","downloads":["baz"],"projects":["icecube"],"sites":["icecube","wipac"]}]''' + await pubs.utils.try_import_file(db, json_data) + @pytest.mark.asyncio async def test_import_file_csv(mocker): db = mocker.AsyncMock() csv_data = '''title,authors,type,citation,date,downloads,projects,sites foo,bar,journal,cite,2020-11-03T00:00:00,baz,icecube,"icecube,wipac"''' await pubs.utils.try_import_file(db, csv_data) + + csv_data = '''title,authors,type,abstract,citation,date,downloads,projects,sites +foo,bar,journal,"this is an abstract",cite,2020-11-03T00:00:00,baz,icecube,"icecube,wipac"''' + await pubs.utils.try_import_file(db, csv_data) @pytest.mark.asyncio async def test_import_file_csv_authors(mocker): diff --git a/tests/util.py b/tests/util.py index 1b5aaf3..72f30a6 100644 --- a/tests/util.py +++ b/tests/util.py @@ -4,7 +4,8 @@ import os import pytest -from rest_tools.server import from_environment +import pytest_asyncio +from wipac_dev_tools import from_environment import motor.motor_asyncio from pubs.server import create_server @@ -21,7 +22,7 @@ def port(): s.close() return ephemeral_port -@pytest.fixture +@pytest_asyncio.fixture async def mongo_client(monkeypatch): if 'DB_URL' not in os.environ: monkeypatch.setenv('DB_URL', 'mongodb://localhost/pub_db_test') @@ -41,12 +42,12 @@ async def mongo_client(monkeypatch): finally: await ret.publications.drop() -@pytest.fixture +@pytest_asyncio.fixture async def server(monkeypatch, port, mongo_client): monkeypatch.setenv('DEBUG', 'True') monkeypatch.setenv('PORT', str(port)) s = create_server() - yield mongo_client, f'http://localhost:{port}' + yield (mongo_client, f'http://localhost:{port}') await s.stop()