Refactor tests

This commit is contained in:
Ken Tsang
2017-11-03 17:26:53 +00:00
parent 85b8e24e17
commit 1c673a4afe
2 changed files with 9 additions and 21 deletions

View File

@@ -1,8 +1,6 @@
from datetime import datetime from datetime import datetime
import pytz
import uuid import uuid
from app import DATETIME_FORMAT
from app import db from app import db
from app.dao.jobs_dao import dao_create_job from app.dao.jobs_dao import dao_create_job
from app.dao.service_inbound_api_dao import save_service_inbound_api from app.dao.service_inbound_api_dao import save_service_inbound_api
@@ -249,10 +247,10 @@ def create_inbound_sms(
): ):
inbound = InboundSms( inbound = InboundSms(
service=service, service=service,
created_at=created_at or datetime.utcnow().strftime(DATETIME_FORMAT), created_at=created_at or datetime.utcnow(),
notify_number=notify_number or service.sms_sender, notify_number=notify_number or service.sms_sender,
user_number=user_number, user_number=user_number,
provider_date=provider_date or datetime.utcnow().strftime(DATETIME_FORMAT), provider_date=provider_date or datetime.utcnow(),
provider_reference=provider_reference or 'foo', provider_reference=provider_reference or 'foo',
content=content, content=content,
provider=provider provider=provider

View File

@@ -1,11 +1,7 @@
import uuid
import pytest import pytest
from flask import json from flask import json
from jsonschema.exceptions import ValidationError from jsonschema.exceptions import ValidationError
from app.dao.api_key_dao import save_model_api_key
from app.models import ApiKey, KEY_TYPE_NORMAL, EMAIL_TYPE, SMS_TYPE, TEMPLATE_TYPES
from app.v2.inbound_sms.inbound_sms_schemas import get_inbound_sms_response, get_inbound_sms_single_response 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 app.schema_validation import validate
@@ -42,23 +38,17 @@ invalid_inbound_sms_list = {
} }
def _get_inbound_sms(client, inbound_sms, url):
auth_header = create_authorization_header(service_id=inbound_sms.service_id)
response = client.get(url, headers=[auth_header])
return json.loads(response.get_data(as_text=True))
def test_get_inbound_sms_contract(client, sample_inbound_sms): def test_get_inbound_sms_contract(client, sample_inbound_sms):
response_json = _get_inbound_sms( auth_header = create_authorization_header(service_id=sample_inbound_sms.service_id)
client, response = client.get('/v2/inbound_sms/{}'.format(sample_inbound_sms.user_number), headers=[auth_header])
sample_inbound_sms, response_json = json.loads(response.get_data(as_text=True))
'/v2/inbound_sms/{}'.format(sample_inbound_sms.user_number)
) assert validate(response_json, get_inbound_sms_response)['inbound_sms_list'][0] \
res = validate(response_json, get_inbound_sms_response) == sample_inbound_sms.serialize()
def test_valid_inbound_sms_json(): def test_valid_inbound_sms_json():
validate(valid_inbound_sms, get_inbound_sms_single_response) assert validate(valid_inbound_sms, get_inbound_sms_single_response) == valid_inbound_sms
def test_valid_inbound_sms_list_json(): def test_valid_inbound_sms_list_json():