Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 38 #40

Merged
merged 5 commits into from
Mar 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions flask_nemo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import jinja2
from flask import request, render_template, Blueprint, abort, Markup, send_from_directory, Flask
import MyCapytain.endpoints.cts5
from MyCapytain.endpoints.proto import CTS as CtsProtoEndpoint
import MyCapytain.resources.texts.tei
import MyCapytain.resources.texts.api
import MyCapytain.resources.inventory
Expand All @@ -33,6 +34,8 @@ class Nemo(object):
:type app: Flask
:param api_url: URL of the API Endpoint
:type api_url: str
:param endpoint: CTS Endpoint (Will be defaulted to api_url using cts5 endpoint if necessary)
:type endpoint: MyCapytain.endpoints.proto.CTS
:param base_url: Base URL to use when registering the endpoint
:type base_url: str
:param cache: SQLITE cache file name
Expand Down Expand Up @@ -105,7 +108,7 @@ class Nemo(object):
"f_order_author"
]

def __init__(self, name=None, app=None, api_url="/", base_url="/nemo", cache=None, expire=3600,
def __init__(self, name=None, app=None, api_url="/", endpoint=None, base_url="/nemo", cache=None, expire=3600,
template_folder=None, static_folder=None, static_url_path=None,
urls=None, inventory=None, transform=None, urntransform=None, chunker=None, prevnext=None,
css=None, js=None, templates=None, statics=None):
Expand All @@ -115,7 +118,11 @@ def __init__(self, name=None, app=None, api_url="/", base_url="/nemo", cache=Non
self.name = name
self.prefix = base_url
self.api_url = api_url
self.endpoint = MyCapytain.endpoints.cts5.CTS(self.api_url)

if isinstance(endpoint, CtsProtoEndpoint):
self.endpoint = endpoint
else:
self.endpoint = MyCapytain.endpoints.cts5.CTS(self.api_url)

self.templates = copy(Nemo.TEMPLATES)
if isinstance(templates, dict):
Expand Down Expand Up @@ -1188,8 +1195,8 @@ def cmd():
app=app,
name="nemo",
base_url="",
css=[ args.css ],
inventory = args.inventory,
css=[args.css],
inventory=args.inventory,
api_url=args.endpoint,
chunker={"default": lambda x, y: Nemo.level_grouper(x, y, groupby=args.groupby)}
)
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MyCapytain==0.1.0
requests_cache==0.4.9
Flask==0.10.1
MyCapytain>=0.1.1
requests_cache>=0.4.9
Flask>=0.10.1
13 changes: 7 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

setup(
name='flask_nemo',
version="0.0.2",
packages = find_packages(exclude=["examples"]),
version="0.0.3",
packages=find_packages(exclude=["examples"]),
url='https://github.com/capitains/flask-capitains-nemo',
license='GNU GPL',
author='Thibault Clerice',
author_email='leponteineptique@gmail.com',
description='Flask Extension to Browse CTS Repository',
test_suite="test_flask_nemo",
test_suite="tests",
install_requires=[
"MyCapytain>=0.1.0",
"requests_cache==0.4.9",
"Flask==0.10.1"
"requests_cache>=0.4.9",
"Flask>=0.10.1"
],
tests_require=[
"mock==1.0.1"
"mock==1.0.1",
"capitains_nautilus>=0.0.2"
],
entry_points={
'console_scripts': ['capitains-nemo=flask_nemo:cmd'],
Expand Down
Empty file added tests/__init__.py
Empty file.
63 changes: 63 additions & 0 deletions tests/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import unittest
from flask.ext.nemo import Nemo
from flask import Markup, Flask
from capitains_nautilus.mycapytain import NautilusEndpoint

def create_test_app(debug=False, config=None):
app = Flask(__name__)
app.debug = debug

if config:
app.config.update(**config)
return app


class RequestPatch(object):
""" Request patch object to deal with patching reply in flask.ext.nemo
"""
def __init__(self, f):
self.__text = f.read()

@property
def text(self):
return self.__text


class RequestPatchChained(object):
""" Request patch object to deal with patching reply in flask.ext.nemo
"""
def __init__(self, requests):
self.resource = [other.text for other in requests]

@property
def text(self):
return self.resource.pop(0)


class NemoResource(unittest.TestCase):
""" Test Suite for Nemo
"""
endpoint = "http://website.com/cts/api"
body_xsl = "testing_data/xsl_test.xml"

def setUp(self):
with open("testing_data/getcapabilities.xml", "r") as f:
self.getCapabilities = RequestPatch(f)

with open("testing_data/getvalidreff.xml", "r") as f:
self.getValidReff_single = RequestPatch(f)
self.getValidReff = RequestPatchChained([self.getCapabilities, self.getValidReff_single])

with open("testing_data/getpassage.xml", "r") as f:
self.getPassage = RequestPatch(f)
self.getPassage_Capabilities = RequestPatchChained([self.getCapabilities, self.getPassage])

with open("testing_data/getprevnext.xml", "r") as f:
self.getPrevNext = RequestPatch(f)
self.getPassage_Route = RequestPatchChained([self.getCapabilities, self.getPassage, self.getPrevNext])

self.nemo = Nemo(
api_url=NemoResource.endpoint
)

NautilusDummy = NautilusEndpoint(folders=["./tests/test_data/nautilus/farsiLit", "./tests/test_data/nautilus/latinLit"])