class TestModuleController(trove_testtools.TestCase): def setUp(self): super(TestModuleController, self).setUp() self.controller = ModuleController() self.module = { "module": { "name": 'test_module', "module_type": 'test', "contents": 'my_contents\n', } } def verify_errors(self, errors, msg=None, properties=None, path=None): msg = msg or [] properties = properties or [] self.assertThat(len(errors), Is(len(msg))) i = 0 while i < len(msg): self.assertIn(errors[i].message, msg) if path: self.assertThat(path, Equals(properties[i])) else: self.assertThat(errors[i].path.pop(), Equals(properties[i])) i += 1 def test_get_schema_create(self): schema = self.controller.get_schema('create', {'module': {}}) self.assertIsNotNone(schema) self.assertTrue('module' in schema['properties']) def test_validate_create_complete(self): body = self.module schema = self.controller.get_schema('create', body) validator = jsonschema.Draft4Validator(schema) self.assertTrue(validator.is_valid(body)) def test_validate_create_blankname(self): body = self.module body['module']['name'] = " " schema = self.controller.get_schema('create', body) validator = jsonschema.Draft4Validator(schema) self.assertFalse(validator.is_valid(body)) errors = sorted(validator.iter_errors(body), key=lambda e: e.path) self.assertThat(len(errors), Is(1)) self.assertThat(errors[0].message, Equals("' ' does not match '^.*[0-9a-zA-Z]+.*$'")) def test_validate_create_invalid_name(self): body = self.module body['module']['name'] = "$#$%^^" schema = self.controller.get_schema('create', body) validator = jsonschema.Draft4Validator(schema) self.assertFalse(validator.is_valid(body)) errors = sorted(validator.iter_errors(body), key=lambda e: e.path) self.assertEqual(1, len(errors)) self.assertIn("'$#$%^^' does not match '^.*[0-9a-zA-Z]+.*$'", errors[0].message)
class TestModuleController(trove_testtools.TestCase): def setUp(self): super(TestModuleController, self).setUp() self.controller = ModuleController() self.module = { "module": { "name": 'test_module', "module_type": 'test', "contents": 'my_contents\n', "priority_apply": 0, "apply_order": 5 } } def test_get_schema_create(self): schema = self.controller.get_schema('create', {'module': {}}) self.assertIsNotNone(schema) self.assertIn('module', schema['properties']) def test_validate_create_complete(self): body = self.module schema = self.controller.get_schema('create', body) validator = jsonschema.Draft4Validator(schema) self.assertTrue(validator.is_valid(body)) def test_validate_create_blank_name(self): body = self.module body['module']['name'] = " " schema = self.controller.get_schema('create', body) validator = jsonschema.Draft4Validator(schema) self.assertFalse(validator.is_valid(body)) errors = sorted(validator.iter_errors(body), key=lambda e: e.path) self.assertThat(len(errors), Is(1)) self.assertThat(errors[0].message, Equals("' ' does not match '^.*[0-9a-zA-Z]+.*$'")) def test_validate_create_invalid_name(self): body = self.module body['module']['name'] = "$#$%^^" schema = self.controller.get_schema('create', body) validator = jsonschema.Draft4Validator(schema) self.assertFalse(validator.is_valid(body)) errors = sorted(validator.iter_errors(body), key=lambda e: e.path) self.assertEqual(1, len(errors)) self.assertIn("'$#$%^^' does not match '^.*[0-9a-zA-Z]+.*$'", errors[0].message) def test_validate_create_invalid_apply_order(self): body = self.module body['module']['apply_order'] = 12 schema = self.controller.get_schema('create', body) validator = jsonschema.Draft4Validator(schema) self.assertFalse(validator.is_valid(body)) errors = sorted(validator.iter_errors(body), key=lambda e: e.path) self.assertEqual(1, len(errors)) self.assertIn("12 is greater than the maximum of 9", errors[0].message)
def setUp(self): super(TestModuleController, self).setUp() self.controller = ModuleController() self.module = { "module": { "name": 'test_module', "module_type": 'test', "contents": 'my_contents\n', } }
def setUp(self): super(TestModuleController, self).setUp() self.controller = ModuleController() self.module = { "module": { "name": 'test_module', "module_type": 'test', "contents": 'my_contents\n', "priority_apply": 0, "apply_order": 5 } }
def _modules_router(self, mapper): modules_resource = ModuleController().create_resource() mapper.resource("modules", "/{tenant_id}/modules", controller=modules_resource) mapper.connect("/{tenant_id}/modules", controller=modules_resource, action="index", conditions={'method': ['GET']}) mapper.connect("/{tenant_id}/modules", controller=modules_resource, action="create", conditions={'method': ['POST']}) mapper.connect("/{tenant_id}/modules/{id}", controller=modules_resource, action="show", conditions={'method': ['GET']}) mapper.connect("/{tenant_id}/modules/{id}", controller=modules_resource, action="update", conditions={'method': ['PUT']}) mapper.connect("/{tenant_id}/modules/{id}", controller=modules_resource, action="delete", conditions={'method': ['DELETE']}) mapper.connect("/{tenant_id}/modules/{id}/instances", controller=modules_resource, action="instances", conditions={'method': ['GET']}) mapper.connect("/{tenant_id}/modules/{id}/instances", controller=modules_resource, action="reapply", conditions={'method': ['PUT']})