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

71 lines
2.5 KiB
Python
Raw Permalink Normal View History

2014-11-07 18:12:21 +00:00
import os
import logging
2014-11-20 18:29:49 +00:00
2014-11-07 18:12:21 +00:00
try:
import unittest.mock as mock
except ImportError:
import mock
from senpy.extensions import Senpy
from flask import Flask
from flask.ext.testing import TestCase
2014-11-20 18:29:49 +00:00
class ExtensionsTest(TestCase):
2014-11-07 18:12:21 +00:00
def create_app(self):
self.app = Flask("test_extensions")
self.dir = os.path.join(os.path.dirname(__file__), "..")
2014-11-26 21:09:02 +00:00
self.senpy = Senpy(plugin_folder=self.dir)
self.senpy.init_app(self.app)
2014-11-07 18:12:21 +00:00
return self.app
def test_init(self):
""" Initialising the app with the extension. """
assert hasattr(self.app, "senpy")
tapp = Flask("temp app")
2014-11-20 18:29:49 +00:00
self.senpy.init_app(tapp)
2014-11-07 18:12:21 +00:00
assert hasattr(tapp, "senpy")
def test_discovery(self):
""" Discovery of plugins in given folders. """
2014-11-20 18:29:49 +00:00
# noinspection PyProtectedMember
2014-11-07 18:12:21 +00:00
assert self.dir in self.senpy._search_folders
print self.senpy.plugins
assert "dummy" in self.senpy.plugins
def test_enabling(self):
""" Enabling a plugin """
2014-11-26 21:09:02 +00:00
self.senpy.activate_plugin("dummy")
assert self.senpy.plugins["dummy"].is_activated
2014-11-07 18:12:21 +00:00
def test_disabling(self):
""" Disabling a plugin """
2014-11-26 21:09:02 +00:00
self.senpy.activate_plugin("dummy")
self.senpy.deactivate_plugin("dummy")
assert not self.senpy.plugins["dummy"].is_activated
2014-11-07 18:12:21 +00:00
def test_default(self):
""" Default plugin should be set """
assert self.senpy.default_plugin
assert self.senpy.default_plugin == "dummy"
def test_analyse(self):
""" Using a plugin """
with mock.patch.object(self.senpy.plugins["dummy"], "analyse") as mocked:
self.senpy.analyse(algorithm="dummy", input="tupni", output="tuptuo")
self.senpy.analyse(input="tupni", output="tuptuo")
mocked.assert_any_call(input="tupni", output="tuptuo", algorithm="dummy")
mocked.assert_any_call(input="tupni", output="tuptuo")
for plug in self.senpy.plugins:
2014-11-26 21:09:02 +00:00
self.senpy.deactivate_plugin(plug)
2014-11-07 18:12:21 +00:00
resp = self.senpy.analyse(input="tupni")
logging.debug("Response: {}".format(resp))
assert resp["status"] == 400
def test_filtering(self):
""" Filtering plugins """
2014-11-20 18:29:49 +00:00
assert len(self.senpy.filter_plugins(name="dummy")) > 0
2014-11-07 18:12:21 +00:00
assert not len(self.senpy.filter_plugins(name="notdummy"))
2014-11-26 21:09:02 +00:00
assert self.senpy.filter_plugins(name="dummy", is_activated=True)
self.senpy.deactivate_plugin("dummy")
assert not len(self.senpy.filter_plugins(name="dummy", is_activated=True))