Merge pull request #2167 from alphagov/fix_services_finding_user_info

Fix displaying of services on User Information page
This commit is contained in:
Pea (Malgorzata Tyczynska)
2018-07-16 17:48:43 +01:00
committed by GitHub
3 changed files with 25 additions and 8 deletions

View File

@@ -30,7 +30,9 @@ def find_users_by_email():
@user_is_platform_admin
def user_information(user_id):
user = user_api_client.get_user(user_id)
services = user_api_client.get_organisations_and_services_for_user(user)
return render_template(
'views/find-users/user-information.html',
user=user
user=user,
services=services['services_without_organisations'],
)

View File

@@ -16,9 +16,9 @@
<h2 class="heading-medium">Services</h2>
<nav class="browse-list">
<ul>
{% for service in user.services %}
{% for service in services %}
<li class="browse-list-item">
<p class="browse-list-sub-item">{{ service.name }}</p>
<a class="browse-list-hint" href={{url_for('.service_dashboard', service_id=service.id)}}>{{ service.name }}</a>
</li>
{% endfor %}
</ul>

View File

@@ -93,11 +93,17 @@ def test_user_information_page_shows_information_about_user(
):
mocker.patch('app.user_api_client.get_user', side_effect=[
platform_admin_user,
User(user_json(name="Apple Bloom", services=[
User(user_json(name="Apple Bloom", services=[1, 2]))
], autospec=True)
mocker.patch(
'app.user_api_client.get_organisations_and_services_for_user',
return_value={'organisations': [], 'services_without_organisations': [
{"id": 1, "name": "Fresh Orchard Juice"},
{"id": 2, "name": "Nature Therapy"},
]))
], autospec=True)
]},
autospec=True
)
client.login(platform_admin_user)
response = client.get(url_for('main.user_information', user_id=345))
assert response.status_code == 200
@@ -109,8 +115,8 @@ def test_user_information_page_shows_information_about_user(
assert document.xpath("//p/text()[normalize-space()='+447700900986']")
assert document.xpath("//h2/text()[normalize-space()='Services']")
assert document.xpath("//p/text()[normalize-space()='Fresh Orchard Juice']")
assert document.xpath("//p/text()[normalize-space()='Nature Therapy']")
assert document.xpath("//a/text()[normalize-space()='Fresh Orchard Juice']")
assert document.xpath("//a/text()[normalize-space()='Nature Therapy']")
assert document.xpath("//h2/text()[normalize-space()='Last login']")
assert not document.xpath("//p/text()[normalize-space()='0 failed login attempts']")
@@ -125,6 +131,15 @@ def test_user_information_page_displays_if_there_are_failed_login_attempts(
platform_admin_user,
User(user_json(name="Apple Bloom", failed_login_count=2))
], autospec=True)
mocker.patch(
'app.user_api_client.get_organisations_and_services_for_user',
return_value={'organisations': [], 'services_without_organisations': [
{"id": 1, "name": "Fresh Orchard Juice"},
{"id": 2, "name": "Nature Therapy"},
]},
autospec=True
)
client.login(platform_admin_user)
response = client.get(url_for('main.user_information', user_id=345))
assert response.status_code == 200