def test_create_with_existing_key(self): """Test that creating and item with an existing key raises an exception.""" collection = CRUDCollection() collection.create("one", 1) with pytest.raises(ValueError, match="Item with name .* already present"): collection.create("one", 1)
def test_read_all(self): """Test that the read_all method works correctly.""" collection = CRUDCollection() collection.create("one", 1) collection.create("two", 2) keyvalue_pairs = collection.read_all() assert {("one", 1), ("two", 2)} == set(keyvalue_pairs)
def test_delete(self): """Test that the delete method works correctly.""" collection = CRUDCollection() collection.create("one", 1) assert collection.read("one") == 1 collection.delete("one") assert collection.read("one") is None
def test_update(self): """Test that the update method works correctly.""" collection = CRUDCollection() collection.create("one", 1) assert collection.read("one") == 1 collection.update("one", 2) assert collection.read("one") == 2
def test_keys(self): """Test the keys method.""" collection = CRUDCollection() collection.create("one", 1) collection.create("two", 2) keyvalue_pairs = collection.keys() assert {"one", "two"} == set(keyvalue_pairs)
def test_read_empty(self): """Test that reading with a non-existing key returns None.""" collection = CRUDCollection() item = collection.read("one") assert item is None
def test_read_not_empty(self): """Test that reading a previously created item gives a non-empty result.""" collection = CRUDCollection() collection.create("one", 1) item = collection.read("one") assert item == 1