mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Update python client to version 1.0.0.
This version of the client removed the request method, path and body from the encode and decode methods. The biggest changes here is to the unit tests.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import json
|
||||
import uuid
|
||||
import random
|
||||
import string
|
||||
from app.models import Template
|
||||
@@ -17,11 +16,7 @@ def test_should_create_a_new_sms_template_for_a_service(notify_api, sample_user,
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -50,11 +45,7 @@ def test_should_create_a_new_email_template_for_a_service(notify_api, sample_use
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -82,11 +73,7 @@ def test_should_be_error_if_service_does_not_exist_on_create(notify_api, sample_
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(fake_uuid),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(fake_uuid),
|
||||
@@ -110,11 +97,7 @@ def test_should_error_if_created_by_missing(notify_api, sample_user, sample_serv
|
||||
'service': service_id
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(service_id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(service_id),
|
||||
@@ -133,11 +116,7 @@ def test_should_be_error_if_service_does_not_exist_on_update(notify_api, fake_uu
|
||||
'name': 'my template'
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template/{}'.format(fake_uuid, fake_uuid),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template/{}'.format(fake_uuid, fake_uuid),
|
||||
@@ -161,11 +140,7 @@ def test_must_have_a_subject_on_an_email_template(notify_api, sample_user, sampl
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -190,11 +165,7 @@ def test_must_have_a_uniqe_subject_on_an_email_template(notify_api, sample_user,
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -212,11 +183,7 @@ def test_must_have_a_uniqe_subject_on_an_email_template(notify_api, sample_user,
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -241,11 +208,7 @@ def test_should_be_able_to_update_a_template(notify_api, sample_user, sample_ser
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
create_response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -260,11 +223,7 @@ def test_should_be_able_to_update_a_template(notify_api, sample_user, sample_ser
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template/{}'.format(sample_service.id, json_resp['data']['id']),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
update_response = client.post(
|
||||
'/service/{}/template/{}'.format(sample_service.id, json_resp['data']['id']),
|
||||
@@ -291,13 +250,7 @@ def test_should_be_able_to_archive_template(notify_api, sample_user, sample_serv
|
||||
|
||||
json_data = json.dumps(data)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template/{}'.format(
|
||||
str(sample_template.service.id),
|
||||
str(sample_template.id)),
|
||||
method='POST',
|
||||
request_body=json_data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
resp = client.post(
|
||||
'/service/{}/template/{}'.format(sample_template.service.id, sample_template.id),
|
||||
@@ -330,21 +283,13 @@ def test_should_be_able_to_get_all_templates_for_a_service(notify_api, sample_us
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data_2 = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data_1
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
data=data_1
|
||||
)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data_2
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -352,10 +297,7 @@ def test_should_be_able_to_get_all_templates_for_a_service(notify_api, sample_us
|
||||
data=data_2
|
||||
)
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -375,20 +317,14 @@ def test_should_get_only_templates_for_that_service(notify_api, sample_user, ser
|
||||
service_1 = service_factory.get('service 1', email_from='service.1')
|
||||
service_2 = service_factory.get('service 2', email_from='service.2')
|
||||
|
||||
auth_header_1 = create_authorization_header(
|
||||
path='/service/{}/template'.format(service_1.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header_1 = create_authorization_header()
|
||||
|
||||
response_1 = client.get(
|
||||
'/service/{}/template'.format(service_1.id),
|
||||
headers=[auth_header_1]
|
||||
)
|
||||
|
||||
auth_header_2 = create_authorization_header(
|
||||
path='/service/{}/template'.format(service_2.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header_2 = create_authorization_header()
|
||||
|
||||
response_2 = client.get(
|
||||
'/service/{}/template'.format(service_2.id),
|
||||
@@ -413,11 +349,7 @@ def test_should_get_only_templates_for_that_service(notify_api, sample_user, ser
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
create_auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(service_1.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
create_auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
'/service/{}/template'.format(service_1.id),
|
||||
headers=[('Content-Type', 'application/json'), create_auth_header],
|
||||
@@ -448,10 +380,7 @@ def test_should_return_empty_array_if_no_templates_for_service(notify_api, sampl
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -467,10 +396,7 @@ def test_should_return_404_if_no_templates_for_service_with_id(notify_api, sampl
|
||||
with notify_api.test_request_context():
|
||||
with notify_api.test_client() as client:
|
||||
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template/{}'.format(sample_service.id, fake_uuid),
|
||||
method='GET'
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.get(
|
||||
'/service/{}/template/{}'.format(sample_service.id, fake_uuid),
|
||||
@@ -496,11 +422,7 @@ def test_create_400_for_over_limit_content(notify_api, sample_user, sample_servi
|
||||
'created_by': str(sample_user.id)
|
||||
}
|
||||
data = json.dumps(data)
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template'.format(sample_service.id),
|
||||
method='POST',
|
||||
request_body=data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
|
||||
response = client.post(
|
||||
'/service/{}/template'.format(sample_service.id),
|
||||
@@ -522,11 +444,7 @@ def test_update_400_for_over_limit_content(notify_api, sample_user, sample_templ
|
||||
'content': ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(limit + 1)),
|
||||
'created_by': str(sample_user.id)
|
||||
})
|
||||
auth_header = create_authorization_header(
|
||||
path='/service/{}/template/{}'.format(sample_template.service.id, sample_template.id),
|
||||
method='POST',
|
||||
request_body=json_data
|
||||
)
|
||||
auth_header = create_authorization_header()
|
||||
resp = client.post(
|
||||
'/service/{}/template/{}'.format(sample_template.service.id, sample_template.id),
|
||||
headers=[('Content-Type', 'application/json'), auth_header],
|
||||
|
||||
Reference in New Issue
Block a user