Skip to content

Commit 67bbab2

Browse files
committed
Merge branch 'release/0.5.9'
2 parents 628c9cb + 9d4e3b8 commit 67bbab2

32 files changed

+254
-49
lines changed

backend/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ You can set `/absolute/path/to/datadir` to any directory of your choosing, as lo
3636

3737
While the Fuseki server is running, you can access its web interface at http://localhost:3030. This lets you upload and download data, try out queries and review statistics about the dataset. The server can be stopped by typing `ctrl-c`.
3838

39+
In order to support the unittests, visit the Fuseki web interface and create an additional dataset by the name `readit-test`.
40+
3941
If you are new to Fuseki but not to READ-IT, i.e., you have previously deployed READ-IT version 0.4.0 or older, or done local development work on any commit that did not descend from `0063b21`, then you should also read the following section about migrating your triples from the rdflib-django store to Fuseki.
4042

4143
[jena-download]: https://jena.apache.org/download/

backend/conftest.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
11
import pytest
22

3+
HAS_TRIPLES = '''
4+
ASK {
5+
GRAPH ?g {
6+
?s ?p ?o
7+
}
8+
}
9+
'''
10+
11+
12+
@pytest.fixture
13+
def credentials():
14+
return 'tester', 'testing123'
15+
316

417
@pytest.fixture
5-
def auth_client(client, django_user_model):
6-
username = 'tester'
7-
password = 'testing123'
18+
def auth_client(client, django_user_model, credentials):
19+
username, password = credentials
820
django_user_model.objects.create_user(username=username, password=password)
921
client.login(username=username, password=password)
1022
yield client
1123
client.logout()
1224
django_user_model.objects.get(username=username).delete()
25+
26+
27+
@pytest.fixture
28+
def sparqlstore(settings):
29+
store = settings.RDFLIB_STORE
30+
assert not store.query(HAS_TRIPLES)
31+
yield store
32+
store.update('CLEAR ALL')

backend/items/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def itemgraph():
7373

7474

7575
@pytest.fixture
76-
def itemgraph_db(db, itemgraph):
76+
def itemgraph_db(db, itemgraph, sparqlstore):
7777
g = graph()
7878
g += itemgraph
7979
yield

backend/items/views_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def submit_data(client, input_graph, method, serial=None):
8282
return response, output_graph
8383

8484

85-
def test_post_item(auth_client):
85+
def test_post_item(auth_client, sparqlstore):
8686
bnode = BNode()
8787
muppet = URIRef('https://muppets.disney.com/')
8888
pork = URIRef('https://en.wikipedia.org/wiki/Pork')

