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

Add plugin method to client

Closes #28
This commit is contained in:
J. Fernando Sánchez
2017-04-07 18:20:38 +02:00
parent 14c86ec38c
commit e0b4c76238
5 changed files with 68 additions and 32 deletions

View File

@@ -4,18 +4,21 @@ try:
except ImportError:
from mock import patch
import json
from senpy.client import Client
from senpy.models import Results, Error
from senpy.models import Results, Plugins, Error
from senpy.plugins import AnalysisPlugin, default_plugin_type
class Call(dict):
def __init__(self, obj):
self.obj = obj.jsonld()
self.obj = obj.serialize()
self.status_code = 200
self.content = self.json()
def json(self):
return self.obj
return json.loads(self.obj)
class ModelsTest(TestCase):
@@ -44,3 +47,19 @@ class ModelsTest(TestCase):
method='GET',
params={'input': 'hello',
'algorithm': 'NONEXISTENT'})
def test_plugins(self):
endpoint = 'http://dummy/'
client = Client(endpoint)
plugins = Plugins()
p1 = AnalysisPlugin({'name': 'AnalysisP1', 'version': 0, 'description': 'No'})
plugins.plugins = [p1, ]
success = Call(plugins)
with patch('requests.request', return_value=success) as patched:
response = client.plugins()
assert isinstance(response, dict)
assert len(response) == 1
assert "AnalysisP1" in response
patched.assert_called_with(
url=endpoint + '/plugins', method='GET',
params={'plugin_type': default_plugin_type})

View File

@@ -170,7 +170,7 @@ class ModelsTest(TestCase):
def test_single_plugin(self):
"""A response with a single plugin should still return a list"""
plugs = Plugins()
p = Plugin({'id': str(0),
p = Plugin({'id': str(1),
'version': 0,
'description': 'dummy'})
plugs.plugins.append(p)