diff options
author | Matthew Lemon <lemon@matthewlemon.com> | 2020-05-25 17:29:41 +0100 |
---|---|---|
committer | Matthew Lemon <lemon@matthewlemon.com> | 2020-05-25 17:29:41 +0100 |
commit | d447a019cfe5d1e523b98c7bd4b488d445615a3f (patch) | |
tree | 1fab839d512df00c8354dea621643f86af1f9d93 /ctrack/users | |
parent | 9a7a1b041246345275a17d89c160b3798be878fa (diff) |
added an explanatory comment about the use of slug_field
Diffstat (limited to 'ctrack/users')
-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" |