1
0
mirror of https://github.com/gsi-upm/senpy synced 2025-08-23 18:12:20 +00:00

PEP8+Better JSON-LD support

* The API has also changed, there are new parameters to send the
context as part of the headers.
* Improved tests
* PEP8 compliance (despite the line about gevent)
This commit is contained in:
J. Fernando Sánchez
2015-02-24 07:15:25 +01:00
parent d58137e8f9
commit d1006bbc92
17 changed files with 416 additions and 207 deletions

View File

@@ -9,6 +9,7 @@ from senpy.extensions import Senpy
from flask import Flask
from flask.ext.testing import TestCase
from gevent import sleep
from itertools import product
def check_dict(indic, template):
@@ -16,6 +17,7 @@ def check_dict(indic, template):
class BlueprintsTest(TestCase):
def create_app(self):
self.app = Flask("test_extensions")
self.senpy = Senpy()
@@ -26,24 +28,31 @@ class BlueprintsTest(TestCase):
return self.app
def test_home(self):
""" Calling with no arguments should ask the user for more arguments """
"""
Calling with no arguments should ask the user for more arguments
"""
resp = self.client.get("/")
self.assert200(resp)
self.assert404(resp)
logging.debug(resp.json)
assert resp.json["status"] == "failed"
assert resp.json["status"] == 404
atleast = {
"status": "failed",
"status": 404,
"message": "Missing or invalid parameters",
}
assert check_dict(resp.json, atleast)
def test_analysis(self):
""" The dummy plugin returns an empty response, it should contain the context """
"""
The dummy plugin returns an empty response,\
it should contain the context
"""
resp = self.client.get("/?i=My aloha mohame")
self.assert200(resp)
logging.debug(resp.json)
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 check_dict(
resp.json["@context"],
{"marl": "http://www.gsi.dit.upm.es/ontologies/marl/ns#"})
assert "entries" in resp.json
def test_list(self):
@@ -52,6 +61,19 @@ class BlueprintsTest(TestCase):
self.assert200(resp)
logging.debug(resp.json)
assert "Dummy" in resp.json
assert "@context" in resp.json
def test_headers(self):
for i, j in product(["/plugins/?nothing=", "/?i=test&"],
["headers", "inHeaders"]):
resp = self.client.get("%s" % (i))
assert "@context" in resp.json
resp = self.client.get("%s&%s=0" % (i, j))
assert "@context" in resp.json
resp = self.client.get("%s&%s=1" % (i, j))
assert "@context" not in resp.json
resp = self.client.get("%s&%s=true" % (i, j))
assert "@context" not in resp.json
def test_detail(self):
""" Show only one plugin"""
@@ -77,3 +99,16 @@ class BlueprintsTest(TestCase):
self.assert200(resp)
assert "is_activated" in resp.json
assert resp.json["is_activated"] == True
def test_default(self):
""" Show only one plugin"""
resp = self.client.get("/default")
self.assert200(resp)
logging.debug(resp.json)
assert "@id" in resp.json
assert resp.json["@id"] == "Dummy_0.1"
resp = self.client.get("/plugins/Dummy/deactivate")
self.assert200(resp)
sleep(0.5)
resp = self.client.get("/default")
self.assert404(resp)