1
0
mirror of https://github.com/gsi-upm/senpy synced 2025-08-23 10:02:21 +00:00

Improved request handling

Also:
 * Shelve -> Pickle to avoid weird db problems
 * Serving schemas and contexts
This commit is contained in:
J. Fernando Sánchez
2016-02-21 19:36:24 +01:00
parent 407d17b2b9
commit b8339e397b
12 changed files with 191 additions and 157 deletions

View File

@@ -46,9 +46,6 @@ class BlueprintsTest(TestCase):
self.assert200(resp)
logging.debug("Got response: %s", resp.json)
assert "@context" in resp.json
assert check_dict(
resp.json["@context"],
{"marl": "http://www.gsi.dit.upm.es/ontologies/marl/ns#"})
assert "entries" in resp.json
def test_list(self):
@@ -111,3 +108,16 @@ class BlueprintsTest(TestCase):
sleep(0.5)
resp = self.client.get("/api/plugins/default/")
self.assert404(resp)
def test_context(self):
resp = self.client.get("/api/contexts/context.jsonld")
self.assert200(resp)
assert "@context" in resp.json
assert check_dict(
resp.json["@context"],
{"marl": "http://www.gsi.dit.upm.es/ontologies/marl/ns#"})
def test_schema(self):
resp = self.client.get("/api/schemas/definitions.json")
self.assert200(resp)
assert "$schema" in resp.json

View File

@@ -2,7 +2,9 @@ from __future__ import print_function
import os
import logging
from functools import partial
from senpy.extensions import Senpy
from senpy.models import Error
from flask import Flask
from flask.ext.testing import TestCase
@@ -54,9 +56,7 @@ class ExtensionsTest(TestCase):
def test_noplugin(self):
""" Don't analyse if there isn't any plugin installed """
self.senpy.deactivate_all(sync=True)
resp = self.senpy.analyse(input="tupni")
logging.debug("Response: {}".format(resp))
assert resp.status == 404
self.assertRaises(Error, partial(self.senpy.analyse, input="tupni"))
def test_analyse(self):
""" Using a plugin """
@@ -67,12 +67,6 @@ class ExtensionsTest(TestCase):
r2 = self.senpy.analyse(input="tupni", output="tuptuo")
assert r1.analysis[0].id[:5] == "Dummy"
assert r2.analysis[0].id[:5] == "Dummy"
for plug in self.senpy.plugins:
self.senpy.deactivate_plugin(plug, sync=True)
resp = self.senpy.analyse(input="tupni")
logging.debug("Response: {}".format(resp))
assert resp.status == 404
def test_filtering(self):
""" Filtering plugins """

View File

@@ -98,7 +98,7 @@ class ModelsTest(TestCase):
c = p.jsonld()
assert "info" not in c
assert "repo" not in c
assert "params" in c
assert "extra_params" in c
logging.debug("Framed:")
logging.debug(c)
p.validate()

View File

@@ -2,7 +2,7 @@
import os
import logging
import shelve
import pickle
import shutil
import tempfile
@@ -16,7 +16,6 @@ from senpy.plugins import SenpyPlugin, ShelfMixin
class ShelfTest(ShelfMixin, SenpyPlugin):
def test(self, key=None, value=None):
assert isinstance(self.sh, shelve.Shelf)
assert key in self.sh
print('Checking: sh[{}] == {}'.format(key, value))
print('SH[{}]: {}'.format(key, self.sh[key]))
@@ -49,7 +48,9 @@ class ModelsTest(TestCase):
a.sh['a'] = 'fromA'
a.test(key='a', value='fromA')
sh = shelve.open(self.shelf_file)
a.save()
sh = pickle.load(open(self.shelf_file, 'rb'))
assert sh['a'] == 'fromA'
@@ -61,7 +62,7 @@ class ModelsTest(TestCase):
'shelf_file': self.shelf_file})
print('Shelf file: %s' % a.shelf_file)
a.sh['a'] = 'fromA'
a.close()
a.save()
b = ShelfTest(info={'name': 'shelve',
'version': 'test',