mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-03 18:01:08 -05:00
Merge pull request #2539 from alphagov/optimise-orgs-services-for-user
Return all required information about a user’s organisations and services
This commit is contained in:
@@ -26,8 +26,10 @@ def test_get_all_organisations(admin_request, notify_db_session):
|
||||
assert len(response) == 2
|
||||
assert response[0]['name'] == 'active org'
|
||||
assert response[0]['active'] is True
|
||||
assert response[0]['count_of_live_services'] == 0
|
||||
assert response[1]['name'] == 'inactive org'
|
||||
assert response[1]['active'] is False
|
||||
assert response[1]['count_of_live_services'] == 0
|
||||
|
||||
|
||||
def test_get_organisation_by_id(admin_request, notify_db_session):
|
||||
@@ -53,6 +55,7 @@ def test_get_organisation_by_id(admin_request, notify_db_session):
|
||||
'email_branding_id',
|
||||
'domains',
|
||||
'request_to_go_live_notes',
|
||||
'count_of_live_services',
|
||||
}
|
||||
assert response['id'] == str(org.id)
|
||||
assert response['name'] == 'test_org_1'
|
||||
@@ -66,6 +69,7 @@ def test_get_organisation_by_id(admin_request, notify_db_session):
|
||||
assert response['email_branding_id'] is None
|
||||
assert response['domains'] == []
|
||||
assert response['request_to_go_live_notes'] is None
|
||||
assert response['count_of_live_services'] == 0
|
||||
|
||||
|
||||
def test_get_organisation_by_id_returns_domains(admin_request, notify_db_session):
|
||||
|
||||
@@ -835,38 +835,63 @@ def test_get_orgs_and_services_nests_services(admin_request, sample_user):
|
||||
|
||||
resp = admin_request.get('user.get_organisations_and_services_for_user', user_id=sample_user.id)
|
||||
|
||||
assert resp == {
|
||||
'organisations': [
|
||||
{
|
||||
'name': org1.name,
|
||||
'id': str(org1.id),
|
||||
'services': [
|
||||
{
|
||||
'name': service1.name,
|
||||
'id': str(service1.id),
|
||||
'restricted': False,
|
||||
},
|
||||
{
|
||||
'name': service2.name,
|
||||
'id': str(service2.id),
|
||||
'restricted': False,
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': org2.name,
|
||||
'id': str(org2.id),
|
||||
'services': []
|
||||
}
|
||||
],
|
||||
'services_without_organisations': [
|
||||
{
|
||||
'name': service3.name,
|
||||
'id': str(service3.id),
|
||||
'restricted': False,
|
||||
}
|
||||
]
|
||||
assert set(resp.keys()) == {
|
||||
'organisations',
|
||||
'services_without_organisations',
|
||||
'services',
|
||||
}
|
||||
assert resp['organisations'] == [
|
||||
{
|
||||
'name': org1.name,
|
||||
'id': str(org1.id),
|
||||
'services': [
|
||||
{
|
||||
'name': service1.name,
|
||||
'id': str(service1.id),
|
||||
'restricted': False,
|
||||
},
|
||||
{
|
||||
'name': service2.name,
|
||||
'id': str(service2.id),
|
||||
'restricted': False,
|
||||
}
|
||||
],
|
||||
'count_of_live_services': 2,
|
||||
},
|
||||
{
|
||||
'name': org2.name,
|
||||
'id': str(org2.id),
|
||||
'services': [],
|
||||
'count_of_live_services': 0,
|
||||
},
|
||||
]
|
||||
assert resp['services_without_organisations'] == [
|
||||
{
|
||||
'name': service3.name,
|
||||
'id': str(service3.id),
|
||||
'restricted': False,
|
||||
}
|
||||
]
|
||||
assert resp['services'] == [
|
||||
{
|
||||
'name': service1.name,
|
||||
'id': str(service1.id),
|
||||
'restricted': False,
|
||||
'organisation': str(org1.id),
|
||||
},
|
||||
{
|
||||
'name': service2.name,
|
||||
'id': str(service2.id),
|
||||
'restricted': False,
|
||||
'organisation': str(org1.id),
|
||||
},
|
||||
{
|
||||
'name': service3.name,
|
||||
'id': str(service3.id),
|
||||
'restricted': False,
|
||||
'organisation': None,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def test_get_orgs_and_services_only_returns_active(admin_request, sample_user):
|
||||
@@ -890,28 +915,52 @@ def test_get_orgs_and_services_only_returns_active(admin_request, sample_user):
|
||||
|
||||
resp = admin_request.get('user.get_organisations_and_services_for_user', user_id=sample_user.id)
|
||||
|
||||
assert resp == {
|
||||
'organisations': [
|
||||
{
|
||||
'name': org1.name,
|
||||
'id': str(org1.id),
|
||||
'services': [
|
||||
{
|
||||
'name': service1.name,
|
||||
'id': str(service1.id),
|
||||
'restricted': False,
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
'services_without_organisations': [
|
||||
{
|
||||
'name': service4.name,
|
||||
'id': str(service4.id),
|
||||
'restricted': False,
|
||||
}
|
||||
]
|
||||
assert set(resp.keys()) == {
|
||||
'organisations',
|
||||
'services_without_organisations',
|
||||
'services',
|
||||
}
|
||||
assert resp['organisations'] == [
|
||||
{
|
||||
'name': org1.name,
|
||||
'id': str(org1.id),
|
||||
'services': [
|
||||
{
|
||||
'name': service1.name,
|
||||
'id': str(service1.id),
|
||||
'restricted': False,
|
||||
}
|
||||
],
|
||||
'count_of_live_services': 1,
|
||||
}
|
||||
]
|
||||
assert resp['services_without_organisations'] == [
|
||||
{
|
||||
'name': service4.name,
|
||||
'id': str(service4.id),
|
||||
'restricted': False,
|
||||
}
|
||||
]
|
||||
assert resp['services'] == [
|
||||
{
|
||||
'name': service1.name,
|
||||
'id': str(service1.id),
|
||||
'restricted': False,
|
||||
'organisation': str(org1.id)
|
||||
},
|
||||
{
|
||||
'name': service3.name,
|
||||
'id': str(service3.id),
|
||||
'restricted': False,
|
||||
'organisation': str(org2.id)
|
||||
},
|
||||
{
|
||||
'name': service4.name,
|
||||
'id': str(service4.id),
|
||||
'restricted': False,
|
||||
'organisation': None,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
def test_get_orgs_and_services_only_shows_users_orgs_and_services(admin_request, sample_user):
|
||||
@@ -932,23 +981,37 @@ def test_get_orgs_and_services_only_shows_users_orgs_and_services(admin_request,
|
||||
|
||||
resp = admin_request.get('user.get_organisations_and_services_for_user', user_id=sample_user.id)
|
||||
|
||||
assert resp == {
|
||||
'organisations': [
|
||||
{
|
||||
'name': org2.name,
|
||||
'id': str(org2.id),
|
||||
'services': []
|
||||
}
|
||||
],
|
||||
# service1 belongs to org1, but the user doesn't know about org1
|
||||
'services_without_organisations': [
|
||||
{
|
||||
'name': service1.name,
|
||||
'id': str(service1.id),
|
||||
'restricted': False,
|
||||
}
|
||||
]
|
||||
assert set(resp.keys()) == {
|
||||
'organisations',
|
||||
'services_without_organisations',
|
||||
'services',
|
||||
}
|
||||
assert resp['organisations'] == [
|
||||
{
|
||||
'name': org2.name,
|
||||
'id': str(org2.id),
|
||||
'services': [],
|
||||
'count_of_live_services': 0,
|
||||
}
|
||||
]
|
||||
# service1 belongs to org1, but the user doesn't know about org1
|
||||
assert resp['services_without_organisations'] == [
|
||||
{
|
||||
'name': service1.name,
|
||||
'id': str(service1.id),
|
||||
'restricted': False,
|
||||
}
|
||||
]
|
||||
# 'services' always returns the org_id no matter whether the user
|
||||
# belongs to that org or not
|
||||
assert resp['services'] == [
|
||||
{
|
||||
'name': service1.name,
|
||||
'id': str(service1.id),
|
||||
'restricted': False,
|
||||
'organisation': str(org1.id),
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def test_find_users_by_email_finds_user_by_partial_email(notify_db, client):
|
||||
|
||||
Reference in New Issue
Block a user