mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-02 17:48:50 -04:00
notify-api-412 use black to enforce python coding style
This commit is contained in:
@@ -6,68 +6,72 @@ from tests import organization_json, service_json
|
||||
from tests.conftest import ORGANISATION_ID, create_folder, create_template
|
||||
|
||||
|
||||
def test_organization_type_when_services_organization_has_no_org_type(mocker, service_one):
|
||||
def test_organization_type_when_services_organization_has_no_org_type(
|
||||
mocker, service_one
|
||||
):
|
||||
service = Service(service_one)
|
||||
service._dict['organization_id'] = ORGANISATION_ID
|
||||
service._dict["organization_id"] = ORGANISATION_ID
|
||||
org = organization_json(organization_type=None)
|
||||
mocker.patch('app.organizations_client.get_organization', return_value=org)
|
||||
mocker.patch("app.organizations_client.get_organization", return_value=org)
|
||||
|
||||
assert not org['organization_type']
|
||||
assert service.organization_type == 'federal'
|
||||
assert not org["organization_type"]
|
||||
assert service.organization_type == "federal"
|
||||
|
||||
|
||||
def test_organization_type_when_service_and_its_org_both_have_an_org_type(mocker, service_one):
|
||||
def test_organization_type_when_service_and_its_org_both_have_an_org_type(
|
||||
mocker, service_one
|
||||
):
|
||||
# service_one has an organization_type of 'central'
|
||||
service = Service(service_one)
|
||||
service._dict['organization'] = ORGANISATION_ID
|
||||
org = organization_json(organization_type='local')
|
||||
mocker.patch('app.organizations_client.get_organization', return_value=org)
|
||||
service._dict["organization"] = ORGANISATION_ID
|
||||
org = organization_json(organization_type="local")
|
||||
mocker.patch("app.organizations_client.get_organization", return_value=org)
|
||||
|
||||
assert service.organization_type == 'local'
|
||||
assert service.organization_type == "local"
|
||||
|
||||
|
||||
def test_organization_name_comes_from_cache(mocker, service_one):
|
||||
mock_redis_get = mocker.patch(
|
||||
'app.extensions.RedisClient.get',
|
||||
"app.extensions.RedisClient.get",
|
||||
return_value=b'"Borchester Council"',
|
||||
)
|
||||
mock_get_organization = mocker.patch('app.organizations_client.get_organization')
|
||||
mock_get_organization = mocker.patch("app.organizations_client.get_organization")
|
||||
service = Service(service_one)
|
||||
service._dict['organization'] = ORGANISATION_ID
|
||||
service._dict["organization"] = ORGANISATION_ID
|
||||
|
||||
assert service.organization_name == 'Borchester Council'
|
||||
mock_redis_get.assert_called_once_with(f'organization-{ORGANISATION_ID}-name')
|
||||
assert service.organization_name == "Borchester Council"
|
||||
mock_redis_get.assert_called_once_with(f"organization-{ORGANISATION_ID}-name")
|
||||
assert mock_get_organization.called is False
|
||||
|
||||
|
||||
def test_organization_name_goes_into_cache(mocker, service_one):
|
||||
mocker.patch(
|
||||
'app.extensions.RedisClient.get',
|
||||
"app.extensions.RedisClient.get",
|
||||
return_value=None,
|
||||
)
|
||||
mock_redis_set = mocker.patch(
|
||||
'app.extensions.RedisClient.set',
|
||||
"app.extensions.RedisClient.set",
|
||||
)
|
||||
mocker.patch(
|
||||
'app.organizations_client.get_organization',
|
||||
"app.organizations_client.get_organization",
|
||||
return_value=organization_json(),
|
||||
)
|
||||
service = Service(service_one)
|
||||
service._dict['organization'] = ORGANISATION_ID
|
||||
service._dict["organization"] = ORGANISATION_ID
|
||||
|
||||
assert service.organization_name == 'Test Organization'
|
||||
assert service.organization_name == "Test Organization"
|
||||
mock_redis_set.assert_called_once_with(
|
||||
f'organization-{ORGANISATION_ID}-name',
|
||||
f"organization-{ORGANISATION_ID}-name",
|
||||
'"Test Organization"',
|
||||
ex=604800,
|
||||
)
|
||||
|
||||
|
||||
def test_service_without_organization_doesnt_need_org_api(mocker, service_one):
|
||||
mock_redis_get = mocker.patch('app.extensions.RedisClient.get')
|
||||
mock_get_organization = mocker.patch('app.organizations_client.get_organization')
|
||||
mock_redis_get = mocker.patch("app.extensions.RedisClient.get")
|
||||
mock_get_organization = mocker.patch("app.organizations_client.get_organization")
|
||||
service = Service(service_one)
|
||||
service._dict['organization'] = None
|
||||
service._dict["organization"] = None
|
||||
|
||||
assert service.organization_id is None
|
||||
assert service.organization_name is None
|
||||
@@ -79,17 +83,17 @@ def test_service_without_organization_doesnt_need_org_api(mocker, service_one):
|
||||
|
||||
def test_bad_permission_raises(service_one):
|
||||
with pytest.raises(KeyError) as e:
|
||||
Service(service_one).has_permission('foo')
|
||||
Service(service_one).has_permission("foo")
|
||||
assert str(e.value) == "'foo is not a service permission'"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("purchase_order_number,expected_result", [
|
||||
[None, None],
|
||||
["PO1234", [None, None, None, "PO1234"]]
|
||||
])
|
||||
@pytest.mark.parametrize(
|
||||
"purchase_order_number,expected_result",
|
||||
[[None, None], ["PO1234", [None, None, None, "PO1234"]]],
|
||||
)
|
||||
def test_service_billing_details(purchase_order_number, expected_result):
|
||||
service = Service(service_json(purchase_order_number=purchase_order_number))
|
||||
service._dict['purchase_order_number'] = purchase_order_number
|
||||
service._dict["purchase_order_number"] = purchase_order_number
|
||||
assert service.billing_details == expected_result
|
||||
|
||||
|
||||
@@ -99,15 +103,15 @@ def test_has_templates_of_type_includes_folders(
|
||||
mock_get_template_folders,
|
||||
):
|
||||
mocker.patch(
|
||||
'app.service_api_client.get_service_templates',
|
||||
return_value={'data': [create_template(
|
||||
folder='something', template_type='sms'
|
||||
)]}
|
||||
"app.service_api_client.get_service_templates",
|
||||
return_value={
|
||||
"data": [create_template(folder="something", template_type="sms")]
|
||||
},
|
||||
)
|
||||
|
||||
mocker.patch(
|
||||
'app.template_folder_api_client.get_template_folders',
|
||||
return_value=[create_folder(id='something')]
|
||||
"app.template_folder_api_client.get_template_folders",
|
||||
return_value=[create_folder(id="something")],
|
||||
)
|
||||
|
||||
assert Service(service_one).has_templates_of_type('sms')
|
||||
assert Service(service_one).has_templates_of_type("sms")
|
||||
|
||||
Reference in New Issue
Block a user