def test_get_by_index(self): """Ensure an address can be found by input index""" collection = AddressCollection([ {'input_index': 3, 'input_id': 'A'}, {'input_index': 5, 'input_id': 'h'}, {'input_index': 8, 'input_id': 'X'}, ]) self.assertEqual(collection.get_index(3).id, 'A') self.assertEqual(collection.get_index(5).id, 'h') self.assertEqual(collection.get_index(8).id, 'X') self.assertRaises(KeyError, collection.get_index, 10)
def test_get_by_id(self): """Ensure an address can be found by input_id""" collection = AddressCollection([ {'input_index': 3, 'input_id': 'A'}, {'input_index': 5, 'input_id': 'h'}, {'input_index': 8, 'input_id': 'X'}, ]) self.assertEqual(collection.get('A').index, 3) self.assertEqual(collection.get('h').index, 5) self.assertEqual(collection.get('X').index, 8) self.assertRaises(KeyError, collection.get_index, 'kj')
def test_get_by_index(self): """Ensure an address can be found by input index""" collection = AddressCollection([ { 'input_index': 3, 'input_id': 'A' }, { 'input_index': 5, 'input_id': 'h' }, { 'input_index': 8, 'input_id': 'X' }, ]) self.assertEqual(collection.get_index(3).id, 'A') self.assertEqual(collection.get_index(5).id, 'h') self.assertEqual(collection.get_index(8).id, 'X') self.assertRaises(KeyError, collection.get_index, 10)
def test_get_by_id(self): """Ensure an address can be found by input_id""" collection = AddressCollection([ { 'input_index': 3, 'input_id': 'A' }, { 'input_index': 5, 'input_id': 'h' }, { 'input_index': 8, 'input_id': 'X' }, ]) self.assertEqual(collection.get('A').index, 3) self.assertEqual(collection.get('h').index, 5) self.assertEqual(collection.get('X').index, 8) self.assertRaises(KeyError, collection.get_index, 'kj')
def test_get_by_list_index(self): """Normal list indexing is unaffected""" collection = AddressCollection([ { 'input_index': 0, 'input_id': 'A' }, { 'input_index': 1, 'input_id': 'h' }, { 'input_index': 2, 'input_id': 'X' }, ]) self.assertEqual(collection[0].id, 'A') self.assertEqual(collection[1].id, 'h') self.assertEqual(collection[2].id, 'X')