2017-11-03 16:35:22 +00:00
|
|
|
import pytest
|
|
|
|
|
from flask import json
|
|
|
|
|
from jsonschema.exceptions import ValidationError
|
|
|
|
|
|
|
|
|
|
from app.v2.inbound_sms.inbound_sms_schemas import get_inbound_sms_response, get_inbound_sms_single_response
|
|
|
|
|
from app.schema_validation import validate
|
|
|
|
|
|
|
|
|
|
from tests import create_authorization_header
|
2017-11-07 16:39:11 +00:00
|
|
|
from tests.app.db import create_inbound_sms
|
2017-11-03 16:35:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
valid_inbound_sms = {
|
|
|
|
|
"provider_date": "2017-11-02T15:07:57.199541Z",
|
|
|
|
|
"provider_reference": "foo",
|
|
|
|
|
"user_number": "447700900111",
|
|
|
|
|
"created_at": "2017-11-02T15:07:57.197546Z",
|
|
|
|
|
"service_id": "a5149c32-f03b-4711-af49-ad6993797d45",
|
|
|
|
|
"id": "342786aa-23ce-4695-9aad-7f79e68ee29a",
|
|
|
|
|
"notify_number": "testing",
|
|
|
|
|
"content": "Hello"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
valid_inbound_sms_list = {
|
2017-11-07 12:19:44 +00:00
|
|
|
"received_text_messages": [valid_inbound_sms],
|
2017-11-06 18:22:18 +00:00
|
|
|
"links": {
|
|
|
|
|
"current": valid_inbound_sms["id"]
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-03 16:35:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
invalid_inbound_sms = {
|
|
|
|
|
"provider_date": "2017-11-02T15:07:57.199541",
|
|
|
|
|
"provider_reference": "foo",
|
|
|
|
|
"user_number": "447700900111",
|
|
|
|
|
"created_at": "2017-11-02T15:07:57.197546",
|
|
|
|
|
"service_id": "a5149c32-f03b-4711-af49-ad6993797d45",
|
|
|
|
|
"id": "342786aa-23ce-4695-9aad-7f79e68ee29a",
|
|
|
|
|
"notify_number": "testing"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
invalid_inbound_sms_list = {
|
2017-11-07 12:19:44 +00:00
|
|
|
"received_text_messages": [invalid_inbound_sms]
|
2017-11-03 16:35:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_inbound_sms_contract(client, sample_inbound_sms):
|
2017-11-03 17:26:53 +00:00
|
|
|
auth_header = create_authorization_header(service_id=sample_inbound_sms.service_id)
|
2017-11-07 16:39:11 +00:00
|
|
|
response = client.get('/v2/received-text-messages', headers=[auth_header])
|
2017-11-03 17:26:53 +00:00
|
|
|
response_json = json.loads(response.get_data(as_text=True))
|
|
|
|
|
|
2017-11-07 12:19:44 +00:00
|
|
|
assert validate(response_json, get_inbound_sms_response)['received_text_messages'][0] \
|
2017-11-03 17:26:53 +00:00
|
|
|
== sample_inbound_sms.serialize()
|
2017-11-03 16:35:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_valid_inbound_sms_json():
|
2017-11-03 17:26:53 +00:00
|
|
|
assert validate(valid_inbound_sms, get_inbound_sms_single_response) == valid_inbound_sms
|
2017-11-03 16:35:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_valid_inbound_sms_list_json():
|
|
|
|
|
validate(valid_inbound_sms_list, get_inbound_sms_response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_inbound_sms_json():
|
|
|
|
|
with pytest.raises(expected_exception=ValidationError):
|
|
|
|
|
validate(invalid_inbound_sms, get_inbound_sms_single_response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_inbound_sms_list_json():
|
|
|
|
|
with pytest.raises(expected_exception=ValidationError):
|
|
|
|
|
validate(invalid_inbound_sms_list, get_inbound_sms_response)
|