コード例 #1
0
    def test_given_invalid_password_raises_exception(self):

        # Arrange
        username = "******"
        password = "******"
        oauth_storage = OAuth2SQLStorage()
        storage = create_autospec(UserLoginStorageInterface)
        presenter = create_autospec(PresenterInterface)
        storage.valid_password.return_value = False
        presenter.raise_exception_for_invalid_password.side_effect = NotFound

        interactor = LoginInteractor(storage=storage,
                                     oauth_storage=oauth_storage,
                                     presenter=presenter)

        # Act
        with pytest.raises(NotFound):
            interactor.user_login(
                username=username,
                password=password,
            )

        # Assert
        storage.valid_username.assert_called_once_with(username=username)
        storage.valid_password.assert_called_once_with(username=username,
                                                       password=password)
        presenter.raise_exception_for_invalid_password.assert_called_once()
コード例 #2
0
def api_wrapper(*args, **kwargs):
    request_data = kwargs['request_data']
    username = request_data['username']
    password = request_data['password']
    storage = StorageImplementation()
    presenter = LoginPresenterImplementation()
    oauth2_storage = OAuth2SQLStorage()
    interactor = LoginInteractor(storage=storage,
                                 oauth2_storage=oauth2_storage)
    response = interactor.login_wrapper(presenter=presenter,
                                        username=username,
                                        password=password)
    return response
コード例 #3
0
def api_wrapper(*args, **kwargs):
    # ---------MOCK IMPLEMENTATION---------

    user = kwargs['user']
    request_data = kwargs['request_data']
    storage = LoginStorageImplementation()
    oauth_storage = OAuth2SQLStorage()
    presenter = UserLoginPresenterImplementation()
    interactor = LoginInteractor(storage=storage, oauth_storage=oauth_storage)
    response = interactor.user_login_wrapper(username=request_data['username'],
                                             password=request_data['password'],
                                             presenter=presenter)

    return response
コード例 #4
0
def api_wrapper(*args, **kwargs):
    request_data = kwargs['request_data']
    mobile_number = request_data["mobile_number"]
    password = request_data["password"]

    storage = StorageImplementation()
    presenter = PresenterImplementation()
    oauth_storage = OAuth2SQLStorage()
    interactor = UserLoginInteractor(storage=storage,
                                     presenter=presenter,
                                     oauth_storage=oauth_storage)

    access_token = interactor.user_login(password=password,
                                         mobile_number=mobile_number)

    response_data = json.dumps(access_token)
    return HttpResponse(response_data, status=200)
コード例 #5
0
def api_wrapper(*args, **kwargs):

    request_data = kwargs['request_data']
    storage = UserStorageImplementation()
    presenter = UserPresenterImplementation()
    oauth_storage = OAuth2SQLStorage()
    interactor = UserLoginInteractor(storage=storage,
                                     oauth_storage=oauth_storage)

    username = request_data['username']
    password = request_data['password']

    login_response = interactor.login_wrapper(username=username,
                                              password=password,
                                              presenter=presenter)
    response_data = json.dumps(login_response)
    return HttpResponse(response_data, status=200)
コード例 #6
0
ファイル: api_wrapper.py プロジェクト: pavan1296/lets_ride
def api_wrapper(*args, **kwargs):
    user = kwargs['user']
    credentials = kwargs['request_data']

    phone_number = dict(credentials)['phone_number']
    password = dict(credentials)['password']

    storage = StorageImplementation()
    presenter = PresenterImplementation()
    oauth2_storage = OAuth2SQLStorage()
    interactor = UserLoginInteractor(storage=storage,
                                     presenter=presenter,
                                     oauth2_storage=oauth2_storage)
    response_data = interactor.login_validation(phone_number=phone_number,
                                                password=password)

    return response_data
コード例 #7
0
def api_wrapper(*args, **kwargs):
    # ---------MOCK IMPLEMENTATION---------

    user = kwargs['user']

    storage = LoginStorageImplementation()
    oauth_storage = OAuth2SQLStorage()
    presenter = UserLoginPresenterImplementation()
    interactor = LoginInteractor(storage=storage,
                                 oauth_storage=oauth_storage,
                                 presenter=presenter)

    response = interactor.user_login(username=user.username,
                                     password=user.password)
    json_data = json.dumps(response)

    return HttpResponse(json_data, status=201)
コード例 #8
0
def test_login_user_interactor_with_invalid_username():
    # Arrange
    username = '******'
    password = "******"
    storage = create_autospec(UserStorageInterface)
    presenter = create_autospec(PresenterInterface)
    oauth_storage = OAuth2SQLStorage()

    storage.is_valid_username.side_effect = InvalidUserName
    presenter.raiseinvalidusername.side_effect = InvalidUserName

    interactor = LoginUserInteractor(storage=storage,
                                     presenter=presenter,
                                     oauth_storage=oauth_storage)

    # Assert
    with pytest.raises(InvalidUserName):
        interactor.login_user(username=username, password=password)
    storage.is_valid_username.assert_called_once_with(username)
