def test_arrays(self): old = { 'type': 'array', 'items': { 'description': 'description', 'type': 'object', 'properties': { 'foo': {'type': 'object', 'description': 'description'}, }, }, } new = { 'type': 'array', 'items': { 'description': 'description', 'type': 'object', 'properties': { 'foo': {'type': 'object', 'description': 'description'}, 'bar': {'type': 'object'}, }, }, } msgs = list(lint.walk_schema('name', old, new, root=True)) self.assertEqual(2, len(msgs)) self.assertEqual(msgs[0].level, lint.WARNING) self.assertEqual('name.items.bar.description', msgs[0].name) self.assertEqual(msgs[1].level, lint.DOCUMENTATION) self.assertEqual('name.items.bar.introduced_at', msgs[1].name)
def test_delete_property_is_error(self): old = { 'type': 'object', 'properties': { 'foo': { 'type': 'string' }, 'bar': { 'type': 'string' }, } } new = { 'type': 'object', 'properties': { 'foo': { 'type': 'string', 'description': 'description', 'introduced_at': 1, }, } } msgs = list(lint.walk_schema('name', old, new, root=True)) self.assertEqual(2, len(msgs)) self.assertEqual(msgs[0].level, lint.ERROR) self.assertEqual('name.bar', msgs[0].name) self.assertIsInstance(msgs[1], lint.CheckChangelog)
def test_type_changed_is_error_multiple_types(self): old = {'type': ['string', 'object']} new = {'type': 'object'} msgs = list(lint.walk_schema('name', old, new, root=True)) self.assertEqual(1, len(msgs)) self.assertEqual(msgs[0].level, lint.ERROR) self.assertEqual('name.type', msgs[0].name) self.assertIn('remove type string', msgs[0].msg)
def test_nested_objects(self): old = { 'type': 'object', 'properties': { 'foo': { 'type': 'object', 'required': ['bar'], 'properties': { 'bar': { 'type': 'string' }, 'baz': { 'type': 'string', 'description': 'description', 'introduced_at': 2, }, }, }, }, } new = { 'type': 'object', 'properties': { 'foo': { 'description': 'description', 'type': 'object', 'required': ['bar', 'foo'], # error for required change 'properties': { 'bar': { 'type': 'object', # type changed 'description': 'description' }, 'baz': { 'type': 'string', 'description': 'description', 'introduced_at': 3, # changed }, }, }, }, } msgs = list(lint.walk_schema('name', old, new, root=True)) self.assertEqual(3, len(msgs)) self.assertEqual(msgs[0].level, lint.ERROR) self.assertEqual('name.foo.required', msgs[0].name) self.assertEqual(msgs[1].level, lint.ERROR) self.assertEqual('name.foo.bar.type', msgs[1].name) self.assertEqual(msgs[2].level, lint.ERROR) self.assertEqual('name.foo.baz.introduced_at', msgs[2].name)
def test_no_introduced_at_when_present_in_old(self): old = { 'type': 'object', 'properties': { 'foo': {'type': 'object'}, }, } new = { 'type': 'object', 'properties': { 'foo': {'type': 'object', 'description': 'description'}, }, } msgs = list(lint.walk_schema('name', old, new, root=True)) self.assertEqual(0, len(msgs))
def test_missing_introduced_at_skipped_if_new_api(self): old = { 'type': 'object', } new = { 'type': 'object', 'properties': { 'foo': {'type': 'object'}, }, } msgs = list(lint.walk_schema( 'name', old, new, root=True, new_api=True )) self.assertEqual(1, len(msgs)) self.assertEqual(msgs[0].level, lint.WARNING) self.assertEqual('name.foo.description', msgs[0].name) self.assertIn('missing', msgs[0].msg)
def test_missing_doc_and_introduced_when_adding_new_field(self): old = { 'type': 'object', } new = { 'type': 'object', 'properties': { 'foo': {'type': 'object'}, }, } msgs = list(lint.walk_schema('name', old, new, root=True)) self.assertEqual(2, len(msgs)) self.assertEqual(msgs[0].level, lint.WARNING) self.assertEqual('name.foo.description', msgs[0].name) self.assertIn('missing', msgs[0].msg) self.assertEqual(msgs[1].level, lint.DOCUMENTATION) self.assertEqual('name.foo.introduced_at', msgs[1].name) self.assertIn('missing', msgs[1].msg)
def test_added_required_is_error(self): old = { 'type': 'object', 'required': ['foo'], 'properties': { 'foo': { 'type': 'string', 'description': 'description', 'introduced_at': 1, }, 'bar': { 'type': 'string', 'description': 'description', 'introduced_at': 1, }, } } new = { 'type': 'object', 'required': ['foo', 'bar'], 'properties': { 'foo': { 'type': 'string', 'description': 'description', 'introduced_at': 1, }, 'bar': { 'type': 'string', 'description': 'description', 'introduced_at': 1, }, } } msgs = list(lint.walk_schema('name', old, new, root=True)) self.assertEqual(3, len(msgs)) self.assertEqual('name.required', msgs[0].name) self.assertIn('bar', msgs[0].msg) self.assertIsInstance(msgs[1], lint.CheckChangelog) self.assertIsInstance(msgs[2], lint.CheckChangelog)