def test_store_get_item(monkeypatch): monkeypatch.setattr(MemoryStore, '_load_data', mock_load_data) store = MemoryStore('dir') mocked_data = mock_load_data('self', 'data_dir') collection_id = 'food' item_id = 'Burger' expected_item = mocked_data[collection_id][item_id] # Returns item if it exists assert store.get_item(collection_id, item_id) == expected_item # Returns None if item is not in the collection dne_item_id = 'Steak' assert dne_item_id not in store.get_collection(collection_id) assert store.get_item(collection_id, dne_item_id) is None
def test_store_create_item(monkeypatch): monkeypatch.setattr(MemoryStore, '_load_data', mock_load_data) store = MemoryStore('dir') collection = 'food' item_id = 'Steak' params = {'id': item_id, 'Price': '$10.00'} # Item is not in the collection assert item_id not in store.get_collection(collection) # Item is present after creation store.create_item(collection, params) assert store.get_item(collection, item_id) == params