diff options
| author | Bryan Newbold <bnewbold@robocracy.org> | 2018-04-23 17:36:22 -0700 | 
|---|---|---|
| committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-04-23 17:36:22 -0700 | 
| commit | 5416a2570e7167ca2e62352dda10d2f371b994a7 (patch) | |
| tree | 02439733d6b74dc6e83aaa49a314b49c5ece5a67 /tests | |
| parent | 5bdd3f6e871599acb339aadc9b78cc12860f9759 (diff) | |
| download | fatcat-5416a2570e7167ca2e62352dda10d2f371b994a7.tar.gz fatcat-5416a2570e7167ca2e62352dda10d2f371b994a7.zip | |
start work on api client
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/api_client.py | 14 | ||||
| -rw-r--r-- | tests/fixtures.py | 64 | ||||
| -rw-r--r-- | tests/test_fixtures.py | 29 | 
3 files changed, 75 insertions, 32 deletions
| diff --git a/tests/api_client.py b/tests/api_client.py new file mode 100644 index 00000000..37e3da56 --- /dev/null +++ b/tests/api_client.py @@ -0,0 +1,14 @@ + +import pytest +import fatcat.api_client +from fixtures import * + + +def test_client_health(api_client): +    assert api_client.health() != None + + +def test_import_crossref(api_client): +    api_client.import_crossref_file('tests/files/crossref-works.2018-01-21.badsample.json') + +    # TODO: use API to check that entities actually created... diff --git a/tests/fixtures.py b/tests/fixtures.py index 04b4314a..30358a5c 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,23 +1,52 @@ +import os +import time +import json  import pytest +import signal  import fatcat  import fatcat.sql  from fatcat.models import *  @pytest.fixture -def app(): +def full_app():      fatcat.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'      fatcat.app.testing = True -    fatcat.app.debug = True +    fatcat.app.debug = False      fatcat.db.session.remove()      fatcat.db.drop_all()      fatcat.db.create_all()      fatcat.sql.populate_db() -    return fatcat.app.test_client() +    return fatcat.app + +@pytest.fixture +def app(full_app): +    return full_app.test_client()  @pytest.fixture  def rich_app(app): +    enrichen_test_app(app) +    return app + + +@pytest.fixture(scope="function") +def api_client(full_app): + +    pid = os.fork() +    if pid == 0: +        full_app.testing = False +        full_app.run(host="localhost", port=8444, debug=False) +        os._exit(0) + +    time.sleep(0.2) +    yield fatcat.api_client.FatCatApiClient("http://localhost:8444") +    os.kill(pid, signal.SIGKILL) + + +## Helpers ################################################################## + +def enrichen_test_app(app):      rv = app.post('/v0/editgroup',          data=json.dumps(dict( @@ -113,35 +142,6 @@ def rich_app(app):          headers={"content-type": "application/json"})      assert rv.status_code == 200 -    return app - -def test_rich_app_fixture(rich_app): -    app = rich_app - -    assert ChangelogEntry.query.count() == 1 - -    for cls in (WorkIdent, WorkRev, WorkEdit, -                ContainerIdent, ContainerRev, ContainerEdit, -                CreatorIdent, CreatorRev, CreatorEdit, -                FileIdent, FileRev, FileEdit): -        assert cls.query.count() == 1 -    for cls in (ReleaseIdent, ReleaseRev, ReleaseEdit): -        assert cls.query.count() == 2 - -    for cls in (WorkIdent, -                ContainerIdent, -                CreatorIdent, -                FileIdent): -        assert cls.query.filter(cls.is_live==True).count() == 1 -    assert ReleaseIdent.query.filter(ReleaseIdent.is_live==True).count() == 2 - -    # test that editor's active edit group is now invalid -    editor = Editor.query.first() -    assert editor.active_edit_group == None - - -## Helpers ################################################################## -  def check_entity_fields(e):      for key in ('rev', 'is_live', 'redirect_id'):          assert key in e diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py new file mode 100644 index 00000000..2ced3bb5 --- /dev/null +++ b/tests/test_fixtures.py @@ -0,0 +1,29 @@ + +import pytest +import fatcat.api_client +from fixtures import * + + +def test_rich_app_fixture(rich_app): +    app = rich_app + +    assert ChangelogEntry.query.count() == 1 + +    for cls in (WorkIdent, WorkRev, WorkEdit, +                ContainerIdent, ContainerRev, ContainerEdit, +                CreatorIdent, CreatorRev, CreatorEdit, +                FileIdent, FileRev, FileEdit): +        assert cls.query.count() == 1 +    for cls in (ReleaseIdent, ReleaseRev, ReleaseEdit): +        assert cls.query.count() == 2 + +    for cls in (WorkIdent, +                ContainerIdent, +                CreatorIdent, +                FileIdent): +        assert cls.query.filter(cls.is_live==True).count() == 1 +    assert ReleaseIdent.query.filter(ReleaseIdent.is_live==True).count() == 2 + +    # test that editor's active edit group is now invalid +    editor = Editor.query.first() +    assert editor.active_edit_group == None | 
