def test_basic(self): a = {} self.assertRaises(Error, parse_params, a) self.assertRaises(Error, parse_params, a, NIF_PARAMS) a = {'input': 'hello'} p = parse_params(a, NIF_PARAMS) assert 'input' in p b = {'i': 'hello'} p = parse_params(b, NIF_PARAMS) assert 'input' in p
def test_parameters2(self): in1 = {'meaningcloud-key': 5} in2 = {'apikey': 25} extra_params = { "apikey": { "aliases": ["apikey", "meaningcloud-key"], "required": True } } p1 = parse_params(in1, extra_params) p2 = parse_params(in2, extra_params) assert (p2['apikey'] / p1['apikey']) == 5
def test_basic(self): a = {} try: parse_params(a, spec=NIF_PARAMS) raise AssertionError() except Error: pass a = {'input': 'hello'} p = parse_params(a, spec=NIF_PARAMS) assert 'input' in p b = {'i': 'hello'} p = parse_params(b, spec=NIF_PARAMS) assert 'input' in p
def test_call(self): call = {'input': "Aloha my friend", 'algo': "Dummy"} p = parse_params(call, API_PARAMS, NIF_PARAMS) assert 'algorithm' in p assert "Dummy" in p['algorithm'] assert 'input' in p assert p['input'] == 'Aloha my friend'
def test_call(self): call = { 'input': "Aloha my friend", 'algo': "Dummy" } p = parse_params(call, API_PARAMS, NIF_PARAMS) assert 'algorithm' in p assert "Dummy" in p['algorithm'] assert 'input' in p assert p['input'] == 'Aloha my friend'
def test_parameters2(self): in1 = { 'meaningcloud-key': 5 } in2 = { 'apikey': 25 } extra_params = { "apikey": { "aliases": [ "apikey", "meaningcloud-key" ], "required": True } } p1 = parse_params(in1, extra_params) p2 = parse_params(in2, extra_params) assert (p2['apikey'] / p1['apikey']) == 5
def test_plugin(self): query = {} plug_params = { 'hello': { 'aliases': ['hiya', 'hello'], 'required': True } } self.assertRaises(Error, parse_params, plug_params) query['hello'] = 'world' p = parse_params(query, plug_params) assert 'hello' in p assert p['hello'] == 'world' del query['hello'] query['hiya'] = 'dlrow' p = parse_params(query, plug_params) assert 'hello' in p assert p['hello'] == 'dlrow'
def test_default(self): spec = { 'hello': { 'required': True, 'default': 1 } } p = parse_params({}, spec=spec) assert 'hello' in p assert p['hello'] == 1
def test_plugin(self): query = {} plug_params = { 'hello': { 'aliases': ['hello', 'hiya'], 'required': True } } self.assertRaises(Error, parse_params, plug_params) query['hello'] = 'world' p = parse_params(query, plug_params) assert 'hello' in p assert p['hello'] == 'world' del query['hello'] query['hiya'] = 'dlrow' p = parse_params(query, plug_params) assert 'hello' in p assert p['hello'] == 'dlrow'
def test_plugin(self): query = {} plug_params = { 'hello': { 'aliases': ['hello', 'hiya'], 'required': True } } try: parse_params(query, spec=plug_params) raise AssertionError() except Error: pass query['hello'] = 'world' p = parse_params(query, spec=plug_params) assert 'hello' in p assert p['hello'] == 'world' del query['hello'] query['hiya'] = 'dlrow' p = parse_params(query, spec=plug_params) assert 'hello' in p assert 'hiya' in p assert p['hello'] == 'dlrow'
def test_api_params(self): """The API should not define any required parameters without a default""" parse_params({}, API_PARAMS)
def test_web_params(self): """The WEB should not define any required parameters without a default""" parse_params({}, spec=WEB_PARAMS)
def test_api_params(self): """The API should not define any required parameters without a default""" parse_params({}, spec=API_PARAMS)
def test_default(self): spec = {'hello': {'required': True, 'default': 1}} p = parse_params({}, spec) assert 'hello' in p assert p['hello'] == 1
def analyse(instance, **kwargs): basic = api.parse_params(kwargs, api.API_PARAMS) request = api.parse_call(basic) return instance.analyse(request)
def test_web_params(self): """The WEB should not define any required parameters without a default""" parse_params({}, WEB_PARAMS)