Exemplo n.º 1
0
def test_create_user() -> None:
    expected_user = User(1, "user_nickname")
    expected_auth = Authentication(
        user_id=expected_user.id,
        category=Authentication.EMAIL,
        identification="*****@*****.**",
        secret="secret",
    )

    dto = CreateUserDto(
        nickname="user_nickname",
        auth_category=expected_auth.category,
        auth_identification=expected_auth.identification,
        auth_secret=expected_auth.secret,
    )

    user_repo = mock.Mock()
    user_repo.create_user.return_value = expected_user
    auth_repo = mock.Mock()
    auth_repo.create_auth.return_value = expected_auth

    output = CreateUserUseCase(user_repo, auth_repo).execute(dto)
    assert True if output.is_success() else False

    assert output.get_data() == expected_user
    assert output.get_data().authentications[0] == expected_auth
def test_call_index(
    client: RequestClient,
    user_repo: UserRepository,
    auth_repo: AuthenticationRepository,
) -> None:
    request_auth_category = "email"
    request_auth_identification = "sample_id"
    request_auth_secret = "123456"

    # Create user and authentication
    user = user_repo.create_user("sample")
    auth_repo.create_auth(
        Authentication(
            user_id=user.id,
            category=request_auth_category,
            identification=request_auth_identification,
            secret=request_auth_secret,
        ))

    resp = client.post(
        "/v1/authentications",
        {
            "category": request_auth_category,
            "identification": request_auth_identification,
            "secret": request_auth_secret,
        },
    )

    assert resp.get_status_code() == 200
    assert resp.get_data()
def create_test_data(repo: AuthenticationRepository) -> Authentication:
    expected_auth = Authentication(
        user_id=1,
        category=Authentication.EMAIL,
        identification="*****@*****.**",
        secret="some_hash_value",
    )
    repo.create_auth(expected_auth)
    return expected_auth
def create_mock_repo(user_id: int) -> Mock:
    repo = mock.Mock()
    repo.find_auth.return_value = Authentication(
        user_id,
        Authentication.EMAIL,
        "*****@*****.**",
        EncryptHelper().encode("some_secret"),
    )
    return repo
Exemplo n.º 5
0
    def create_auth(self, auth: AuthenticationEntity) -> AuthenticationEntity:
        new_auth: AuthenticationModel = AuthenticationModel(
            user_id=auth.user_id,
            category=auth.category,
            identification=auth.identification,
            secret=EncryptHelper().encode(auth.secret),
        )
        auth = rdb.Query(new_auth).create()

        return auth.to_entity()
def test_create_authentication(repo: AuthenticationRepository) -> None:
    expected_auth = Authentication(
        user_id=1,
        category=Authentication.EMAIL,
        identification="*****@*****.**",
        secret="some_hash_value",
    )

    new_auth = repo.create_auth(expected_auth)

    assert expected_auth.user_id == new_auth.user_id
    assert expected_auth.category == new_auth.category
    assert expected_auth.identification == new_auth.identification
    assert expected_auth.secret != new_auth.secret
Exemplo n.º 7
0
def create_token(user_id: int) -> str:
    user_id = user_id
    category = Authentication.EMAIL
    identification = "*****@*****.**"
    secret = "some_secret"

    repo = mock.Mock()
    repo.find_auth.return_value = Authentication(
        user_id,
        Authentication.EMAIL,
        "*****@*****.**",
        EncryptHelper().encode("some_secret"),
    )

    dto = CreateTokenDto(
        category=category, identification=identification, secret=secret
    )

    output = CreateTokenUseCase(repo).execute(dto)

    return output.get_data()