def __init__(self, endpoint, method, **kwargs): self.endpoint = endpoint self.method = method self.vars = Variables(**kwargs.get('variables', {})) self.mimetype = kwargs.get('mimetype', None) self.url = endpoint.url self.description = kwargs.get('description', None) self.traversal = kwargs.get('traverse', None) self.timeout = kwargs.get('timeout', 5)
def __init__(self, hive, *args, **kwargs): self._root = hive.get('root') self._mimetype = hive.get('mimetype', 'application/json') self._vars = Variables(variable_settings=hive.get( 'variable_settings', {}), **hive.get('variables', {})).fill(*args, **kwargs) self._endpoints = {} self._description = hive.get('description', None) self._name = hive.get('name', None) self._objects = {} for name, endpoint in hive['endpoints'].items(): self.add_endpoint(name, **endpoint) for name, obj in hive['objects'].items(): self.add_object(name, obj)
def __init__(self, parent, path, **kwargs): self.parent = parent self.path = path self.vars = Variables(**kwargs.get('variables', {})) self.methods = kwargs.get('methods', ['GET']) self.mimetype = kwargs.get('mimetype', None)
def setUp(self): self.variables = Variables(variable_settings=dict(default_type='type'),x=variable_1, y=variable_2)
class VariablesTest(unittest.TestCase): def setUp(self): self.variables = Variables(variable_settings=dict(default_type='type'),x=variable_1, y=variable_2) def test_create(self): self.assertEqual(self.variables, {'x':variable_1, 'y': variable_2}) def test_types(self): self.variables.add(z=variable_3, a=variable_4) self.assertIn('type1_1', self.variables.types()) self.assertIn('type1_2', self.variables.types()) self.assertIn('type2_1', self.variables.types()) self.assertIn('type', self.variables.types()) def test_vals(self): self.variables.add(z=variable_4) self.assertEqual(self.variables.vals('type'), {'z': Variable('type',**variable_4)}) def test_fill_kwargs(self): self.variables.fill_kwargs(x='value_of_x', y='value_of_y') self.assertEqual(self.variables['x']['value'], 'value_of_x') self.assertEqual(self.variables['y']['value'], 'value_of_y') def test_fill_args(self): self.variables.add(a=variable_3) teststr = 'this should go under a' self.variables.fill_arg(teststr) self.assertEqual(self.variables['a']['value'], teststr) def test_fill(self): self.variables.add(a=variable_3) teststr = 'this should go under a' self.variables.fill(teststr, x='valx', y='valy') self.assertEqual(self.variables['x']['value'], 'valx') self.assertEqual(self.variables['y']['value'], 'valy') self.assertEqual(self.variables['a']['value'], teststr) def test_filled_when_not(self): self.variables.add(a=variable_3) with self.assertRaises(TypeError): self.variables.fill() def test_missing_vars(self): self.variables.add(a=variable_3) self.assertEqual(self.variables.missing_vars(), ['a']) def test_keyword_named_variable(self): self.variables.add(**{'from':variable_3}) self.assertIn('_from', self.variables) self.assertEqual(self.variables['_from']['name'], 'from')