def test_can_get_user_if_exists(): reset_file_from_path(csv_path) uuid = CustomUuid() uuid.set_next_uuid("pat_uuid") csv_user_repository = CsvUserRepository(csv_path=csv_path, uuid_generator=uuid) csv_user_repository.add(user_example) assert csv_user_repository.get(uuid="pat_uuid") == user_example
def test_can_add_user(): reset_file_from_path(csv_path) csv_user_repository = CsvUserRepository(csv_path=csv_path) csv_user_repository.add(user_example) with csv_path.open("r") as f: reader = csv.DictReader(f) assert list(reader)[0] == { "uuid": "pat_uuid", "name": "patrice", "status": "contact", }
# sanity check route @app.route("/ping", methods=["GET"]) def on_get_ping(): return jsonify("pong!") @app.route("/user", methods=["POST"]) def on_post_new_user(): create_new_user.execute(**request.form) return jsonify("ok!") @app.route("/users", methods=["GET"]) def on_get_all_users(): users = get_all_users.execute() return jsonify(users) @app.route("/user", methods=["POST"]) def add_new_user(): # TODO : add_new_user.execute(...) pass return app if __name__ == "__main__": csv_path = Path("data") / "user_repo.csv" user_repository = CsvUserRepository(csv_path=csv_path) reset_file_from_path(csv_path) config = Config(user_repository) app = make_app(config) app.run()
def test_can_get_user_if_exists(): reset_file_from_path(csv_path) csv_user_repository = CsvUserRepository(csv_path=csv_path) csv_user_repository.add(user_example) assert csv_user_repository.get(uuid="pat_uuid") == user_example
from pathlib import Path from adapters.csv_topic_repository import CsvTopicRepository from adapters.csv_user_repository import CsvUserRepository from domain.ports.uuid import RealUuid from entrypoints.config.model import Config csv_config = Config( user_repo=CsvUserRepository(csv_path=Path("data") / "user_repo", uuid_generator=RealUuid()), topic_repo=CsvTopicRepository(csv_path=Path("data") / "topic_repo", uuid_generator=RealUuid()), )