diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-05-24 17:53:22 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-05-24 17:53:22 +0100 |
commit | 7494bebcd8c531df0680e96952ffeceb34fd0a57 (patch) | |
tree | e81b9aa1239425915ad134a69195ea22c965d7d0 /ctrack/users/tests | |
parent | 54aa9bfe8a3815229b5b79f28a4fcc9e0e32fdbc (diff) |
failing test trying to add org to User
Diffstat (limited to '')
-rw-r--r-- | ctrack/users/tests/test_views.py | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/ctrack/users/tests/test_views.py b/ctrack/users/tests/test_views.py index 33ab238..8b923f6 100644 --- a/ctrack/users/tests/test_views.py +++ b/ctrack/users/tests/test_views.py @@ -1,6 +1,8 @@ import pytest +from django.contrib.auth import get_user_model from django.test import RequestFactory +from ctrack.organisations.tests.factories import OrganisationFactory from ctrack.users.models import User from ctrack.users.views import UserDetailView, UserRedirectView, UserUpdateView @@ -46,15 +48,26 @@ class TestUserRedirectView: assert view.get_redirect_url() == f"/users/{user.username}/" -def test_profile_view_contains_organisation_information(user: User): +def test_profile_view_contains_organisation_information(): """url: users/username - This is where users are redirected to when they log in and where I want to capture + This is where users are redirected to when they log in and where I want to capture information about the user - particularly if they are an OES user. - """ + """ + org = OrganisationFactory.create() + user = get_user_model().objects.create_user( + username="testy", + email="testy@test.com", + password="test1020", + oes_user=True, + organisation=org, + ) factory = RequestFactory() request = factory.get(f"/users/{user.username}") # we have to do the following to simulate logged-in user # Django Advanced Testing Topics request.user = user - response = UserDetailView.as_view()(request) - assert response.status_code == 300 + response = UserDetailView.as_view()(request, username=user.username) + assert response.status_code == 200 + assert response.context_data["object"].oes_user is True + # TODO - work out how we can attach an organisation to the User model + assert response.context_data["object"].organisation.name == org.name |