backend/nlp_ontology/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
PREFIX dctypes: <http://purl.org/dc/dcmitype/>
2323
PREFIX ns3: <http://schema.org/>
2424
25-
INSERT DATA {
25+
INSERT DATA {
2626
my:icecream a ns3:Food ;
2727
ns3:color "#f9e5bc" .
2828
ns3:Cat my:meow "loud" .
@@ -36,15 +36,15 @@
3636
}
3737
'''
3838

39-
ASK_QUERY = '''PREFIX my: <http://testserver/nlp-ontology#>
39+
ASK_QUERY = '''PREFIX my: <http://testserver/nlp-ontology#>
4040
ASK { ?x my:meow "loud" }'''
41-
ASK_QUERY_FALSE = '''PREFIX my: <http://testserver/nlp-ontology#>
41+
ASK_QUERY_FALSE = '''PREFIX my: <http://testserver/nlp-ontology#>
4242
ASK { ?x my:meow "silent" }'''
4343

4444
CONSTRUCT_QUERY = '''
4545
PREFIX my: <http://testserver/nlp-ontology#>
4646
PREFIX ns3: <http://schema.org/>
47-
CONSTRUCT WHERE { ?x my:meow ?name }
47+
CONSTRUCT WHERE { ?x my:meow ?name }
4848
'''
4949

5050

@@ -55,7 +55,7 @@ def ontologygraph():
5555

5656

5757
@pytest.fixture
58-
def ontologygraph_db(db, ontologygraph):
58+
def ontologygraph_db(db, ontologygraph, sparqlstore):
5959
g = graph()
6060
g += ontologygraph
6161
yield

backend/nlp_ontology/views.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import rdflib.plugins.sparql as rdf_sparql
21
from django.http.response import HttpResponseBase
32
from pyparsing import ParseException
43
from rdflib import BNode, Literal
@@ -7,6 +6,7 @@
76
from rest_framework.exceptions import APIException
87
from rest_framework.response import Response
98
from rest_framework.views import APIView
9+
from SPARQLWrapper.SPARQLExceptions import QueryBadFormed
1010

1111
from rdf.ns import HTTP, HTTPSC, RDF
1212
from rdf.renderers import TurtleRenderer
@@ -26,12 +26,15 @@ def get_exception_handler(self):
2626
return turtle_exception_handler
2727

2828
def execute_update(self, updatestring):
29+
graph = self.graph()
2930
try:
30-
return self.graph().update(updatestring)
31-
except ParseException as p_e:
31+
return graph.update(updatestring)
32+
except (ParseException, QueryBadFormed) as p_e:
3233
# Raised when SPARQL syntax is not valid, or parsing fails
34+
graph.rollback()
3335
raise ParseSPARQLError(p_e)
3436
except Exception as e:
37+
graph.rollback()
3538
raise APIException(e)
3639

3740
def post(self, request, **kwargs):
@@ -107,7 +110,7 @@ def execute_query(self, querystring):
107110
self.request.data['query_type'] = query_type
108111
return query_results
109112

110-
except ParseException as p_e:
113+
except (ParseException, QueryBadFormed) as p_e:
111114
# Raised when SPARQL syntax is not valid, or parsing fails
112115
raise ParseSPARQLError(p_e)
113116
except Exception as n_e:

backend/nlp_ontology/views_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,23 @@ def test_construct(client, test_queries, ontologygraph_db):
4242
assert response.status_code == 200
4343

4444

45-
def test_authorized(admin_client, test_queries):
45+
def test_authorized(admin_client, test_queries, sparqlstore):
4646
response = admin_client.post(UPDATE_URL, {'update': test_queries.INSERT})
4747
assert response.status_code == 200
4848

4949

50-
def test_unauthorized(client):
50+
def test_unauthorized(client, sparqlstore):
5151
response = client.post(UPDATE_URL)
5252
assert response.status_code == 403
5353

5454

55-
def test_malformed_update(admin_client):
55+
def test_malformed_update(admin_client, sparqlstore):
5656
response = admin_client.post(
5757
UPDATE_URL, {'update': 'this is no SPARQL update!'})
5858
assert response.status_code == 400
5959

6060

61-
def test_malformed_query(admin_client):
61+
def test_malformed_query(admin_client, sparqlstore):
6262
response = admin_client.post(
6363
QUERY_URL, {'query': 'this is no SPARQL query!'})
6464
assert response.status_code == 400

backend/ontology/rdf_migrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def delete_cascade(graph, predicate, _object):
5555
Delete all triples in the item graph with the combination of `predicate` and `_object`.
5656
"""
5757
obsolete = list(graph.quads((None, predicate, _object)))
58-
prune_triples_cascade(graph, obsolete, [item_graph], [OA.hasBody])
58+
prune_triples_cascade(graph, obsolete, [item_graph()], [OA.hasBody])
5959

6060

6161
def delete_predicate(graph, predicate):

backend/readit/index.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
from django.http import HttpResponse
22
from django.contrib.staticfiles import finders
33
from django.views.decorators.csrf import ensure_csrf_cookie
4+
from django.conf import settings
45

56

67
def html_view(filename):
78
""" Return a view function that loads `filename` from the static files. """
89
def fetch_html(request):
9-
return HttpResponse(content=open(finders.find(filename)))
10+
with open(finders.find(filename)) as html_file:
11+
return HttpResponse(content=html_file)
1012
return fetch_html
1113

1214

1315
""" Thin wrapper for the static index.html that adds the CSRF cookie."""
14-
index = ensure_csrf_cookie(html_view('index.html'))
16+
index = ensure_csrf_cookie(html_view(settings.INDEX_FILE_PATH))
1517

1618
""" Helper view for injecting a Jasmine runner from a frontend. """
17-
specRunner = html_view('specRunner.html')
19+
specRunner = html_view(settings.TESTRUNNER_FILE_PATH)

backend/readit/index_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test_index_available(client):
2+
assert client.get('/').status_code == 200

0 commit comments

Comments
 (0)