Skip to content

Commit

Permalink
don't crash when extended rdf data is requested and there exists no a…
Browse files Browse the repository at this point in the history
…nnotation file for the resource
  • Loading branch information
staffanm committed Jan 6, 2020
1 parent eb51812 commit d9803db
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ RUN python3.7 -m venv .virtualenv && \
./.virtualenv/bin/pip install wheel && \
./.virtualenv/bin/pip install -r requirements.txt

EXPOSE 80 8000 3330 9001 9200
EXPOSE 80 8000 3030 9001 9200
COPY docker /tmp/docker
RUN mv /tmp/docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf && \
mv /tmp/docker/nginx.conf /etc/nginx/sites-enabled/default && \
Expand All @@ -86,4 +86,4 @@ COPY . .
ENTRYPOINT ["/bin/bash", "/tmp/docker/setup.sh"]
CMD ["/usr/bin/supervisord"] # starts nginx, elasticsearch, fuseki, cron etc

# then: docker run --name ferenda -d -v c:/docker/ferenda:/usr/share/ferenda/site -p 81:80 -p 3330:3330 -p 9001:9001 -p 9200:9200 -p 8000:8000 <imageid>
# then: docker run --name ferenda -d -v c:/docker/ferenda:/usr/share/ferenda/site -p 81:80 -p 3030:3030 -p 9001:9001 -p 9200:9200 -p 8000:8000 <imageid>
7 changes: 4 additions & 3 deletions ferenda/requesthandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,10 @@ def lookup_resource(self, environ, basefile, params, contenttype, suffix):
g = Graph()
g.parse(self.repo.store.distilled_path(basefile))
if 'extended' in params:
annotation_graph = self.repo.annotation_file_to_graph(
self.repo.store.annotation_path(basefile))
g += annotation_graph
if os.path.exists(self.repo.store.annotation_path(basefile)):
annotation_graph = self.repo.annotation_file_to_graph(
self.repo.store.annotation_path(basefile))
g += annotation_graph
path = None
if contenttype in self._rdfformats:
data = g.serialize(format=self._rdfformats[contenttype])
Expand Down
2 changes: 1 addition & 1 deletion ferenda/sources/legal/se/res/sparql/dv-annotations.rq
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CONSTRUCT {
} WHERE
{
{
?inboundavgorande rpubl:rattsfall <%(uri)s> .
?inboundavgorande rpubl:rattsfallshanvisning <%(uri)s> .
?inboundreferat rpubl:referatAvDomstolsavgorande ?inboundavgorande ;
rdf:type ?referattyp ;
dcterms:identifier ?referatid .
Expand Down
1 change: 1 addition & 0 deletions lagen/nu/res/scripts/testdata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dv HDO/B3594-14 # Tystnadsplikt, TF
dv HFD/4453-10
dv HFD/4970-14
dv HDO/Ö3938-14
dv HDO/Ö1715-96_1 # referred to by another case
dv HFD/2015_not_1
dv REG/6970-09 # complicated OOXML structure that needs to be simplified
mediawiki Missbruksmodellen
Expand Down
22 changes: 21 additions & 1 deletion test/integrationLagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def test_extended_rdf(self):
got = Graph().parse(data=res.text)
self.assertEqualGraphs(g, got)


def test_extended_ntriples(self):
# extended test 7: accept: "/data" + "application/n-triples" -> extended
# RDF statements in NTriples
Expand Down Expand Up @@ -1271,7 +1272,26 @@ def test_autocomplete_expired(self):
hits = res.json()
self.assertEqual(hits[0]['url'], self.baseurl + "1998:204")
self.assertEqual(hits[0]['role'], "expired")


class DV(TestLagen):
def test_extended_rdf(self):
for doc, exact in (("nja/1996s439", False),
("nja/2015s180", True)):
# first get our reference graph and just assume that it's there
g = Graph().parse(data=self.get(self.baseurl + "dom/%s.rdf" % doc).text)

# then get the extended version and check if it works
res = self.get(self.baseurl + "dom/%s/data.rdf" % doc)
self.assertEqual(200, res.status_code)
self.assertEqual("application/rdf+xml; charset=utf-8", res.headers['Content-Type'])
got = Graph().parse(data=res.text)
self.assertEqualGraphs(g, got, exact)
if exact:
self.assertEqual(len(got), len(g))
else:
# the extended graph should have more data than the reference
self.assertGreater(len(got), len(g))

class Errorhandling(TestLagen):
def test_generated_missing(self):
rootdir = os.environ.get("FERENDA_TESTDATA", "tng.lagen.nu/data")
Expand Down
1 change: 0 additions & 1 deletion test/testManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,6 @@ def test_global_config(self):
self._enable_repos()
argv = ["test", "mpinspect", "--all", "--processes=2"]
res = manager.run(argv)
import pudb; pu.db
self.assertEqual(res, [(True, False), (True, False), (True, False)])

@quiet()
Expand Down

0 comments on commit d9803db

Please sign in to comment.