# Path: wunderhabit/views.py
# def index(request):
# def dashboard(request):
# def logout_view(request):
# def delete_account(request):
# def add_connection(request):
# def delete_connection(request, connection_id):
# def test_authentication(request):
# 
# Path: wunderhabit/default.py
# MESSAGE_CREATED_CONNECTION = _('Created new Connection!')
# MESSAGE_CREATE_CONNECTION_ERROR = _('Could not create Connection.')
# MESSAGE_DELETED_CONNECTION = _('Deleted the Connection!')
# MESSAGE_LOGGED_OUT = _('Successfully logged out.')
# MESSAGE_AUTH_SUCCESS = _('Successfully connected with Wunderlist and Habitica.')
# MESSAGE_DELETED_ACCOUNT = _('Your account has successfully been deleted.')
# 
# Path: wunderhabit/tests/utils.py
# def get_user():
#     """
#     Returns a user which is connected with wunderlist and habitica.
#     """
# 
#     wunderlist = WunderlistFactory.create()
#     habitica = HabiticaFactory.create()
#     habitica.owner = wunderlist.owner
#     habitica.save()
#     return wunderlist.owner
# 
# Path: wunderhabit/tests/utils.py
# @pytest.fixture(autouse=True)
# def mock_messages(monkeypatch):
#     monkeypatch.setattr('django.http.HttpRequest._messages', MockMessages(), raising=False)
# 
# Path: wunderlist/tests/utils.py
# @pytest.fixture(autouse=True)
# def mock_wunderlist_api(monkeypatch):
#     monkeypatch.setattr('wunderlist.api.WunderlistApi.get_user', lambda x: API_USER, raising=False)
#     monkeypatch.setattr('wunderlist.api.WunderlistApi.get_lists', lambda x: API_LISTS, raising=False)
#     monkeypatch.setattr('wunderlist.api.WunderlistApi.test_auth', lambda x: True, raising=False)
# 
# Path: wh_habitica/tests/utils.py
# @pytest.fixture
# def mock_habitica_api(monkeypatch):
#     monkeypatch.setattr('habitica.api.Habitica.status', lambda x: API_STATUS_UP, raising=False)
#     monkeypatch.setattr('habitica.api.Habitica.user', lambda x: API_USER, raising=False)
#     monkeypatch.setattr('wh_habitica.api.HabiticaApi.post_task', lambda x, task_id: API_TASK, raising=False)


import pytest
from django.core.urlresolvers import reverse
from wunderhabit import views
from wunderhabit import default
from .utils import get_user
from .utils import mock_messages
from wunderlist.tests.utils import mock_wunderlist_api
from wh_habitica.tests.utils import mock_habitica_api




@pytest.mark.usefixtures('mock_messages', 'mock_wunderlist_api', 'mock_habitica_api')
@pytest.mark.django_db
def test_successfully_authenticated(rf):
    request = rf.get(reverse('test_authentication'))
    request.user = get_user()
    response = views.test_authentication(request)

# Path: wunderhabit/views.py
# def index(request):
# def dashboard(request):
# def logout_view(request):
# def delete_account(request):
# def add_connection(request):
# def delete_connection(request, connection_id):
# def test_authentication(request):
# 
# Path: wunderhabit/default.py
# MESSAGE_CREATED_CONNECTION = _('Created new Connection!')
# MESSAGE_CREATE_CONNECTION_ERROR = _('Could not create Connection.')
# MESSAGE_DELETED_CONNECTION = _('Deleted the Connection!')
# MESSAGE_LOGGED_OUT = _('Successfully logged out.')
# MESSAGE_AUTH_SUCCESS = _('Successfully connected with Wunderlist and Habitica.')
# MESSAGE_DELETED_ACCOUNT = _('Your account has successfully been deleted.')
# 
# Path: wunderhabit/tests/utils.py
# def get_user():
#     """
#     Returns a user which is connected with wunderlist and habitica.
#     """
# 
#     wunderlist = WunderlistFactory.create()
#     habitica = HabiticaFactory.create()
#     habitica.owner = wunderlist.owner
#     habitica.save()
#     return wunderlist.owner
# 
# Path: wunderhabit/tests/utils.py
# @pytest.fixture(autouse=True)
# def mock_messages(monkeypatch):
#     monkeypatch.setattr('django.http.HttpRequest._messages', MockMessages(), raising=False)
# 
# Path: wunderlist/tests/utils.py
# @pytest.fixture(autouse=True)
# def mock_wunderlist_api(monkeypatch):
#     monkeypatch.setattr('wunderlist.api.WunderlistApi.get_user', lambda x: API_USER, raising=False)
#     monkeypatch.setattr('wunderlist.api.WunderlistApi.get_lists', lambda x: API_LISTS, raising=False)
#     monkeypatch.setattr('wunderlist.api.WunderlistApi.test_auth', lambda x: True, raising=False)
# 
# Path: wh_habitica/tests/utils.py
# @pytest.fixture
# def mock_habitica_api(monkeypatch):
#     monkeypatch.setattr('habitica.api.Habitica.status', lambda x: API_STATUS_UP, raising=False)
#     monkeypatch.setattr('habitica.api.Habitica.user', lambda x: API_USER, raising=False)
#     monkeypatch.setattr('wh_habitica.api.HabiticaApi.post_task', lambda x, task_id: API_TASK, raising=False)


# Path: wunderhabit/tests/test_views.py
import pytest
from django.core.urlresolvers import reverse
from wunderhabit import views
from wunderhabit import default
from .utils import get_user
from .utils import mock_messages
from wunderlist.tests.utils import mock_wunderlist_api
from wh_habitica.tests.utils import mock_habitica_api





@pytest.mark.usefixtures('mock_messages', 'mock_wunderlist_api', 'mock_habitica_api')
@pytest.mark.django_db
def test_successfully_authenticated(rf):
    request = rf.get(reverse('test_authentication'))
    request.user = get_user()
    response = views.test_authentication(request)

    assert request._messages.messages[0] == default.MESSAGE_AUTH_SUCCESS