1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-11-23 00:22:28 +00:00
senpy/tests/models_test/__init__.py

82 lines
2.4 KiB
Python
Raw Normal View History

2015-02-23 01:13:31 +00:00
import os
import logging
try:
import unittest.mock as mock
except ImportError:
import mock
import json
import os
from unittest import TestCase
from senpy.models import Response, Entry
2015-02-23 01:13:31 +00:00
from senpy.plugins import SenpyPlugin
2015-02-23 01:13:31 +00:00
class ModelsTest(TestCase):
2015-02-23 01:13:31 +00:00
def test_response(self):
r = Response(context=os.path.normpath(
os.path.join(__file__, "..", "..", "context.jsonld")))
2015-02-23 01:13:31 +00:00
assert("@context" in r)
assert(r._frame)
logging.debug("Default frame: %s", r._frame)
2015-02-23 01:13:31 +00:00
assert("marl" in r.context)
assert("entries" in r.context)
2015-02-23 01:13:31 +00:00
r2 = Response(context=json.loads('{"test": "roger"}'))
assert("test" in r2.context)
2015-02-23 01:13:31 +00:00
r3 = Response(context=None)
del r3.context
assert("@context" not in r3)
assert("entries" in r3)
assert("analysis" in r3)
r4 = Response()
assert("@context" in r4)
assert("entries" in r4)
assert("analysis" in r4)
dummy = SenpyPlugin({"name": "dummy", "version": 0})
r5 = Response({"dummy": dummy}, context=None, frame=None)
logging.debug("Response 5: %s", r5)
assert("dummy" in r5)
assert(r5["dummy"].name == "dummy")
js = r5.jsonld(context={}, frame={})
logging.debug("jsonld 5: %s", js)
assert("dummy" in js)
assert(js["dummy"].name == "dummy")
r6 = Response()
r6.entries.append(Entry(text="Just testing"))
logging.debug("Reponse 6: %s", r6)
assert("@context" in r6)
assert("marl" in r6.context)
assert("entries" in r6.context)
js = r6.jsonld()
logging.debug("jsonld: %s", js)
assert("entries" in js)
assert("entries" in js)
assert("analysis" in js)
resp = r6.flask()
received = json.loads(resp.data)
logging.debug("Response: %s", js)
assert(received["entries"])
assert(received["entries"][0]["text"] == "Just testing")
assert(received["entries"][0]["text"] != "Not testing")
2015-02-23 01:13:31 +00:00
def test_opinions(self):
pass
def test_plugins(self):
2015-02-23 01:13:31 +00:00
p = SenpyPlugin({"name": "dummy", "version": 0})
c = p.jsonld()
2015-02-23 01:13:31 +00:00
assert "info" not in c
assert "repo" not in c
assert "params" not in c
logging.debug("Framed: %s", c)
assert "extra_params" in c
2015-02-23 01:13:31 +00:00
def test_frame_response(self):
pass