aboutsummaryrefslogtreecommitdiffstats
path: root/python/tests
diff options
context:
space:
mode:
Diffstat (limited to 'python/tests')
-rw-r--r--python/tests/tools_api.py6
-rw-r--r--python/tests/web_auth.py4
-rw-r--r--python/tests/web_citation_csl.py2
-rw-r--r--python/tests/web_editor.py28
-rw-r--r--python/tests/web_routes.py1
-rw-r--r--python/tests/web_search.py82
6 files changed, 117 insertions, 6 deletions
diff --git a/python/tests/tools_api.py b/python/tests/tools_api.py
index ac75a73a..933135a3 100644
--- a/python/tests/tools_api.py
+++ b/python/tests/tools_api.py
@@ -9,8 +9,7 @@ from fatcat_tools import public_api, authenticated_api
def test_authenticated_api():
api = authenticated_api("http://localhost:9411/v0")
api.get_changelog()
- api.create_editgroup_annotation("aaaaaaaaaaaabo53aaaaaaaaa4",
- EditgroupAnnotation(comment_markdown="bloop test thingie"))
+ api.auth_check()
def test_public_api():
api = public_api("http://localhost:9411/v0")
@@ -19,5 +18,4 @@ def test_public_api():
# authenticated. Maybe the DefaultAPI thing?
pytest.skip("public_api() client not isolated from authenticated")
with pytest.raises(ApiException):
- api.create_editgroup_annotation("aaaaaaaaaaaabo53aaaaaaaaa4",
- EditgroupAnnotation(comment_markdown="bloop unauth test thingie"))
+ api.auth_check()
diff --git a/python/tests/web_auth.py b/python/tests/web_auth.py
index 81986eec..2fa9363b 100644
--- a/python/tests/web_auth.py
+++ b/python/tests/web_auth.py
@@ -26,6 +26,10 @@ def test_ia_xauth(full_app):
# successful login
with full_app.test_client() as app:
+
+ rv = app.get('/auth/token_login')
+ assert rv.status_code == 200
+
responses.add(responses.POST, full_app.config['IA_XAUTH_URI'] + "?op=authenticate",
status=200, json={'success': True})
responses.add(responses.POST, full_app.config['IA_XAUTH_URI'] + "?op=info",
diff --git a/python/tests/web_citation_csl.py b/python/tests/web_citation_csl.py
index ae9bca55..cf50f3c3 100644
--- a/python/tests/web_citation_csl.py
+++ b/python/tests/web_citation_csl.py
@@ -15,6 +15,8 @@ def test_release_bibtex(app):
rv = app.get('/release/aaaaaaaaaaaaarceaaaaaaaaam.bib')
assert rv.status_code == 200
assert b'@article{' in rv.data
+ rv = app.get('/release/ccccccccccccccccccccccccca.bib')
+ assert rv.status_code == 404
rv = app.get('/release/aaaaaaaaaaaaarceaaaaaaaaam/citeproc?style=csl-json')
assert rv.status_code == 200
# could also rv.get_json() here
diff --git a/python/tests/web_editor.py b/python/tests/web_editor.py
new file mode 100644
index 00000000..de094488
--- /dev/null
+++ b/python/tests/web_editor.py
@@ -0,0 +1,28 @@
+
+import json
+import pytest
+from fatcat_client.rest import ApiException
+from fixtures import *
+
+
+def test_change_username(app_admin):
+
+ # these tests aren't supposed to mutate database
+ rv = app_admin.post('/auth/change_username', data={'username': 'admin-tmp'},
+ follow_redirects=True)
+ assert rv.status_code == 200
+ rv = app_admin.get('/auth/account')
+ assert b'admin-tmp' in rv.data
+
+ rv = app_admin.post('/auth/change_username', data={'username': 'claire'},
+ follow_redirects=True)
+ assert rv.status_code == 400
+ rv = app_admin.get('/auth/account')
+ assert b'admin-tmp' in rv.data
+
+ rv = app_admin.post('/auth/change_username', data={'username': 'admin'},
+ follow_redirects=True)
+ assert rv.status_code == 200
+ rv = app_admin.get('/auth/account')
+ assert b'admin-tmp' not in rv.data
+
diff --git a/python/tests/web_routes.py b/python/tests/web_routes.py
index 889bdd90..3af5369b 100644
--- a/python/tests/web_routes.py
+++ b/python/tests/web_routes.py
@@ -11,5 +11,6 @@ def test_static_routes(app):
rv = app.get(route)
assert rv.status_code == 200
+ assert app.get("/search").status_code == 302
assert app.get("/static/bogus/route").status_code == 404
diff --git a/python/tests/web_search.py b/python/tests/web_search.py
index 4e7cb2e0..43be9f01 100644
--- a/python/tests/web_search.py
+++ b/python/tests/web_search.py
@@ -33,8 +33,86 @@ def test_container_search(app):
assert b"European Instructional Course Lectures" in rv.data
assert b"British Editorial Society of Bone and Joint Surger" in rv.data
-# TODO: entity stats
+elastic_resp1 = {
+ 'timed_out': False,
+ 'aggregations': {
+ 'release_ref_count': {'value': 8031459}},
+ 'hits': {'total': 80578584, 'hits': [], 'max_score': 0.0},
+ '_shards': {'successful': 5, 'total': 5, 'skipped': 0, 'failed': 0},
+ 'took': 0
+}
+elastic_resp2 = {
+ 'timed_out': False,
+ 'aggregations': {
+ 'paper_like': {'buckets': {
+ 'is_oa': {'doc_count': 8031459},
+ 'in_kbart': {'doc_count': 51594200},
+ 'in_web': {'doc_count': 10925092},
+ 'in_web_not_kbart': {'doc_count': 5160359}}}},
+ 'hits': {'total': 80578584, 'hits': [], 'max_score': 0.0},
+ '_shards': {'successful': 5, 'total': 5, 'skipped': 0, 'failed': 0},
+ 'took': 0
+}
+elastic_resp3 = {
+ 'timed_out': False,
+ 'hits': {'total': 80578584, 'hits': [], 'max_score': 0.0},
+ '_shards': {'successful': 5, 'total': 5, 'skipped': 0, 'failed': 0},
+ 'took': 0
+}
+
+@responses.activate
+def test_stats(app):
+
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_release/_search?request_cache=true',
+ json=elastic_resp1.copy(), status=200)
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_release/_search?request_cache=true',
+ json=elastic_resp2.copy(), status=200)
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_container/_search?request_cache=true',
+ json=elastic_resp3.copy(), status=200)
+ rv = app.get('/stats')
+ assert rv.status_code == 200
+ # TODO: probe these reponses better
+
+@responses.activate
+def test_stats_json(app):
+
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_release/_search?request_cache=true',
+ json=elastic_resp1.copy(), status=200)
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_release/_search?request_cache=true',
+ json=elastic_resp2.copy(), status=200)
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_container/_search?request_cache=true',
+ json=elastic_resp3.copy(), status=200)
+ rv = app.get('/stats.json')
+ assert rv.status_code == 200
+
+@responses.activate
+def test_container_stats(app):
+
+ elastic_resp = {
+ 'timed_out': False,
+ 'aggregations': {
+ 'container_stats': {'buckets': {
+ 'is_preserved': {'doc_count': 461939},
+ 'in_web': {'doc_count': 2797}}}},
+ 'hits': {'total': 461939, 'hits': [], 'max_score': 0.0},
+ '_shards': {'successful': 5, 'total': 5, 'skipped': 0, 'failed': 0},
+ 'took': 50
+ }
+
+ responses.add(responses.GET,
+ 'http://localhost:9200/fatcat_release/_search?request_cache=true',
+ json=elastic_resp, status=200)
+ rv = app.get('/container/issnl/1234-5678/stats.json')
+ assert rv.status_code == 200
+ # TODO: probe this reponse better
+
# TODO: container stats
# TODO: container ISSN-L query
# TODO: release DOI query
-# TODO: release fulltext query
+# TODO: release fulltext (filter) query