コード例 #1
0
    def test_returns_true_when_logging_is_successful(self):
        uow = FakeUnitOfWork()

        credential_service.add_credential('Tserewara', 'password1', uow)

        username = credential_service.authenticate('Tserewara', 'password1',
                                                   uow)

        assert username == 'Tserewara'
コード例 #2
0
    def test_raises_exception_when_logging_with_invalid_username(self):
        uow = FakeUnitOfWork()

        _credential = ('Tserewara', 'password1')

        credential_service.add_credential(_credential[0], _credential[1], uow)

        with pytest.raises(exceptions.CredentialValueError,
                           match='Invalid credential. Username not found'):
            credential_service.authenticate('John', 'password', uow)
コード例 #3
0
def test_can_delete_credential():
    uow = FakeUnitOfWork()

    _credential = ('Tserewara', 'password1')

    credential_service.add_credential(_credential[0], _credential[1], uow)

    credential_service.delete_credential('Tserewara', uow)

    assert uow.credentials.list() == []
コード例 #4
0
def test_service_can_update_password():
    uow = FakeUnitOfWork()

    credential_service.add_credential('Tserewara', 'password1', uow)

    result = credential_service.update_credential('Tserewara',
                                                  new_password='******',
                                                  uow=uow)

    assert result == 'Credential updated for user Tserewara'
    assert credential_service.authenticate('Tserewara', 'password10', uow)
コード例 #5
0
def test_service_can_update_username():
    uow = FakeUnitOfWork()

    _credential = ('Tserewara', 'password1')

    credential_service.add_credential(_credential[0], _credential[1], uow)

    result = credential_service.update_credential('Tserewara',
                                                  new_username='******',
                                                  uow=uow)

    assert result == 'Credential updated for user Tserewara'
    assert credential_service.authenticate('Tsere', 'password1', uow)
コード例 #6
0
    def post():
        try:
            credential_service.add_credential(
                username=request.json['username'],
                password=request.json['password'],
                uow=unit_of_work.SqlAlchemyUnitOfWork())
            return jsonify({
                "message":
                f"Credential created for user "
                f"{request.json['username']}"
            }), 201

        except exceptions.PasswordStrengthError as e:
            return jsonify(message=str(e)), 400
コード例 #7
0
def create(username, password):

    uow = unit_of_work.SqlAlchemyUnitOfWork()

    try:
        result = credential_service.add_credential(username=username,
                                                   password=password,
                                                   uow=uow)
        print(result)

    except exceptions.PasswordStrengthError as error:
        print(str(error))
コード例 #8
0
def test_service_can_create_credential():
    uow = FakeUnitOfWork()

    result = credential_service.add_credential('Tserewara', 'password1', uow)

    assert result == 'Credential created for Tserewara'