Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rybesh committed Oct 26, 2024
1 parent 7bd5013 commit 6c3ae95
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
10 changes: 3 additions & 7 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def init_db(shared_datadir):

@pytest.fixture
def active_user(init_db):
init_db
with app.app_context():
return auth.add_user_or_update_credentials(
{
Expand All @@ -54,7 +53,6 @@ def active_user(init_db):

@pytest.fixture
def expired_user(init_db):
init_db
with app.app_context():
return auth.add_user_or_update_credentials(
{
Expand All @@ -68,7 +66,6 @@ def expired_user(init_db):

@pytest.fixture
def unauthorized_user(init_db):
init_db
with app.app_context():
return auth.add_user_or_update_credentials(
{
Expand All @@ -83,7 +80,6 @@ def unauthorized_user(init_db):

@pytest.fixture
def admin_user(init_db):
init_db
with app.app_context():
return auth.add_user_or_update_credentials(
{
Expand All @@ -110,21 +106,21 @@ def _bearer_auth(token):

@pytest.fixture
def client(request, init_db):
init_db
marker = request.node.get_closest_marker("client_auth_token")
if marker is None:
auth = None
else:
auth = BearerAuth(marker.args[0])
with httpx.Client(
app=app, base_url=f"http://{DEV_SERVER_NAME}", auth=auth
transport=httpx.WSGITransport(app=app),
base_url=f"http://{DEV_SERVER_NAME}",
auth=auth,
) as client:
yield client


@pytest.fixture
def submit_and_merge_patch(active_user, admin_user, client, bearer_auth, load_json):
active_user, admin_user

def _submit_and_merge_patch(filename):
res = client.patch(
Expand Down
8 changes: 3 additions & 5 deletions test/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import pytest
import re
from rdflib import ConjunctiveGraph
from rdflib import Dataset
from rdflib.namespace import Namespace
from urllib.parse import urlparse
from periodo import app, database, identifier, cache, DEV_SERVER_NAME
Expand All @@ -13,7 +13,6 @@


def test_initial_data_load_patch(init_db):
init_db
with app.app_context():
created_entities = json.loads(
database.query_db_for_one(
Expand All @@ -36,7 +35,6 @@ def test_initial_data_load_patch(init_db):

@pytest.mark.client_auth_token("this-token-has-normal-permissions")
def test_submit_patch(active_user, client, load_json):
active_user
res = client.patch("/d/", json=load_json("test-patch-replace-values-1.json"))
assert res.status_code == httpx.codes.ACCEPTED
patch_url = res.headers["Location"]
Expand Down Expand Up @@ -269,7 +267,7 @@ def test_remove_period(client, submit_and_merge_patch):
assert res.status_code == httpx.codes.OK

res = client.get("/history.nt")
g = ConjunctiveGraph()
g = Dataset()
g.parse(format="nt", data=res.text)

generated = list(g.objects(subject=HOST["h#change-2"], predicate=PROV.generated))
Expand Down Expand Up @@ -321,7 +319,7 @@ def test_remove_authority(client, submit_and_merge_patch):
assert res.status_code == httpx.codes.OK

res = client.get("/h.nt")
g = ConjunctiveGraph()
g = Dataset()
g.parse(format="nt", data=res.text)

generated = g.value(subject=HOST["h#change-2"], predicate=PROV.generated, any=False)
Expand Down
25 changes: 17 additions & 8 deletions test/test_provenance.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import httpx
import pytest
import re
from rdflib import ConjunctiveGraph, URIRef
from rdflib import Dataset, Literal, URIRef
from rdflib.namespace import Namespace, RDFS, FOAF, RDF
from urllib.parse import urlparse
from periodo import DEV_SERVER_NAME
from typing import cast

PERIODO = Namespace("http://n2t.net/ark:/99152/")
PROV = Namespace("http://www.w3.org/ns/prov#")
Expand All @@ -22,7 +23,6 @@ def test_get_history(
bearer_auth,
load_json,
):
active_user, admin_user
res = client.patch(
"/d/",
json=load_json("test-patch-adds-items.json"),
Expand Down Expand Up @@ -51,7 +51,7 @@ def check_redirects_to_nt(content_type):
assert res.status_code == httpx.codes.OK
assert res.headers["Content-Type"] == "application/n-triples"

g = ConjunctiveGraph()
g = Dataset()
g.parse(format="nt", data=res.text)

# Initial data load
Expand Down Expand Up @@ -119,7 +119,8 @@ def check_time(time):
commentCount = g.value(
subject=HOST["h#patch-request-2-comments"], predicate=AS.totalItems
)
assert commentCount.value == 2
assert commentCount is not None
assert cast(Literal, commentCount).value == 2
assert (
HOST["h#patch-request-2-comments"],
AS.first,
Expand All @@ -140,8 +141,12 @@ def check_comment(num, commenter, comment):
assert (HOST[f"h#patch-request-2-comment-{num}"], RDF.type, AS.Note) in g
assert (HOST[f"h#patch-request-2-comment-{num}"], AS.published, None) in g
assert (
g.value(
subject=HOST[f"h#patch-request-2-comment-{num}"], predicate=AS.mediaType
cast(
Literal,
g.value(
subject=HOST[f"h#patch-request-2-comment-{num}"],
predicate=AS.mediaType,
),
).value
== "text/plain"
)
Expand All @@ -151,8 +156,12 @@ def check_comment(num, commenter, comment):
URIRef(commenter),
) in g
assert (
g.value(
subject=HOST[f"h#patch-request-2-comment-{num}"], predicate=AS.content
cast(
Literal,
g.value(
subject=HOST[f"h#patch-request-2-comment-{num}"],
predicate=AS.content,
),
).value
== comment
)
Expand Down

0 comments on commit 6c3ae95

Please sign in to comment.