mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-24 01:11:38 -05:00
Merge pull request #2540 from alphagov/remove-old-fields-from-organisations-and-services
Remove old fields from organisations and services
This commit is contained in:
@@ -622,15 +622,18 @@ def create_domain(domain, organisation_id):
|
||||
return domain
|
||||
|
||||
|
||||
def create_organisation(name='test_org_1', active=True, organisation_type=None):
|
||||
def create_organisation(name='test_org_1', active=True, organisation_type=None, domains=None):
|
||||
data = {
|
||||
'name': name,
|
||||
'active': active,
|
||||
'organisation_type': organisation_type
|
||||
'organisation_type': organisation_type,
|
||||
}
|
||||
organisation = Organisation(**data)
|
||||
dao_create_organisation(organisation)
|
||||
|
||||
for domain in domains or []:
|
||||
create_domain(domain, organisation.id)
|
||||
|
||||
return organisation
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from tests.app.db import (
|
||||
|
||||
def test_get_all_organisations(admin_request, notify_db_session):
|
||||
create_organisation(name='inactive org', active=False)
|
||||
create_organisation(name='active org')
|
||||
create_organisation(name='active org', domains=['example.com'])
|
||||
|
||||
response = admin_request.get(
|
||||
'organisation.get_organisations',
|
||||
@@ -27,9 +27,11 @@ def test_get_all_organisations(admin_request, notify_db_session):
|
||||
assert response[0]['name'] == 'active org'
|
||||
assert response[0]['active'] is True
|
||||
assert response[0]['count_of_live_services'] == 0
|
||||
assert response[0]['domains'] == ['example.com']
|
||||
assert response[1]['name'] == 'inactive org'
|
||||
assert response[1]['active'] is False
|
||||
assert response[1]['count_of_live_services'] == 0
|
||||
assert response[1]['domains'] == []
|
||||
|
||||
|
||||
def test_get_organisation_by_id(admin_request, notify_db_session):
|
||||
@@ -78,10 +80,10 @@ def test_get_organisation_by_id(admin_request, notify_db_session):
|
||||
|
||||
def test_get_organisation_by_id_returns_domains(admin_request, notify_db_session):
|
||||
|
||||
org = create_organisation()
|
||||
|
||||
create_domain('foo.gov.uk', org.id)
|
||||
create_domain('bar.gov.uk', org.id)
|
||||
org = create_organisation(domains=[
|
||||
'foo.gov.uk',
|
||||
'bar.gov.uk',
|
||||
])
|
||||
|
||||
response = admin_request.get(
|
||||
'organisation.get_organisation_by_id',
|
||||
|
||||
@@ -837,41 +837,20 @@ def test_get_orgs_and_services_nests_services(admin_request, sample_user):
|
||||
|
||||
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,
|
||||
@@ -917,30 +896,15 @@ def test_get_orgs_and_services_only_returns_active(admin_request, sample_user):
|
||||
|
||||
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,
|
||||
@@ -983,25 +947,15 @@ def test_get_orgs_and_services_only_shows_users_orgs_and_services(admin_request,
|
||||
|
||||
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'] == [
|
||||
|
||||
Reference in New Issue
Block a user