Remove arguments from fixtures

These can't be used, since we fixtures can no longer be called as if
they were functions, so we can simply the code by removing them.
This commit is contained in:
Katie Smith
2020-01-10 12:17:56 +00:00
parent 17f72dc4cd
commit 8e9b7ae368
2 changed files with 38 additions and 97 deletions

View File

@@ -79,7 +79,6 @@ def _get_notifications_csv(
def _get_notifications_csv_mock( def _get_notifications_csv_mock(
mocker, mocker,
api_user_active, api_user_active,
job_id=fake_uuid
): ):
return mocker.patch( return mocker.patch(
'app.notification_api_client.get_notifications_for_service', 'app.notification_api_client.get_notifications_for_service',

View File

@@ -825,16 +825,16 @@ def mock_get_service_template_with_placeholders_same_as_recipient(mocker):
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def mock_get_service_email_template(mocker, content=None, subject=None, redact_personalisation=False): def mock_get_service_email_template(mocker):
def _get(service_id, template_id, version=None): def _get(service_id, template_id, version=None):
template = template_json( template = template_json(
service_id, service_id,
template_id, template_id,
"Two week reminder", "Two week reminder",
"email", "email",
content or "Your vehicle tax expires on ((date))", "Your vehicle tax expires on ((date))",
subject or "Your ((thing)) is due soon", "Your ((thing)) is due soon",
redact_personalisation=redact_personalisation, redact_personalisation=False,
) )
return {'data': template} return {'data': template}
@@ -861,15 +861,15 @@ def mock_get_service_email_template_without_placeholders(mocker):
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def mock_get_service_letter_template(mocker, content=None, subject=None, postage='second'): def mock_get_service_letter_template(mocker):
def _get(service_id, template_id, version=None, postage=postage): def _get(service_id, template_id, version=None, postage='second'):
template = template_json( template = template_json(
service_id, service_id,
template_id, template_id,
"Two week reminder", "Two week reminder",
"letter", "letter",
content or "Template <em>content</em> with & entity", "Template <em>content</em> with & entity",
subject or "Subject", "Subject",
postage=postage, postage=postage,
) )
return {'data': template} return {'data': template}
@@ -1108,11 +1108,11 @@ def api_user_active(fake_uuid):
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def api_user_active_email_auth(fake_uuid, email_address='test@user.gov.uk'): def api_user_active_email_auth(fake_uuid):
user_data = {'id': fake_uuid, user_data = {'id': fake_uuid,
'name': 'Test User', 'name': 'Test User',
'password': 'somepassword', 'password': 'somepassword',
'email_address': email_address, 'email_address': 'test@user.gov.uk',
'mobile_number': '07700 900762', 'mobile_number': '07700 900762',
'state': 'active', 'state': 'active',
'failed_login_count': 0, 'failed_login_count': 0,
@@ -1755,14 +1755,6 @@ def mock_get_uploads(mocker, api_user_active):
def mock_get_notifications( def mock_get_notifications(
mocker, mocker,
api_user_active, api_user_active,
template_content=None,
diff_template_type=None,
personalisation=None,
redact_personalisation=False,
is_precompiled_letter=False,
client_reference=None,
noti_status=None,
postage=None,
): ):
def _get_notifications( def _get_notifications(
service_id, service_id,
@@ -1782,21 +1774,19 @@ def mock_get_notifications(
job = None job = None
if job_id is not None: if job_id is not None:
job = job_json(service_id, api_user_active, job_id=job_id) job = job_json(service_id, api_user_active, job_id=job_id)
if diff_template_type or template_type: if template_type:
template = template_json( template = template_json(
service_id, service_id,
id_=str(generate_uuid()), id_=str(generate_uuid()),
type_=diff_template_type or template_type[0], type_=template_type[0],
content=template_content, redact_personalisation=False,
redact_personalisation=redact_personalisation, is_precompiled_letter=False,
is_precompiled_letter=is_precompiled_letter,
) )
else: else:
template = template_json( template = template_json(
service_id, service_id,
id_=str(generate_uuid()), id_=str(generate_uuid()),
content=template_content, redact_personalisation=False,
redact_personalisation=redact_personalisation,
) )
return notification_json( return notification_json(
service_id, service_id,
@@ -1804,12 +1794,7 @@ def mock_get_notifications(
rows=rows, rows=rows,
job=job, job=job,
with_links=True if count_pages is None else count_pages, with_links=True if count_pages is None else count_pages,
personalisation=personalisation,
template_type=diff_template_type,
client_reference=client_reference,
status=noti_status,
created_by_name='Firstname Lastname', created_by_name='Firstname Lastname',
postage=postage
) )
return mocker.patch( return mocker.patch(
@@ -2036,38 +2021,35 @@ def mock_s3_upload(mocker):
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def mock_s3_download(mocker, content=None): def mock_s3_download(mocker):
if not content: def _download(service_id, upload_id):
content = """ return """
phone number,name phone number,name
+447700900986,John +447700900986,John
+447700900986,Smith +447700900986,Smith
""" """
def _download(service_id, upload_id):
return content
return mocker.patch('app.main.views.send.s3download', side_effect=_download) return mocker.patch('app.main.views.send.s3download', side_effect=_download)
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def mock_s3_set_metadata(mocker, content=None): def mock_s3_set_metadata(mocker):
return mocker.patch('app.main.views.send.set_metadata_on_csv_upload') return mocker.patch('app.main.views.send.set_metadata_on_csv_upload')
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def sample_invite(mocker, service_one, status='pending', permissions=None): def sample_invite(mocker, service_one):
id_ = USER_ONE_ID id_ = USER_ONE_ID
from_user = service_one['users'][0] from_user = service_one['users'][0]
email_address = 'invited_user@test.gov.uk' email_address = 'invited_user@test.gov.uk'
service_id = service_one['id'] service_id = service_one['id']
permissions = permissions or 'view_activity,send_messages,manage_service,manage_api_keys' permissions = 'view_activity,send_messages,manage_service,manage_api_keys'
created_at = str(datetime.utcnow()) created_at = str(datetime.utcnow())
auth_type = 'sms_auth' auth_type = 'sms_auth'
folder_permissions = [] folder_permissions = []
return invite_json( return invite_json(
id_, from_user, service_id, email_address, permissions, created_at, status, auth_type, folder_permissions) id_, from_user, service_id, email_address, permissions, created_at, 'pending', auth_type, folder_permissions)
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
@@ -2573,18 +2555,7 @@ def mock_reset_failed_login_count(mocker):
@pytest.fixture @pytest.fixture
def mock_get_notification( def mock_get_notification(mocker):
mocker,
notification_id=fake_uuid,
notification_status='delivered',
redact_personalisation=False,
template_type=None,
template_name='sample template',
is_precompiled_letter=False,
key_type=None,
postage=None,
sent_one_off=True,
):
def _get_notification( def _get_notification(
service_id, service_id,
notification_id, notification_id,
@@ -2592,31 +2563,23 @@ def mock_get_notification(
noti = notification_json( noti = notification_json(
service_id, service_id,
rows=1, rows=1,
status=notification_status, personalisation={'name': 'Jo'}
template_type=template_type,
postage=postage
)['notifications'][0] )['notifications'][0]
noti['id'] = notification_id noti['id'] = notification_id
if sent_one_off: noti['created_by'] = {
noti['created_by'] = { 'id': fake_uuid,
'id': fake_uuid, 'name': 'Test User',
'name': 'Test User', 'email_address': 'test@user.gov.uk'
'email_address': 'test@user.gov.uk' }
}
noti['personalisation'] = {'name': 'Jo'}
noti['template'] = template_json( noti['template'] = template_json(
service_id, service_id,
'5407f4db-51c7-4150-8758-35412d42186a', '5407f4db-51c7-4150-8758-35412d42186a',
content='hello ((name))', content='hello ((name))',
subject='blah', subject='blah',
redact_personalisation=redact_personalisation, redact_personalisation=False,
type_=template_type, name='sample template'
is_precompiled_letter=is_precompiled_letter,
name=template_name
) )
if key_type:
noti['key_type'] = key_type
return noti return noti
return mocker.patch( return mocker.patch(
@@ -2981,11 +2944,7 @@ def mock_get_organisations_with_unusual_domains(mocker):
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def mock_get_organisation( def mock_get_organisation(mocker):
mocker,
email_branding_id=None,
letter_branding_id=None,
):
def _get_organisation(org_id): def _get_organisation(org_id):
return organisation_json( return organisation_json(
org_id, org_id,
@@ -2994,29 +2953,15 @@ def mock_get_organisation(
'o2': 'Org 2', 'o2': 'Org 2',
'o3': 'Org 3', 'o3': 'Org 3',
}.get(org_id, 'Org 1'), }.get(org_id, 'Org 1'),
email_branding_id=email_branding_id,
letter_branding_id=letter_branding_id,
) )
return mocker.patch('app.organisations_client.get_organisation', side_effect=_get_organisation) return mocker.patch('app.organisations_client.get_organisation', side_effect=_get_organisation)
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def mock_get_organisation_by_domain( def mock_get_organisation_by_domain(mocker):
mocker,
name=False,
crown=True,
agreement_signed=False,
organisation_type='',
):
def _get_organisation_by_domain(org_id): def _get_organisation_by_domain(org_id):
return organisation_json( return organisation_json(org_id)
org_id,
name,
crown=crown,
agreement_signed=agreement_signed,
organisation_type=organisation_type,
)
return mocker.patch( return mocker.patch(
'app.organisations_client.get_organisation_by_domain', 'app.organisations_client.get_organisation_by_domain',
@@ -3027,18 +2972,14 @@ def mock_get_organisation_by_domain(
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def mock_get_service_organisation( def mock_get_service_organisation(
mocker, mocker,
name=False,
crown=True,
agreement_signed=None, agreement_signed=None,
organisation_type=None, organisation_type=None,
): ):
def _get_service_organisation(service_id): def _get_service_organisation(service_id):
return organisation_json( return organisation_json(
'7aa5d4e9-4385-4488-a489-07812ba13383', '7aa5d4e9-4385-4488-a489-07812ba13383',
name, agreement_signed=None,
crown=crown, organisation_type=None,
agreement_signed=agreement_signed,
organisation_type=organisation_type,
) )
return mocker.patch('app.organisations_client.get_service_organisation', side_effect=_get_service_organisation) return mocker.patch('app.organisations_client.get_service_organisation', side_effect=_get_service_organisation)
@@ -3111,12 +3052,13 @@ def mock_get_invited_users_for_organisation(mocker, sample_org_invite):
@pytest.fixture(scope='function') @pytest.fixture(scope='function')
def sample_org_invite(mocker, organisation_one, status='pending'): def sample_org_invite(mocker, organisation_one):
id_ = str(UUID(bytes=b'sample_org_invit', version=4)) id_ = str(UUID(bytes=b'sample_org_invit', version=4))
invited_by = organisation_one['users'][0] invited_by = organisation_one['users'][0]
email_address = 'invited_user@test.gov.uk' email_address = 'invited_user@test.gov.uk'
organisation = organisation_one['id'] organisation = organisation_one['id']
created_at = str(datetime.utcnow()) created_at = str(datetime.utcnow())
status = 'pending'
return org_invite_json(id_, invited_by, organisation, email_address, created_at, status) return org_invite_json(id_, invited_by, organisation, email_address, created_at, status)