def test_can_get_topic_if_exists(): reset_file_from_path(csv_path) uuid = CustomUuid() uuid.set_next_uuid("ant") csv_topic_repository = CsvTopicRepository(csv_path=csv_path, uuid_generator=uuid) csv_topic_repository.add(topic_example) assert csv_topic_repository.get(uuid="ant") == topic_example
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 write_csv_file(csv_path: Path, header: List, rows: List): reset_file_from_path(csv_path) with open(csv_path, "w") as f: writer = csv.writer(f) writer.writerow(header) for row in rows: writer.writerow(row)
def test_data_persistence(): reset_file_from_path(csv_path) uuid = CustomUuid() uuid.set_next_uuid('ant') csv_topic_repository = CsvTopicRepository(csv_path=csv_path, uuid_generator=uuid) csv_topic_repository.add(topic_example) second_repo = CsvTopicRepository(csv_path, uuid_generator=uuid) assert second_repo.get('ant')
def test_can_add_topic(): reset_file_from_path(csv_path) uuid = CustomUuid() uuid.set_next_uuid("ant") csv_user_repository = CsvTopicRepository(csv_path=csv_path, uuid_generator=uuid) csv_user_repository.add(topic_example) with csv_path.open("r") as f: reader = csv.DictReader(f) assert list(reader)[0] == dict( uuid='ant', author_uuid="pat2b", created_date=str(created_date.timestamp()), topic_name="Antarctique", )
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