add create service tests for dvla_org

This commit is contained in:
Leo Hemsted
2017-04-20 17:22:45 +01:00
parent f127bac600
commit 76676280ab

View File

@@ -129,21 +129,20 @@ def test_get_service_list_should_return_empty_list_if_no_services(notify_api, no
assert len(json_resp['data']) == 0 assert len(json_resp['data']) == 0
def test_get_service_by_id(notify_api, sample_service): def test_get_service_by_id(client, sample_service):
with notify_api.test_request_context(): auth_header = create_authorization_header()
with notify_api.test_client() as client: resp = client.get(
auth_header = create_authorization_header() '/service/{}'.format(sample_service.id),
resp = client.get( headers=[auth_header]
'/service/{}'.format(sample_service.id), )
headers=[auth_header] assert resp.status_code == 200
) json_resp = json.loads(resp.get_data(as_text=True))
assert resp.status_code == 200 assert json_resp['data']['name'] == sample_service.name
json_resp = json.loads(resp.get_data(as_text=True)) assert json_resp['data']['id'] == str(sample_service.id)
assert json_resp['data']['name'] == sample_service.name assert not json_resp['data']['research_mode']
assert json_resp['data']['id'] == str(sample_service.id) assert json_resp['data']['organisation'] is None
assert not json_resp['data']['research_mode'] assert json_resp['data']['branding'] == 'govuk'
assert json_resp['data']['organisation'] is None assert json_resp['data']['dvla_organisation'] == '001'
assert json_resp['data']['branding'] == 'govuk'
def test_get_service_by_id_should_404_if_no_service(notify_api, notify_db): def test_get_service_by_id_should_404_if_no_service(notify_api, notify_db):
@@ -191,41 +190,40 @@ def test_get_service_by_id_should_404_if_no_service_for_user(notify_api, sample_
assert json_resp['message'] == 'No result found' assert json_resp['message'] == 'No result found'
def test_create_service(notify_api, sample_user): def test_create_service(client, sample_user):
with notify_api.test_request_context(): data = {
with notify_api.test_client() as client: 'name': 'created service',
data = { 'user_id': str(sample_user.id),
'name': 'created service', 'message_limit': 1000,
'user_id': str(sample_user.id), 'restricted': False,
'message_limit': 1000, 'active': False,
'restricted': False, 'email_from': 'created.service',
'active': False, 'created_by': str(sample_user.id)}
'email_from': 'created.service', auth_header = create_authorization_header()
'created_by': str(sample_user.id)} headers = [('Content-Type', 'application/json'), auth_header]
auth_header = create_authorization_header() resp = client.post(
headers = [('Content-Type', 'application/json'), auth_header] '/service',
resp = client.post( data=json.dumps(data),
'/service', headers=headers)
data=json.dumps(data), json_resp = json.loads(resp.get_data(as_text=True))
headers=headers) assert resp.status_code == 201
json_resp = json.loads(resp.get_data(as_text=True)) assert json_resp['data']['id']
assert resp.status_code == 201 assert json_resp['data']['name'] == 'created service'
assert json_resp['data']['id'] assert json_resp['data']['email_from'] == 'created.service'
assert json_resp['data']['name'] == 'created service' assert not json_resp['data']['research_mode']
assert json_resp['data']['email_from'] == 'created.service' assert json_resp['data']['dvla_organisation'] == '001'
assert not json_resp['data']['research_mode']
auth_header_fetch = create_authorization_header() auth_header_fetch = create_authorization_header()
resp = client.get( resp = client.get(
'/service/{}?user_id={}'.format(json_resp['data']['id'], sample_user.id), '/service/{}?user_id={}'.format(json_resp['data']['id'], sample_user.id),
headers=[auth_header_fetch] headers=[auth_header_fetch]
) )
assert resp.status_code == 200 assert resp.status_code == 200
json_resp = json.loads(resp.get_data(as_text=True)) json_resp = json.loads(resp.get_data(as_text=True))
assert json_resp['data']['name'] == 'created service' assert json_resp['data']['name'] == 'created service'
assert not json_resp['data']['research_mode'] assert not json_resp['data']['research_mode']
assert not json_resp['data']['can_send_letters'] assert not json_resp['data']['can_send_letters']
def test_should_not_create_service_with_missing_user_id_field(notify_api, fake_uuid): def test_should_not_create_service_with_missing_user_id_field(notify_api, fake_uuid):