make inbound sms honour data retention

code inspired by the delete notification code, but with some clean up
since we don't deal with different types etc, and only need to run the
query for services with inbound numbers

also, update tests.app.db.create_inbound_sms to create inbound numbers
and assign them to services to ensure the test db is always accurate
and reflects real world usage
This commit is contained in:
Leo Hemsted
2019-02-26 17:57:55 +00:00
parent 38f0ea6cca
commit e7b8f83fc8
3 changed files with 91 additions and 37 deletions

View File

@@ -1,3 +1,4 @@
import random
import uuid
from datetime import datetime, date
@@ -318,10 +319,18 @@ def create_inbound_sms(
provider="mmg",
created_at=None
):
if not service.inbound_number:
create_inbound_number(
# create random inbound number
notify_number or '07{:09}'.format(random.randint(0, 1e9 - 1)),
provider=provider,
service_id=service.id
)
inbound = InboundSms(
service=service,
created_at=created_at or datetime.utcnow(),
notify_number=notify_number or service.get_default_sms_sender(),
notify_number=service.get_inbound_number(),
user_number=user_number,
provider_date=provider_date or datetime.utcnow(),
provider_reference=provider_reference or 'foo',