diff options
Diffstat (limited to '')
-rw-r--r-- | ctrack/users/tests/test_views.py | 4 | ||||
-rw-r--r-- | ctrack/users/views.py | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/ctrack/users/tests/test_views.py b/ctrack/users/tests/test_views.py index 7c2c8be..ca2d0c2 100644 --- a/ctrack/users/tests/test_views.py +++ b/ctrack/users/tests/test_views.py @@ -62,14 +62,18 @@ def test_profile_view_contains_organisation_information(person): user.save() 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, username=user.username) assert response.status_code == 200 assert response.context_data["user"].username == "testy" assert response.context_data["user"].is_stakeholder() is True assert response.context_data["user"].stakeholder.person.first_name == "Chinaplate" + + # Two ways of getting the organisaton name assert ( response.context_data["user"].stakeholder.person.get_organisation_name() == org_name diff --git a/ctrack/users/views.py b/ctrack/users/views.py index a292191..fcc0e84 100644 --- a/ctrack/users/views.py +++ b/ctrack/users/views.py @@ -11,7 +11,11 @@ User = get_user_model() class UserDetailView(LoginRequiredMixin, DetailView): model = User + + # This names the field in the model that contains the slug. Want it to be thise so that is a good + # citizen to be used in a URL slug_field = "username" + slug_url_kwarg = "username" |