Exemplo n.º 1
0
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
Exemplo n.º 3
0
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')
Exemplo n.º 4
0
def test_create_new_user():
    user_repository = InMemoryUserRepository()
    uuid = CustomUuid()
    create_new_user = CreateNewUser(user_repository, uuid)
    uuid.set_next_uuid("pat_uuid")
    create_new_user.execute(name="patrice", status="active")
    assert len(user_repository.users) == 1
    expected_user = User(uuid="pat_uuid", name="patrice", status="active")
    assert user_repository.users == [expected_user]
Exemplo n.º 5
0
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)
    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)

    with csv_path.open("r") as f:
        reader = csv.DictReader(f)
        assert list(reader)[0] == {
            "uuid": "pat_uuid",
            "name": "patrice",
            "status": "contact",
        }
def test_create_new_topic():
    uuid_topic, uuid_user = '******', 'topic_user'
    topic_name = "My first topic"
    uuid = CustomUuid()
    uuid.set_next_uuid(uuid_topic)
    topic_repo = InMemoryTopicRepository(uuid_generator=uuid)
    user = User(name='patrice', status='active', uuid=uuid_user)
    create_new_topic = CreateNewTopic(topic_repository=topic_repo)
    create_new_topic.execute(topic_name=topic_name, user=user)

    created_topic = topic_repo.get_all()[0]
    assert isinstance(created_topic, Topic), 'wrong type'
    assert created_topic.topic_name == topic_name, 'wrong name'
    assert created_topic.uuid == uuid_topic, "wrong uuid"
    assert created_topic.author_uuid == user.uuid, "wrong user"
def test_create_new_user():
    uuid_gen = CustomUuid()
    user_repository = InMemoryUserRepository(uuid_generator=uuid_gen)

    get_all_users = GetAllUsers(user_repository)
    user_repository.users = [
        User(uuid="pat_uuid", name="patrice", status="active")
    ]
    actual_users = get_all_users.execute()
    assert actual_users == [
        User(uuid="pat_uuid", name="patrice", status="active")
    ]