from unittest.mock import create_autospec
import pytest

from user_app.interactors.user_logout_interactor\
    import UserLogoutInteractor
from user_app.interactors.storages.user_storage_interface\
    import UserStorageInterface
from user_app.interactors\
    .presenters.user_presenter_interface\
    import UserPresenterInterface
from user_app.exceptions import InvalidToken

class TestLogout:

    def test_logout_with_valid_token(self):

        #arrange
        access_token = "kjfewrfjbwg"
        storage = create_autospec(UserStorageInterface)
        presenter = create_autospec(UserPresenterInterface)
        interactor = UserLogoutInteractor(storage=storage)
        storage.validate_access_token.return_value = True
        presenter.logout_response.return_value = None
        expected_response = None

        #act
        response = interactor.logout_wrapper(access_token=access_token,
                                             presenter=presenter
                                            )

        #assert
        storage.validate_access_token.assert_called_once_with(
            access_token=access_token
            )
        assert response == expected_response

    def test_logout_with_invalid_token(self):

        #arrange
        access_token = "some_random"
        storage = create_autospec(UserStorageInterface)
        presenter = create_autospec(UserPresenterInterface)
        interactor = UserLogoutInteractor(storage=storage)
        storage.validate_access_token.return_value = False
        presenter.raise_invalid_access_token_exception\
            .side_effect = InvalidToken

        #act
        with pytest.raises(InvalidToken):
            interactor.logout_wrapper(access_token=access_token,
                                      presenter=presenter
                                     )

        #assert
        storage.validate_access_token.assert_called_once_with(
            access_token=access_token
            )
        presenter.raise_invalid_access_token_exception.assert_called_once()

6c727ae1b633221236ad05834103da221a345381
<mask token>


class TestLogout:
    <mask token>
    <mask token>

<mask token>


class TestLogout:

    def test_logout_with_valid_token(self):
        access_token = 'kjfewrfjbwg'
        storage = create_autospec(UserStorageInterface)
        presenter = create_autospec(UserPresenterInterface)
        interactor = UserLogoutInteractor(storage=storage)
        storage.validate_access_token.return_value = True
        presenter.logout_response.return_value = None
        expected_response = None
        response = interactor.logout_wrapper(access_token=access_token,
            presenter=presenter)
        storage.validate_access_token.assert_called_once_with(access_token=
            access_token)
        assert response == expected_response
    <mask token>

<mask token>


class TestLogout:

    def test_logout_with_valid_token(self):
        access_token = 'kjfewrfjbwg'
        storage = create_autospec(UserStorageInterface)
        presenter = create_autospec(UserPresenterInterface)
        interactor = UserLogoutInteractor(storage=storage)
        storage.validate_access_token.return_value = True
        presenter.logout_response.return_value = None
        expected_response = None
        response = interactor.logout_wrapper(access_token=access_token,
            presenter=presenter)
        storage.validate_access_token.assert_called_once_with(access_token=
            access_token)
        assert response == expected_response

    def test_logout_with_invalid_token(self):
        access_token = 'some_random'
        storage = create_autospec(UserStorageInterface)
        presenter = create_autospec(UserPresenterInterface)
        interactor = UserLogoutInteractor(storage=storage)
        storage.validate_access_token.return_value = False
        presenter.raise_invalid_access_token_exception.side_effect = (
            InvalidToken)
        with pytest.raises(InvalidToken):
            interactor.logout_wrapper(access_token=access_token, presenter=
                presenter)
        storage.validate_access_token.assert_called_once_with(access_token=
            access_token)
        presenter.raise_invalid_access_token_exception.assert_called_once()

from unittest.mock import create_autospec
import pytest
from user_app.interactors.user_logout_interactor import UserLogoutInteractor
from user_app.interactors.storages.user_storage_interface import UserStorageInterface
from user_app.interactors.presenters.user_presenter_interface import UserPresenterInterface
from user_app.exceptions import InvalidToken


class TestLogout:

    def test_logout_with_valid_token(self):
        access_token = 'kjfewrfjbwg'
        storage = create_autospec(UserStorageInterface)
        presenter = create_autospec(UserPresenterInterface)
        interactor = UserLogoutInteractor(storage=storage)
        storage.validate_access_token.return_value = True
        presenter.logout_response.return_value = None
        expected_response = None
        response = interactor.logout_wrapper(access_token=access_token,
            presenter=presenter)
        storage.validate_access_token.assert_called_once_with(access_token=
            access_token)
        assert response == expected_response

    def test_logout_with_invalid_token(self):
        access_token = 'some_random'
        storage = create_autospec(UserStorageInterface)
        presenter = create_autospec(UserPresenterInterface)
        interactor = UserLogoutInteractor(storage=storage)
        storage.validate_access_token.return_value = False
        presenter.raise_invalid_access_token_exception.side_effect = (
            InvalidToken)
        with pytest.raises(InvalidToken):
            interactor.logout_wrapper(access_token=access_token, presenter=
                presenter)
        storage.validate_access_token.assert_called_once_with(access_token=
            access_token)
        presenter.raise_invalid_access_token_exception.assert_called_once()

from unittest.mock import create_autospec
import pytest

from user_app.interactors.user_logout_interactor\
    import UserLogoutInteractor
from user_app.interactors.storages.user_storage_interface\
    import UserStorageInterface
from user_app.interactors\
    .presenters.user_presenter_interface\
    import UserPresenterInterface
from user_app.exceptions import InvalidToken

class TestLogout:

    def test_logout_with_valid_token(self):

        #arrange
        access_token = "kjfewrfjbwg"
        storage = create_autospec(UserStorageInterface)
        presenter = create_autospec(UserPresenterInterface)
        interactor = UserLogoutInteractor(storage=storage)
        storage.validate_access_token.return_value = True
        presenter.logout_response.return_value = None
        expected_response = None

        #act
        response = interactor.logout_wrapper(access_token=access_token,
                                             presenter=presenter
                                            )

        #assert
        storage.validate_access_token.assert_called_once_with(
            access_token=access_token
            )
        assert response == expected_response

    def test_logout_with_invalid_token(self):

        #arrange
        access_token = "some_random"
        storage = create_autospec(UserStorageInterface)
        presenter = create_autospec(UserPresenterInterface)
        interactor = UserLogoutInteractor(storage=storage)
        storage.validate_access_token.return_value = False
        presenter.raise_invalid_access_token_exception\
            .side_effect = InvalidToken

        #act
        with pytest.raises(InvalidToken):
            interactor.logout_wrapper(access_token=access_token,
                                      presenter=presenter
                                     )

        #assert
        storage.validate_access_token.assert_called_once_with(
            access_token=access_token
            )
        presenter.raise_invalid_access_token_exception.assert_called_once()
