Skip to content

Commit

Permalink
Documentation & CI Configs & Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PonteIneptique committed Jun 16, 2016
1 parent 96cfdea commit db4d8c4
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 92 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: python
python:
- "3.4"
# command to install dependencies
install:
- python setup.py develop
- pip install coveralls
# command to run tests
script:
- coverage run --source=nemo_arethusa_plugin setup.py test
after_success:
- coveralls
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ Arethusa for CapiTainS Nemo
:alt: Documentation
:target: http://nemo-arethusa-plugin.readthedocs.io/

.. image:: https://travis-ci.org/alpheios/nemo-arethusa-plugin.svg
.. image:: https://travis-ci.org/alpheios-project/nemo_arethusa_plugin.svg
:alt: Build status
:target: https://travis-ci.org/alpheios/nemo-arethusa-plugin
:target: https://travis-ci.org/alpheios-project/nemo_arethusa_plugin

.. image:: https://coveralls.io/repos/alpheios/nemo-arethusa-plugin/badge.svg?branch=master&service=github
.. image:: https://coveralls.io/repos/alpheios-project/nemo_arethusa_plugin/badge.svg?branch=master&service=github
:alt: Coverage
:target: https://coveralls.io/github/alpheios/nemo-arethusa-plugin?branch=master
:target: https://coveralls.io/github/alpheios-project/nemo_arethusa_plugin?branch=master

.. image:: https://badge.fury.io/py/nemo_arethusa_plugin.svg
:target: https://badge.fury.io/py/nemo_arethusa_plugin
Expand Down
10 changes: 5 additions & 5 deletions nemo_arethusa_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class Arethusa(AnnotationsApiPlugin):
The overall plugins contains three new routes (on top of AnnotationsAPIPlugin) :
- ``/arethusa.deps.json`` which feeds informations about Arethusa assets dependencies
- ``/arethusa-assets/<filename>`` which is a self implemented assets route.
- ``/arethusa.config.json`` which is the config for the widget
- :code:`/arethusa.deps.json` which feeds informations about Arethusa assets dependencies
- :code:`/arethusa-assets/<filename>` which is a self implemented assets route.
- :code:`/arethusa.config.json` which is the config for the widget
It contains two new templates :
- a ``arethusa::text.html`` template which overrides the original when there is treebank available
- a ``arethusa::widget.tree.json`` template which providees the configuration for the widget
- a :code:`arethusa::text.html` template which overrides the original when there is treebank available
- a :code:`arethusa::widget.tree.json` template which providees the configuration for the widget
It contains a render functions which will use the arethusa::text.html instead of main::text.html if there is a treebank found within the QueryInterface
Expand Down
26 changes: 1 addition & 25 deletions tests/resources.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
from flask import Flask
from flask_nemo import Nemo
from flask_nemo.chunker import level_grouper
from capitains_nautilus.mycapytain import NautilusRetriever


NautilusDummy = NautilusRetriever(
folders=[
"./tests/test_data/latinLit"
]
)


def make_client(*plugins, output_nemo=False):
""" Create a test client with *plugins inserted
:param plugins: plugins instances
:return:
"""
app = Flask("Nemo")
app.debug = True
nemo = Nemo(
app=app,
base_url="",
retriever=NautilusDummy,
chunker={"default": lambda x, y: level_grouper(x, y, groupby=30)},
plugins=plugins
)
if output_nemo:
return nemo, app.test_client()
return app.test_client()
)
89 changes: 89 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
from unittest import TestCase
from .resources import NautilusDummy
from flask import Flask
from flask_nemo import Nemo
from flask_nemo.chunker import level_grouper
from flask_nemo.query.interface import SimpleQuery
from flask_nemo.query.resolve import LocalRetriever, Resolver
from nemo_arethusa_plugin import Arethusa
import json


class TestPlugin(TestCase):
def setUp(self):
TB_URI = "http://data.perseus.org/rdfvocab/treebank"

app = Flask("Nemo")
app.debug = True
self.interface = SimpleQuery(
[
("urn:cts:latinLit:phi1294.phi002.perseus-lat2:6.1", "treebanks/treebank1.xml", TB_URI),
("urn:cts:latinLit:phi1294.phi002.perseus-lat2:1.5", "treebanks/treebank2.xml", TB_URI),
("urn:cts:latinLit:phi1294.phi002.perseus-lat2:6.1", "images/N0060308_TIFF_145_145.tif", "dc:image"),
("urn:cts:latinLit:phi1294.phi002.perseus-lat2:6.2", "images/N0060308_TIFF_145_145.tif", "dc:image")
],
resolver=Resolver(LocalRetriever(path="./tests/test_data/"))
)
self.arethusa = Arethusa(queryinterface=self.interface)
app.debug = True
nemo = Nemo(
app=app,
base_url="",
retriever=NautilusDummy,
chunker={"default": lambda x, y: level_grouper(x, y, groupby=30)},
plugins=[self.arethusa]
)
self.interface.process(nemo)
self.client = app.test_client()

def test_text_with_treebank(self):
"""Ensure treebank are visible"""
data = self.client.get("/read/latinLit/phi1294/phi002/perseus-lat2/6.1").data.decode("utf-8")
self.assertIn(
">Treebank</a>", data,
"Treebank tab should be visible when there is a treebank"
)
self.assertIn(
self.interface.annotations[0].sha, data,
"Treebank sha should be visible in scripts"
)

def test_text_without_treebank(self):
"""Ensure treebank are not loaded"""
data = self.client.get("/read/latinLit/phi1294/phi002/perseus-lat2/6.2").data.decode("utf-8")
self.assertNotIn(
">Treebank</a>", data,
"Treebank tab should not be visible when there is no treebank"
)
data = self.client.get("/read/latinLit/phi1294/phi002/perseus-lat2/6.3").data.decode("utf-8")
self.assertNotIn(
">Treebank</a>", data,
"Treebank tab should not be visible when there is no treebank"
)

def test_asset_route(self):
""" Ensure assets are accessible """
response = self.client.get("/arethusa-assets/js/arethusa.min.js")
self.assertEqual(response.status_code, 200, "Assets should be accessible")

def test_dependencies_config(self):
""" Ensure dependencies json are working """
data = json.loads(self.client.get("/arethusa.deps.json").data.decode("utf-8"))
self.assertCountEqual(list(data.keys()), ["js", "css"], "Dict should have two dict : js and css")
self.assertCountEqual(list(data["js"].keys()), ["arethusa", "packages"], "Js should have required pkgs")
self.assertCountEqual(list(data["css"].keys()), ["arethusa", "colorpicker", "foundation", "font_awesome"],
"Js should have required pkgs")
counter = 6

for url in list(data["js"].values()) + list(data["css"].values()):
self.assertEqual(self.client.get(url).status_code, 200, "Assets should be accessible")
counter -= 1
self.assertEqual(counter, 0)

def test_arethusa_config(self):
""" Ensure the config for Arethusa contains the right URI """
data = json.loads(self.client.get("/arethusa.config.json").data.decode("utf-8"))
self.assertEqual(
data["resources"]["arethusaServerTreebank"]["route"], "/api/annotations/:doc/body",
"Route to annotation API body should be available"
)
58 changes: 0 additions & 58 deletions tests/test_methods.py

This file was deleted.

0 comments on commit db4d8c4

Please sign in to comment.