def test_entities(self, mock_parse_entity): mock_parse_entity.return_value = [{'name': 'entity2'}] data = { 'key1': 'val1', 'key2': 'val2', 'entities': [ { 'name': 'entity1', 'objectClassName': 'derp' }, { 'name': 'entity2', 'objectClassName': 'entity' }, { 'name': 'entity3', 'objectClassName': 'herp' } ], 'handle': 'handle' } expected = [{'class': 'root', 'handle': 'handle'}, {'name': 'entity2'}] actual = rdap._process_data(data) self.assertEqual(expected, actual)
def test_no_desired_fields(self): data = { 'key1': 'val1', 'key2': 'val2' } expected = [{'class': 'root'}] actual = rdap._process_data(data) self.assertEqual(expected, actual)
def test_status(self): data = { 'key1': 'val1', 'key2': 'val2', 'status': ['status1', 'status2'] } expected = [{'class': 'root', 'status': 'status1,status2'}] actual = rdap._process_data(data) self.assertEqual(expected, actual)
def test_interesting_fields(self): data = { 'key1': 'val1', 'key2': 'val2', 'handle': 'cool_handle', 'name': 'cool_name' } expected = [{'class': 'root', 'handle': 'cool_handle', 'name': 'cool_name'}] actual = rdap._process_data(data) self.assertEqual(expected, actual)
def test_events(self, mock_parse_events): mock_parse_events.return_value = {'event1': 'derp', 'event2': 'herp'} data = { 'key1': 'val1', 'key2': 'val2', 'events': 'events' } expected = [{'class': 'root', 'event1': 'derp', 'event2': 'herp'}] actual = rdap._process_data(data) self.assertEqual(expected, actual)
def test(self, mock_parse_events, mock_parse_entity): mock_parse_events.return_value = {'event1': 'derp', 'event2': 'herp'} mock_parse_entity.return_value = [{'name': 'entity2'}] data = { 'key1': 'val1', 'key2': 'val2', 'handle': 'cool_handle', 'name': 'cool_name', 'events': 'events', 'status': ['status1', 'status2'], 'entities': [ { 'name': 'entity1', 'objectClassName': 'derp' }, { 'name': 'entity2', 'objectClassName': 'entity' }, { 'name': 'entity3', 'objectClassName': 'herp' } ] } expected = [ { 'class': 'root', 'handle': 'cool_handle', 'name': 'cool_name', 'event1': 'derp', 'event2': 'herp', 'status': 'status1,status2' }, { 'name': 'entity2' } ] actual = rdap._process_data(data) self.assertEqual(expected, actual)
def test_entities_none_desired(self): data = { 'key1': 'val1', 'key2': 'val2', 'entities': [ { 'name': 'entity1', 'objectClassName': 'derp' }, { 'name': 'entity2', 'objectClassName': 'herp' } ] } expected = [{'class': 'root'}] actual = rdap._process_data(data) self.assertEqual(expected, actual)
def test_not_dict(self): with self.assertRaises(Exception): rdap._process_data(['i', 'am', 'a', 'list'])