コード例 #9
0
def api_wrapper(*args, **kwargs):

    request_data = kwargs["request_data"]
    username = request_data["username"]
    password = request_data["password"]

    user_storage = UserStorageImplementation()
    user_presenter =  UserPresenterImplementation()
    oauth2_storage = OAuth2SQLStorage()
    interactor = UserLoginInteractor(user_storage=user_storage,
                                     user_presenter=user_presenter,
                                     oauth2_storage=oauth2_storage)

    access_token_dict = interactor.user_login(username=username,
                                              password=password)

    access_token_dict_json = json.dumps(access_token_dict)

    response = HttpResponse(access_token_dict_json, status=200)
    return response
コード例 #10
0
def api_wrapper(*args, **kwargs):
    # ---------MOCK IMPLEMENTATION---------
    request_data = kwargs['request_data']
    username = request_data['username']
    password = request_data['password']

    storage = UserStorageImplementation()
    presenter = PresenterImplementation()
    oauth_storage = OAuth2SQLStorage()

    interactor = UserLoginInteractor(storage=storage, \
                    presenter=presenter,oauth_storage=oauth_storage)

    response = interactor.login_user(username=username, password=password)

    json_data = json.dumps(response)

    # print(json_data)

    return HttpResponse(json_data)
コード例 #11
0
    def user_login(self, username: str, password: str):

        valid_username = self.storage.valid_username(username=username)

        if not valid_username:
            self.presenter.raise_exception_for_invalid_username()
            return

        valid_password = self.storage.valid_password(username=username,
                                                     password=password)

        if not valid_password:
            self.presenter.raise_exception_for_invalid_password()
            return
        user = authenticate(username=username, password=password)

        user_id = user.id
        storage = OAuth2SQLStorage()
        service = OAuthUserAuthTokensService(oauth2_storage=storage)
        token_dto = service.create_user_auth_tokens(user_id=user_id)
        print(token_dto)
        self.presenter.get_acces_token_dto_response(token=token_dto)
コード例 #12
0
def api_wrapper(*args, **kwargs):

    request_data = kwargs["request_data"]
    name = request_data["name"]
    username = request_data["username"]
    password = request_data["password"]

    user_storage = UserStorageImplementation()
    user_presenter = UserPresenterImplementation()
    oauth2_storage = OAuth2SQLStorage()
    interactor = CreateUserSignUpInteractor(user_storage=user_storage,
                                            user_presenter=user_presenter,
                                            oauth2_storage=oauth2_storage)

    access_tocken_dict = interactor.create_signup(name=name,
                                                  username=username,
                                                  password=password)

    access_tocken_dict_json = json.dumps(access_tocken_dict)
    response_data = HttpResponse(access_tocken_dict_json, status=201)

    return response_data
コード例 #13
0
def test_login_user_interactor_with_valid_details(useraccount):
    # Arrange
    username = '******'
    password = "******"
    user_id = 1
    expires_in = datetime.datetime(2020, 9, 21, 3, 45, 50, 163595)
    expected_token = {
        "user_id": user_id,
        "access_token": "HiplEtNJKFIPRsyDSDqrH7GHkSHSzq",
        "refresh_token": "DIxY1vyGQRkN7zJKqE4MZaq73tpKDj3ee444444444444e",
        "expires_in": expires_in
    }

    from common.oauth_user_auth_tokens_service\
            import OAuthUserAuthTokensService

    storage = create_autospec(UserStorageInterface)
    presenter = create_autospec(PresenterInterface)
    oauth_storage = OAuth2SQLStorage()

    storage.is_valid_username.return_value = None
    storage.is_valid_password.return_value = user_id
    presenter.get_response_login_user.return_value = expected_token

    interactor = LoginUserInteractor(storage=storage,
                                     presenter=presenter,
                                     oauth_storage=oauth_storage)
    # service = OAuthUserAuthTokensService(interactor.oauth_storage)

    # Act
    token = interactor.login_user(username=username, password=password)

    # Assert
    assert token == expected_token
    assert expected_user_auth_token_dto.user_id == user_id
    storage.is_valid_username.assert_called_once_with(username)
    storage.is_valid_password.assert_called_once_with(username, password)
    presenter.get_response_login_user.assert_called_once_with(
        expected_user_auth_token_dto)
