Updated inbound sms API endpoints

- from `/v2/inbound_sms` to `/v2/received-text-messages`
- use paginated results
This commit is contained in:
Ken Tsang
2017-11-06 18:22:18 +00:00
parent 02ee072251
commit 0350c99a3e
5 changed files with 122 additions and 20 deletions

View File

@@ -14,12 +14,12 @@ def test_get_all_inbound_sms_returns_200(
create_inbound_sms(service=sample_service, user_number='447700900111', content='Hi'),
create_inbound_sms(service=sample_service, user_number='447700900112'),
create_inbound_sms(service=sample_service, user_number='447700900111', content='Bye'),
create_inbound_sms(service=sample_service, user_number='447700900113')
create_inbound_sms(service=sample_service, user_number='07700900113')
]
auth_header = create_authorization_header(service_id=sample_service.id)
response = client.get(
path='/v2/inbound_sms',
path='/v2/received-text-messages',
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 200
@@ -34,12 +34,47 @@ def test_get_all_inbound_sms_returns_200(
assert json_response == expected_response
@pytest.mark.parametrize('inbound_sms_path,user_number', [
('v2_inbound_sms.get_all_inbound_sms', None),
('v2_inbound_sms.get_inbound_sms_by_number', '447700900111')
])
def test_get_all_inbound_sms_generate_page_links(
client, sample_service, mocker, inbound_sms_path, user_number
):
mocker.patch.dict("app.v2.inbound_sms.get_inbound_sms.current_app.config", {"API_PAGE_SIZE": 1})
all_inbound_sms = [
create_inbound_sms(service=sample_service, user_number='447700900111', content='Hi'),
create_inbound_sms(service=sample_service, user_number='447700900111'),
]
auth_header = create_authorization_header(service_id=sample_service.id)
response = client.get(
path=url_for(inbound_sms_path, user_number=user_number),
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 200
json_response = json.loads(response.get_data(as_text=True))
expected_inbound_sms_list = [all_inbound_sms[-1].serialize()]
assert json_response['inbound_sms_list'] == expected_inbound_sms_list
assert url_for(
inbound_sms_path,
user_number=user_number,
_external=True) == json_response['links']['current']
assert url_for(
inbound_sms_path,
user_number=user_number,
older_than=all_inbound_sms[-1].id,
_external=True) == json_response['links']['next']
def test_get_all_inbound_sms_for_no_inbound_sms_returns_200(
client, sample_service
):
auth_header = create_authorization_header(service_id=sample_service.id)
response = client.get(
path='/v2/inbound_sms',
path='/v2/received-text-messages',
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 200
@@ -55,10 +90,13 @@ def test_get_all_inbound_sms_for_no_inbound_sms_returns_200(
def test_get_inbound_sms_by_number_returns_200(
client, sample_service
):
sample_inbound_sms = create_inbound_sms(service=sample_service)
sample_inbound_sms1 = create_inbound_sms(service=sample_service, user_number='447700900111')
create_inbound_sms(service=sample_service, user_number='447700900112')
sample_inbound_sms2 = create_inbound_sms(service=sample_service, user_number='447700900111')
auth_header = create_authorization_header(service_id=sample_service.id)
response = client.get(
path='/v2/inbound_sms/{}'.format(sample_inbound_sms.user_number),
path='/v2/received-text-messages/{}'.format('07700900111'),
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 200
@@ -66,7 +104,7 @@ def test_get_inbound_sms_by_number_returns_200(
json_response = json.loads(response.get_data(as_text=True))['inbound_sms_list']
expected_response = [sample_inbound_sms.serialize()]
expected_response = [sample_inbound_sms2.serialize(), sample_inbound_sms1.serialize()]
assert json_response == expected_response
@@ -76,7 +114,7 @@ def test_get_inbound_sms_for_no_inbound_sms_returns_200(
):
auth_header = create_authorization_header(service_id=sample_service.id)
response = client.get(
path='/v2/inbound_sms',
path='/v2/received-text-messages',
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 200
@@ -92,7 +130,7 @@ def test_get_inbound_sms_for_no_inbound_sms_returns_200(
def test_get_inbound_sms_by_nonexistent_number(client, sample_service):
auth_header = create_authorization_header(service_id=sample_service.id)
response = client.get(
path='/v2/inbound_sms/447700900000',
path='/v2/received-text-messages/447700900000',
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 200
@@ -113,7 +151,7 @@ def test_get_inbound_sms_by_invalid_number(
client, sample_service, invalid_number, expected_message):
auth_header = create_authorization_header(service_id=sample_service.id)
response = client.get(
path='/v2/inbound_sms/{}'.format(invalid_number),
path='/v2/received-text-messages/{}'.format(invalid_number),
headers=[('Content-Type', 'application/json'), auth_header])
assert response.status_code == 400

View File

@@ -20,7 +20,11 @@ valid_inbound_sms = {
}
valid_inbound_sms_list = {
"inbound_sms_list": [valid_inbound_sms]
"inbound_sms_list": [valid_inbound_sms],
"links": {
"current": valid_inbound_sms["id"]
}
}
invalid_inbound_sms = {
@@ -40,7 +44,7 @@ invalid_inbound_sms_list = {
def test_get_inbound_sms_contract(client, sample_inbound_sms):
auth_header = create_authorization_header(service_id=sample_inbound_sms.service_id)
response = client.get('/v2/inbound_sms/{}'.format(sample_inbound_sms.user_number), headers=[auth_header])
response = client.get('/v2/received-text-messages/{}'.format(sample_inbound_sms.user_number), headers=[auth_header])
response_json = json.loads(response.get_data(as_text=True))
assert validate(response_json, get_inbound_sms_response)['inbound_sms_list'][0] \