コード例 #14
0
    def test_given_valid_username_and_password_returns_tokens(self):
        # Arrange
        username = "******"
        password = "******"
        user_dto = UserDto(user_id=1, name="mouli", is_admin="False")
        access_token = "12345"
        access_token_dto = {
            "access_token": "12345",
            "refresh_token": "123",
            "expires_in": 1000000000
        }
        oauth_storage = OAuth2SQLStorage()
        storage = create_autospec(StorageInterface)
        presenter = create_autospec(PresenterInterface)
        storage.validate_username_for_dupilicate.return_value = False
        storage.get_user_id.return_value = user_dto

        interactor = SignUpInteractor(storage=storage,
                                      oauth_storage=oauth_storage)
        mock_response = {
            "access_token": "some_access_token",
            "refresh_token": "some_refresh_token"
        }

        # Act
        with patch.object(OAuthUserAuthTokensService,
                          'create_user_auth_tokens',
                          return_value=access_token_dto):
            interactor.user_signup_wrapper(username=username,
                                           password=password,
                                           presenter=presenter)

        storage.validate_username_for_dupilicate.assert_called_once_with(
            username=username)

        presenter.user_signup_response.assert_called_once_with(
            token_dto=access_token_dto, user_is_admin=user_dto.is_admin)
コード例 #15
0
    def test_given_valid_username_and_password_returns_tokens(self):
        # Arrange
        username = "******"
        password = "******"
        user_is_admin = True
        user_dto = UserDto(name="mouli", user_id="1", is_admin="False")
        access_token = "12345"
        access_token_dto = {
            "access_token": "12345",
            "refresh_token": "123",
            "expires_in": 1000000000
        }

        storage = create_autospec(StorageInterface)
        storage.validate_password.return_value = True
        storage.validate_username.return_value = True
        oauth_storage = OAuth2SQLStorage()
        # storage = create_autospec(StorageInterface)
        presenter = create_autospec(PresenterInterface)
        storage.get_user_id.return_value = user_dto

        interactor = LoginInteractor(storage=storage,
                                     oauth_storage=oauth_storage)
        # Act
        with patch.object(OAuthUserAuthTokensService,
                          'create_user_auth_tokens',
                          return_value=access_token_dto):
            interactor.user_login_wrapper(username=username,
                                          password=password,
                                          presenter=presenter)

        # Assert
        storage.validate_username.assert_called_once_with(username=username)
        storage.validate_password.assert_called_once_with(username=username,
                                                          password=password)
        presenter.user_login_response.assert_called_once_with(
            token_dto=access_token_dto, user_is_admin=user_dto.is_admin)
コード例 #16
0
    def test_given_invalid_password_raises_exception(self):
        # Arrange
        username = "******"
        password = "******"

        oauth_storage = OAuth2SQLStorage()
        storage = create_autospec(StorageInterface)
        presenter = create_autospec(PresenterInterface)
        oauth_storage = create_autospec(OAuth2SQLStorage)
        storage.validate_password.return_value = False
        storage.validate_username.return_value = True
        # presenter.raise_exception_for_invalid_password.return_value = mock

        interactor = LoginInteractor(storage=storage,
                                     oauth_storage=oauth_storage)

        response = interactor.user_login_wrapper(username=username,
                                                 password=password,
                                                 presenter=presenter)
        # Assert
        storage.validate_username.assert_called_once_with(username=username)
        storage.validate_password.assert_called_once_with(username=username,
                                                          password=password)
        presenter.raise_exception_for_invalid_password.assert_called_once()
コード例 #17
0
def api_wrapper(*args, **kwargs):
    # ---------MOCK IMPLEMENTATION---------

    request_data = kwargs['request_data']
    username = request_data['username']
    password = request_data['password']

    storage = UserStorageImplementation()
    presenter = PresenterImplementation()
    oauth_storage = OAuth2SQLStorage()

    interactor = LoginUserInteractor(storage=storage,
                                     presenter=presenter,
                                     oauth_storage=oauth_storage)

    try:
        access_token_response = interactor.login_user(username=username,
                                                      password=password)
    except InvalidUserName:
        raise NotFound(*INVALID_USERNAME)
    except InvalidPassword:
        raise NotFound(*INVALID_PASSWORD)
    data = json.dumps(access_token_response)
    return HttpResponse(data, 200)
コード例 #18
0
 def __init__(self, storage: StorageInterface,
              oauth_storage: OAuth2SQLStorage()):
     self.storage = storage
     self.oauth_storage = oauth_storage
コード例 #19
0
 def __init__(self, storage: PostStorageInterface,
              presenter: PresenterInterface,
              oauth_storage: OAuth2SQLStorage()):
     self.storage = storage
     self.presenter = presenter
     self.oauth_storage = oauth_storage