mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 00:06:16 -04:00
Update limit to message_limit.
Further db changes and updates. Remove traceback print out. Fix bug in passing template id to a task.
This commit is contained in:
@@ -70,7 +70,7 @@ def delete_verify_codes():
|
|||||||
def delete_successful_notifications():
|
def delete_successful_notifications():
|
||||||
try:
|
try:
|
||||||
start = datetime.utcnow()
|
start = datetime.utcnow()
|
||||||
deleted = delete_notifications_created_more_than_a_week_ago('sent')
|
deleted = delete_notifications_created_more_than_a_week_ago('sending')
|
||||||
current_app.logger.info(
|
current_app.logger.info(
|
||||||
"Delete job started {} finished {} deleted {} successful notifications".format(
|
"Delete job started {} finished {} deleted {} successful notifications".format(
|
||||||
start,
|
start,
|
||||||
@@ -129,12 +129,13 @@ def process_job(job_id):
|
|||||||
if stats:
|
if stats:
|
||||||
total_sent = stats.emails_requested + stats.sms_requested
|
total_sent = stats.emails_requested + stats.sms_requested
|
||||||
|
|
||||||
if total_sent + job.notification_count > service.limit:
|
if total_sent + job.notification_count > service.message_limit:
|
||||||
job.status = 'sending limits exceeded'
|
job.status = 'sending limits exceeded'
|
||||||
job.processing_finished = datetime.utcnow()
|
job.processing_finished = datetime.utcnow()
|
||||||
dao_update_job(job)
|
dao_update_job(job)
|
||||||
current_app.logger.info(
|
current_app.logger.info(
|
||||||
"Job {} size {} error. Sending limits {} exceeded".format(job_id, job.notification_count, service.limit)
|
"Job {} size {} error. Sending limits {} exceeded".format(
|
||||||
|
job_id, job.notification_count, service.message_limit)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -152,7 +153,7 @@ def process_job(job_id):
|
|||||||
).recipients_and_personalisation:
|
).recipients_and_personalisation:
|
||||||
|
|
||||||
encrypted = encryption.encrypt({
|
encrypted = encryption.encrypt({
|
||||||
'template': template.id,
|
'template': str(template.id),
|
||||||
'job': str(job.id),
|
'job': str(job.id),
|
||||||
'to': recipient,
|
'to': recipient,
|
||||||
'personalisation': personalisation
|
'personalisation': personalisation
|
||||||
@@ -217,7 +218,7 @@ def send_sms(service_id, notification_id, encrypted_notification, created_at):
|
|||||||
to=notification['to'],
|
to=notification['to'],
|
||||||
service_id=service_id,
|
service_id=service_id,
|
||||||
job_id=notification.get('job', None),
|
job_id=notification.get('job', None),
|
||||||
status='failed' if restricted else 'sent',
|
status='failed' if restricted else 'sending',
|
||||||
created_at=datetime.strptime(created_at, DATETIME_FORMAT),
|
created_at=datetime.strptime(created_at, DATETIME_FORMAT),
|
||||||
sent_at=sent_at,
|
sent_at=sent_at,
|
||||||
sent_by=client.get_name()
|
sent_by=client.get_name()
|
||||||
@@ -277,7 +278,7 @@ def send_email(service_id, notification_id, subject, from_address, encrypted_not
|
|||||||
to=notification['to'],
|
to=notification['to'],
|
||||||
service_id=service_id,
|
service_id=service_id,
|
||||||
job_id=notification.get('job', None),
|
job_id=notification.get('job', None),
|
||||||
status='failed' if restricted else 'sent',
|
status='failed' if restricted else 'sending',
|
||||||
created_at=datetime.strptime(created_at, DATETIME_FORMAT),
|
created_at=datetime.strptime(created_at, DATETIME_FORMAT),
|
||||||
sent_at=sent_at,
|
sent_at=sent_at,
|
||||||
sent_by=client.get_name()
|
sent_by=client.get_name()
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ ses_response_map = {
|
|||||||
'Bounce': {
|
'Bounce': {
|
||||||
"message": 'Bounced',
|
"message": 'Bounced',
|
||||||
"success": False,
|
"success": False,
|
||||||
"notification_status": 'bounce',
|
"notification_status": 'failed',
|
||||||
"notification_statistics_status": STATISTICS_FAILURE
|
"notification_statistics_status": STATISTICS_FAILURE
|
||||||
},
|
},
|
||||||
'Delivery': {
|
'Delivery': {
|
||||||
@@ -19,9 +19,9 @@ ses_response_map = {
|
|||||||
},
|
},
|
||||||
'Complaint': {
|
'Complaint': {
|
||||||
"message": 'Complaint',
|
"message": 'Complaint',
|
||||||
"success": False,
|
"success": True,
|
||||||
"notification_status": 'complaint',
|
"notification_status": 'delivered',
|
||||||
"notification_statistics_status": STATISTICS_FAILURE
|
"notification_statistics_status": STATISTICS_DELIVERED
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ firetext_responses = {
|
|||||||
},
|
},
|
||||||
'2': {
|
'2': {
|
||||||
"message": 'Undelivered (Pending with Network)',
|
"message": 'Undelivered (Pending with Network)',
|
||||||
"success": False,
|
"success": True,
|
||||||
"notification_statistics_status": None,
|
"notification_statistics_status": STATISTICS_DELIVERED,
|
||||||
"notification_status": 'sent'
|
"notification_status": 'delivered'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,8 +44,10 @@ class TwilioClient(SmsClient):
|
|||||||
def status(self, message_id):
|
def status(self, message_id):
|
||||||
try:
|
try:
|
||||||
response = self.client.messages.get(message_id)
|
response = self.client.messages.get(message_id)
|
||||||
if response.status in ('delivered', 'undelivered', 'failed'):
|
if response.status in ('delivered', 'failed'):
|
||||||
return response.status
|
return response.status
|
||||||
|
elif response.status == 'undelivered':
|
||||||
|
return 'sending'
|
||||||
return None
|
return None
|
||||||
except TwilioRestException as e:
|
except TwilioRestException as e:
|
||||||
current_app.logger.exception(e)
|
current_app.logger.exception(e)
|
||||||
|
|||||||
@@ -112,12 +112,12 @@ def update_query(notification_type, status):
|
|||||||
TEMPLATE_TYPE_SMS: {
|
TEMPLATE_TYPE_SMS: {
|
||||||
STATISTICS_REQUESTED: NotificationStatistics.sms_requested,
|
STATISTICS_REQUESTED: NotificationStatistics.sms_requested,
|
||||||
STATISTICS_DELIVERED: NotificationStatistics.sms_delivered,
|
STATISTICS_DELIVERED: NotificationStatistics.sms_delivered,
|
||||||
STATISTICS_FAILURE: NotificationStatistics.sms_error
|
STATISTICS_FAILURE: NotificationStatistics.sms_failed
|
||||||
},
|
},
|
||||||
TEMPLATE_TYPE_EMAIL: {
|
TEMPLATE_TYPE_EMAIL: {
|
||||||
STATISTICS_REQUESTED: NotificationStatistics.emails_requested,
|
STATISTICS_REQUESTED: NotificationStatistics.emails_requested,
|
||||||
STATISTICS_DELIVERED: NotificationStatistics.emails_delivered,
|
STATISTICS_DELIVERED: NotificationStatistics.emails_delivered,
|
||||||
STATISTICS_FAILURE: NotificationStatistics.emails_error
|
STATISTICS_FAILURE: NotificationStatistics.emails_failed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class Service(db.Model):
|
|||||||
nullable=True,
|
nullable=True,
|
||||||
onupdate=datetime.datetime.now)
|
onupdate=datetime.datetime.now)
|
||||||
active = db.Column(db.Boolean, index=False, unique=False, nullable=False)
|
active = db.Column(db.Boolean, index=False, unique=False, nullable=False)
|
||||||
limit = db.Column(db.BigInteger, index=False, unique=False, nullable=False)
|
message_limit = db.Column(db.BigInteger, index=False, unique=False, nullable=False)
|
||||||
users = db.relationship(
|
users = db.relationship(
|
||||||
'User',
|
'User',
|
||||||
secondary=user_to_service,
|
secondary=user_to_service,
|
||||||
@@ -121,10 +121,10 @@ class NotificationStatistics(db.Model):
|
|||||||
service = db.relationship('Service', backref=db.backref('service_notification_stats', lazy='dynamic'))
|
service = db.relationship('Service', backref=db.backref('service_notification_stats', lazy='dynamic'))
|
||||||
emails_requested = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
emails_requested = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
||||||
emails_delivered = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
emails_delivered = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
||||||
emails_error = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
emails_failed = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
||||||
sms_requested = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
sms_requested = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
||||||
sms_delivered = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
sms_delivered = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
||||||
sms_error = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
sms_failed = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=0)
|
||||||
|
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
UniqueConstraint('service_id', 'day', name='uix_service_to_day'),
|
UniqueConstraint('service_id', 'day', name='uix_service_to_day'),
|
||||||
@@ -234,7 +234,7 @@ class VerifyCode(db.Model):
|
|||||||
return check_hash(cde, self._code)
|
return check_hash(cde, self._code)
|
||||||
|
|
||||||
|
|
||||||
NOTIFICATION_STATUS_TYPES = ['sent', 'delivered', 'failed', 'complaint', 'bounce']
|
NOTIFICATION_STATUS_TYPES = ['sending', 'delivered', 'failed']
|
||||||
|
|
||||||
|
|
||||||
class Notification(db.Model):
|
class Notification(db.Model):
|
||||||
@@ -267,7 +267,7 @@ class Notification(db.Model):
|
|||||||
nullable=True,
|
nullable=True,
|
||||||
onupdate=datetime.datetime.utcnow)
|
onupdate=datetime.datetime.utcnow)
|
||||||
status = db.Column(
|
status = db.Column(
|
||||||
db.Enum(*NOTIFICATION_STATUS_TYPES, name='notification_status_types'), nullable=False, default='sent')
|
db.Enum(*NOTIFICATION_STATUS_TYPES, name='notification_status_types'), nullable=False, default='sending')
|
||||||
reference = db.Column(db.String, nullable=True, index=True)
|
reference = db.Column(db.String, nullable=True, index=True)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -287,8 +287,9 @@ def send_notification(notification_type):
|
|||||||
total_sms_count = service_stats.sms_requested
|
total_sms_count = service_stats.sms_requested
|
||||||
total_email_count = service_stats.emails_requested
|
total_email_count = service_stats.emails_requested
|
||||||
|
|
||||||
if (total_email_count + total_sms_count >= service.limit) and service.restricted:
|
if (total_email_count + total_sms_count >= service.message_limit) and service.restricted:
|
||||||
return jsonify(result="error", message='Exceeded send limits ({}) for today'.format(service.limit)), 429
|
return jsonify(result="error", message='Exceeded send limits ({}) for today'.format(
|
||||||
|
service.message_limit)), 429
|
||||||
|
|
||||||
notification, errors = (
|
notification, errors = (
|
||||||
sms_template_notification_schema if notification_type == 'sms' else email_notification_schema
|
sms_template_notification_schema if notification_type == 'sms' else email_notification_schema
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ def upgrade():
|
|||||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('active', sa.Boolean(), nullable=False),
|
sa.Column('active', sa.Boolean(), nullable=False),
|
||||||
sa.Column('limit', sa.BigInteger(), nullable=False),
|
sa.Column('message_limit', sa.BigInteger(), nullable=False),
|
||||||
sa.Column('restricted', sa.Boolean(), nullable=False),
|
sa.Column('restricted', sa.Boolean(), nullable=False),
|
||||||
sa.Column('email_from', sa.Text(), nullable=False),
|
sa.Column('email_from', sa.Text(), nullable=False),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
@@ -78,10 +78,10 @@ def upgrade():
|
|||||||
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
|
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
sa.Column('emails_requested', sa.BigInteger(), nullable=False),
|
sa.Column('emails_requested', sa.BigInteger(), nullable=False),
|
||||||
sa.Column('emails_delivered', sa.BigInteger(), nullable=False),
|
sa.Column('emails_delivered', sa.BigInteger(), nullable=False),
|
||||||
sa.Column('emails_error', sa.BigInteger(), nullable=False),
|
sa.Column('emails_failed', sa.BigInteger(), nullable=False),
|
||||||
sa.Column('sms_requested', sa.BigInteger(), nullable=False),
|
sa.Column('sms_requested', sa.BigInteger(), nullable=False),
|
||||||
sa.Column('sms_delivered', sa.BigInteger(), nullable=False),
|
sa.Column('sms_delivered', sa.BigInteger(), nullable=False),
|
||||||
sa.Column('sms_error', sa.BigInteger(), nullable=False),
|
sa.Column('sms_failed', sa.BigInteger(), nullable=False),
|
||||||
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
|
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
sa.UniqueConstraint('service_id', 'day', name='uix_service_to_day')
|
sa.UniqueConstraint('service_id', 'day', name='uix_service_to_day')
|
||||||
@@ -175,7 +175,7 @@ def upgrade():
|
|||||||
sa.Column('sent_at', sa.DateTime(), nullable=True),
|
sa.Column('sent_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('sent_by', sa.String(), nullable=True),
|
sa.Column('sent_by', sa.String(), nullable=True),
|
||||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||||
sa.Column('status', sa.Enum('sent', 'delivered', 'failed', 'complaint', 'bounce', name='notification_status_types'), nullable=False),
|
sa.Column('status', sa.Enum('sending', 'delivered', 'failed', name='notification_status_types'), nullable=False),
|
||||||
sa.Column('reference', sa.String(), nullable=True),
|
sa.Column('reference', sa.String(), nullable=True),
|
||||||
sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], ),
|
sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], ),
|
||||||
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
|
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ def test_should_allow_valid_token_with_post_body(notify_api, sample_api_key):
|
|||||||
'email_from': 'new name',
|
'email_from': 'new name',
|
||||||
'name': 'new name',
|
'name': 'new name',
|
||||||
'users': [service.users[0].id],
|
'users': [service.users[0].id],
|
||||||
'limit': 1000,
|
'message_limit': 1000,
|
||||||
'restricted': False,
|
'restricted': False,
|
||||||
'active': False}
|
'active': False}
|
||||||
|
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ def test_should_send_template_to_correct_sms_provider_and_persist(sample_templat
|
|||||||
assert persisted_notification.id == notification_id
|
assert persisted_notification.id == notification_id
|
||||||
assert persisted_notification.to == '+447234123123'
|
assert persisted_notification.to == '+447234123123'
|
||||||
assert persisted_notification.template_id == sample_template_with_placeholders.id
|
assert persisted_notification.template_id == sample_template_with_placeholders.id
|
||||||
assert persisted_notification.status == 'sent'
|
assert persisted_notification.status == 'sending'
|
||||||
assert persisted_notification.created_at == now
|
assert persisted_notification.created_at == now
|
||||||
assert persisted_notification.sent_at > now
|
assert persisted_notification.sent_at > now
|
||||||
assert persisted_notification.sent_by == 'MMG'
|
assert persisted_notification.sent_by == 'MMG'
|
||||||
@@ -481,7 +481,7 @@ def test_should_send_template_to_correct_sms_provider_and_persist_with_job_id(sa
|
|||||||
assert persisted_notification.to == '+447234123123'
|
assert persisted_notification.to == '+447234123123'
|
||||||
assert persisted_notification.job_id == sample_job.id
|
assert persisted_notification.job_id == sample_job.id
|
||||||
assert persisted_notification.template_id == sample_job.template.id
|
assert persisted_notification.template_id == sample_job.template.id
|
||||||
assert persisted_notification.status == 'sent'
|
assert persisted_notification.status == 'sending'
|
||||||
assert persisted_notification.sent_at > now
|
assert persisted_notification.sent_at > now
|
||||||
assert persisted_notification.created_at == now
|
assert persisted_notification.created_at == now
|
||||||
assert persisted_notification.sent_by == 'MMG'
|
assert persisted_notification.sent_by == 'MMG'
|
||||||
@@ -522,7 +522,7 @@ def test_should_use_email_template_and_persist(sample_email_template_with_placeh
|
|||||||
assert persisted_notification.template_id == sample_email_template_with_placeholders.id
|
assert persisted_notification.template_id == sample_email_template_with_placeholders.id
|
||||||
assert persisted_notification.created_at == now
|
assert persisted_notification.created_at == now
|
||||||
assert persisted_notification.sent_at > now
|
assert persisted_notification.sent_at > now
|
||||||
assert persisted_notification.status == 'sent'
|
assert persisted_notification.status == 'sending'
|
||||||
assert persisted_notification.sent_by == 'ses'
|
assert persisted_notification.sent_by == 'ses'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ def test_should_return_correct_details_for_delivery():
|
|||||||
def test_should_return_correct_details_for_bounced():
|
def test_should_return_correct_details_for_bounced():
|
||||||
response_dict = get_aws_responses('Bounce')
|
response_dict = get_aws_responses('Bounce')
|
||||||
assert response_dict['message'] == 'Bounced'
|
assert response_dict['message'] == 'Bounced'
|
||||||
assert response_dict['notification_status'] == 'bounce'
|
assert response_dict['notification_status'] == 'failed'
|
||||||
assert response_dict['notification_statistics_status'] == 'failure'
|
assert response_dict['notification_statistics_status'] == 'failure'
|
||||||
assert not response_dict['success']
|
assert not response_dict['success']
|
||||||
|
|
||||||
@@ -22,9 +22,9 @@ def test_should_return_correct_details_for_bounced():
|
|||||||
def test_should_return_correct_details_for_complaint():
|
def test_should_return_correct_details_for_complaint():
|
||||||
response_dict = get_aws_responses('Complaint')
|
response_dict = get_aws_responses('Complaint')
|
||||||
assert response_dict['message'] == 'Complaint'
|
assert response_dict['message'] == 'Complaint'
|
||||||
assert response_dict['notification_status'] == 'complaint'
|
assert response_dict['notification_status'] == 'delivered'
|
||||||
assert response_dict['notification_statistics_status'] == 'failure'
|
assert response_dict['notification_statistics_status'] == 'delivered'
|
||||||
assert not response_dict['success']
|
assert response_dict['success']
|
||||||
|
|
||||||
|
|
||||||
def test_should_be_none_if_unrecognised_status_code():
|
def test_should_be_none_if_unrecognised_status_code():
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ def test_should_return_correct_details_for_bounced():
|
|||||||
def test_should_return_correct_details_for_complaint():
|
def test_should_return_correct_details_for_complaint():
|
||||||
response_dict = get_firetext_responses('2')
|
response_dict = get_firetext_responses('2')
|
||||||
assert response_dict['message'] == 'Undelivered (Pending with Network)'
|
assert response_dict['message'] == 'Undelivered (Pending with Network)'
|
||||||
assert response_dict['notification_status'] == 'sent'
|
assert response_dict['notification_status'] == 'delivered'
|
||||||
assert not response_dict['notification_statistics_status']
|
assert response_dict['notification_statistics_status'] == 'delivered'
|
||||||
assert not response_dict['success']
|
assert response_dict['success']
|
||||||
|
|
||||||
|
|
||||||
def test_should_be_none_if_unrecognised_status_code():
|
def test_should_be_none_if_unrecognised_status_code():
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ def sample_service(notify_db,
|
|||||||
user = sample_user(notify_db, notify_db_session)
|
user = sample_user(notify_db, notify_db_session)
|
||||||
data = {
|
data = {
|
||||||
'name': service_name,
|
'name': service_name,
|
||||||
'limit': limit,
|
'message_limit': limit,
|
||||||
'active': False,
|
'active': False,
|
||||||
'restricted': restricted,
|
'restricted': restricted,
|
||||||
'email_from': email_from
|
'email_from': email_from
|
||||||
@@ -285,7 +285,7 @@ def sample_notification(notify_db,
|
|||||||
template=None,
|
template=None,
|
||||||
job=None,
|
job=None,
|
||||||
to_field=None,
|
to_field=None,
|
||||||
status='sent',
|
status='sending',
|
||||||
reference=None,
|
reference=None,
|
||||||
created_at=datetime.utcnow()):
|
created_at=datetime.utcnow()):
|
||||||
if service is None:
|
if service is None:
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ def test_should_by_able_to_update_status_by_reference(sample_email_template):
|
|||||||
notification = Notification(**data)
|
notification = Notification(**data)
|
||||||
dao_create_notification(notification, sample_email_template.template_type)
|
dao_create_notification(notification, sample_email_template.template_type)
|
||||||
|
|
||||||
assert Notification.query.get(notification.id).status == "sent"
|
assert Notification.query.get(notification.id).status == "sending"
|
||||||
update_notification_reference_by_id(notification.id, 'reference')
|
update_notification_reference_by_id(notification.id, 'reference')
|
||||||
update_notification_status_by_reference('reference', 'delivered', 'delivered')
|
update_notification_status_by_reference('reference', 'delivered', 'delivered')
|
||||||
assert Notification.query.get(notification.id).status == 'delivered'
|
assert Notification.query.get(notification.id).status == 'delivered'
|
||||||
@@ -68,11 +68,11 @@ def test_should_by_able_to_update_status_by_reference(sample_email_template):
|
|||||||
).one().emails_requested == 1
|
).one().emails_requested == 1
|
||||||
assert NotificationStatistics.query.filter_by(
|
assert NotificationStatistics.query.filter_by(
|
||||||
service_id=sample_email_template.service.id
|
service_id=sample_email_template.service.id
|
||||||
).one().emails_error == 0
|
).one().emails_failed == 0
|
||||||
|
|
||||||
|
|
||||||
def test_should_by_able_to_update_status_by_id(sample_notification):
|
def test_should_by_able_to_update_status_by_id(sample_notification):
|
||||||
assert Notification.query.get(sample_notification.id).status == 'sent'
|
assert Notification.query.get(sample_notification.id).status == 'sending'
|
||||||
count = update_notification_status_by_id(sample_notification.id, 'delivered', 'delivered')
|
count = update_notification_status_by_id(sample_notification.id, 'delivered', 'delivered')
|
||||||
assert count == 1
|
assert count == 1
|
||||||
assert Notification.query.get(sample_notification.id).status == 'delivered'
|
assert Notification.query.get(sample_notification.id).status == 'delivered'
|
||||||
@@ -84,11 +84,11 @@ def test_should_by_able_to_update_status_by_id(sample_notification):
|
|||||||
).one().sms_requested == 1
|
).one().sms_requested == 1
|
||||||
assert NotificationStatistics.query.filter_by(
|
assert NotificationStatistics.query.filter_by(
|
||||||
service_id=sample_notification.service.id
|
service_id=sample_notification.service.id
|
||||||
).one().sms_error == 0
|
).one().sms_failed == 0
|
||||||
|
|
||||||
|
|
||||||
def test_should_be_able_to_record_statistics_failure_for_sms(sample_notification):
|
def test_should_be_able_to_record_statistics_failure_for_sms(sample_notification):
|
||||||
assert Notification.query.get(sample_notification.id).status == 'sent'
|
assert Notification.query.get(sample_notification.id).status == 'sending'
|
||||||
count = update_notification_status_by_id(sample_notification.id, 'delivered', 'failure')
|
count = update_notification_status_by_id(sample_notification.id, 'delivered', 'failure')
|
||||||
assert count == 1
|
assert count == 1
|
||||||
assert Notification.query.get(sample_notification.id).status == 'delivered'
|
assert Notification.query.get(sample_notification.id).status == 'delivered'
|
||||||
@@ -100,7 +100,7 @@ def test_should_be_able_to_record_statistics_failure_for_sms(sample_notification
|
|||||||
).one().sms_requested == 1
|
).one().sms_requested == 1
|
||||||
assert NotificationStatistics.query.filter_by(
|
assert NotificationStatistics.query.filter_by(
|
||||||
service_id=sample_notification.service.id
|
service_id=sample_notification.service.id
|
||||||
).one().sms_error == 1
|
).one().sms_failed == 1
|
||||||
|
|
||||||
|
|
||||||
def test_should_be_able_to_record_statistics_failure_for_email(sample_email_template):
|
def test_should_be_able_to_record_statistics_failure_for_email(sample_email_template):
|
||||||
@@ -117,9 +117,9 @@ def test_should_be_able_to_record_statistics_failure_for_email(sample_email_temp
|
|||||||
dao_create_notification(notification, sample_email_template.template_type)
|
dao_create_notification(notification, sample_email_template.template_type)
|
||||||
|
|
||||||
update_notification_reference_by_id(notification.id, 'reference')
|
update_notification_reference_by_id(notification.id, 'reference')
|
||||||
count = update_notification_status_by_reference('reference', 'bounce', 'failure')
|
count = update_notification_status_by_reference('reference', 'failed', 'failure')
|
||||||
assert count == 1
|
assert count == 1
|
||||||
assert Notification.query.get(notification.id).status == 'bounce'
|
assert Notification.query.get(notification.id).status == 'failed'
|
||||||
assert NotificationStatistics.query.filter_by(
|
assert NotificationStatistics.query.filter_by(
|
||||||
service_id=notification.service.id
|
service_id=notification.service.id
|
||||||
).one().emails_delivered == 0
|
).one().emails_delivered == 0
|
||||||
@@ -128,7 +128,7 @@ def test_should_be_able_to_record_statistics_failure_for_email(sample_email_temp
|
|||||||
).one().emails_requested == 1
|
).one().emails_requested == 1
|
||||||
assert NotificationStatistics.query.filter_by(
|
assert NotificationStatistics.query.filter_by(
|
||||||
service_id=notification.service.id
|
service_id=notification.service.id
|
||||||
).one().emails_error == 1
|
).one().emails_failed == 1
|
||||||
|
|
||||||
|
|
||||||
def test_should_return_zero_count_if_no_notification_with_id():
|
def test_should_return_zero_count_if_no_notification_with_id():
|
||||||
@@ -157,12 +157,12 @@ def test_should_be_able_to_get_statistics_for_a_service(sample_template):
|
|||||||
assert stats[0].emails_requested == 0
|
assert stats[0].emails_requested == 0
|
||||||
assert stats[0].sms_requested == 1
|
assert stats[0].sms_requested == 1
|
||||||
assert stats[0].sms_delivered == 0
|
assert stats[0].sms_delivered == 0
|
||||||
assert stats[0].sms_error == 0
|
assert stats[0].sms_failed == 0
|
||||||
assert stats[0].day == notification.created_at.strftime(DATE_FORMAT)
|
assert stats[0].day == notification.created_at.strftime(DATE_FORMAT)
|
||||||
assert stats[0].service_id == notification.service_id
|
assert stats[0].service_id == notification.service_id
|
||||||
assert stats[0].emails_requested == 0
|
assert stats[0].emails_requested == 0
|
||||||
assert stats[0].emails_delivered == 0
|
assert stats[0].emails_delivered == 0
|
||||||
assert stats[0].emails_error == 0
|
assert stats[0].emails_failed == 0
|
||||||
|
|
||||||
|
|
||||||
def test_should_be_able_to_get_statistics_for_a_service_for_a_day(sample_template):
|
def test_should_be_able_to_get_statistics_for_a_service_for_a_day(sample_template):
|
||||||
@@ -182,10 +182,10 @@ def test_should_be_able_to_get_statistics_for_a_service_for_a_day(sample_templat
|
|||||||
sample_template.service.id, now.strftime(DATE_FORMAT)
|
sample_template.service.id, now.strftime(DATE_FORMAT)
|
||||||
)
|
)
|
||||||
assert stat.emails_requested == 0
|
assert stat.emails_requested == 0
|
||||||
assert stat.emails_error == 0
|
assert stat.emails_failed == 0
|
||||||
assert stat.emails_delivered == 0
|
assert stat.emails_delivered == 0
|
||||||
assert stat.sms_requested == 1
|
assert stat.sms_requested == 1
|
||||||
assert stat.sms_error == 0
|
assert stat.sms_failed == 0
|
||||||
assert stat.sms_delivered == 0
|
assert stat.sms_delivered == 0
|
||||||
assert stat.day == notification.created_at.strftime(DATE_FORMAT)
|
assert stat.day == notification.created_at.strftime(DATE_FORMAT)
|
||||||
assert stat.service_id == notification.service_id
|
assert stat.service_id == notification.service_id
|
||||||
@@ -303,7 +303,7 @@ def test_save_notification_creates_sms_and_template_stats(sample_template, sampl
|
|||||||
assert data['service'] == notification_from_db.service
|
assert data['service'] == notification_from_db.service
|
||||||
assert data['template'] == notification_from_db.template
|
assert data['template'] == notification_from_db.template
|
||||||
assert data['created_at'] == notification_from_db.created_at
|
assert data['created_at'] == notification_from_db.created_at
|
||||||
assert 'sent' == notification_from_db.status
|
assert 'sending' == notification_from_db.status
|
||||||
assert Job.query.get(sample_job.id).notifications_sent == 1
|
assert Job.query.get(sample_job.id).notifications_sent == 1
|
||||||
|
|
||||||
stats = NotificationStatistics.query.filter(
|
stats = NotificationStatistics.query.filter(
|
||||||
@@ -348,7 +348,7 @@ def test_save_notification_and_create_email_and_template_stats(sample_email_temp
|
|||||||
assert data['service'] == notification_from_db.service
|
assert data['service'] == notification_from_db.service
|
||||||
assert data['template'] == notification_from_db.template
|
assert data['template'] == notification_from_db.template
|
||||||
assert data['created_at'] == notification_from_db.created_at
|
assert data['created_at'] == notification_from_db.created_at
|
||||||
assert 'sent' == notification_from_db.status
|
assert 'sending' == notification_from_db.status
|
||||||
assert Job.query.get(sample_job.id).notifications_sent == 1
|
assert Job.query.get(sample_job.id).notifications_sent == 1
|
||||||
|
|
||||||
stats = NotificationStatistics.query.filter(
|
stats = NotificationStatistics.query.filter(
|
||||||
@@ -537,7 +537,7 @@ def test_save_notification_and_increment_job(sample_template, sample_job):
|
|||||||
assert data['service'] == notification_from_db.service
|
assert data['service'] == notification_from_db.service
|
||||||
assert data['template'] == notification_from_db.template
|
assert data['template'] == notification_from_db.template
|
||||||
assert data['created_at'] == notification_from_db.created_at
|
assert data['created_at'] == notification_from_db.created_at
|
||||||
assert 'sent' == notification_from_db.status
|
assert 'sending' == notification_from_db.status
|
||||||
assert Job.query.get(sample_job.id).notifications_sent == 1
|
assert Job.query.get(sample_job.id).notifications_sent == 1
|
||||||
|
|
||||||
notification_2 = Notification(**data)
|
notification_2 = Notification(**data)
|
||||||
@@ -603,7 +603,7 @@ def test_save_notification_and_increment_correct_job(notify_db, notify_db_sessio
|
|||||||
assert data['service'] == notification_from_db.service
|
assert data['service'] == notification_from_db.service
|
||||||
assert data['template'] == notification_from_db.template
|
assert data['template'] == notification_from_db.template
|
||||||
assert data['created_at'] == notification_from_db.created_at
|
assert data['created_at'] == notification_from_db.created_at
|
||||||
assert 'sent' == notification_from_db.status
|
assert 'sending' == notification_from_db.status
|
||||||
assert Job.query.get(job_1.id).notifications_sent == 1
|
assert Job.query.get(job_1.id).notifications_sent == 1
|
||||||
assert Job.query.get(job_2.id).notifications_sent == 0
|
assert Job.query.get(job_2.id).notifications_sent == 0
|
||||||
|
|
||||||
@@ -629,7 +629,7 @@ def test_save_notification_with_no_job(sample_template):
|
|||||||
assert data['service'] == notification_from_db.service
|
assert data['service'] == notification_from_db.service
|
||||||
assert data['template'] == notification_from_db.template
|
assert data['template'] == notification_from_db.template
|
||||||
assert data['created_at'] == notification_from_db.created_at
|
assert data['created_at'] == notification_from_db.created_at
|
||||||
assert 'sent' == notification_from_db.status
|
assert 'sending' == notification_from_db.status
|
||||||
|
|
||||||
|
|
||||||
def test_get_notification(sample_notification):
|
def test_get_notification(sample_notification):
|
||||||
@@ -660,7 +660,7 @@ def test_save_notification_no_job_id(sample_template):
|
|||||||
assert data['to'] == notification_from_db.to
|
assert data['to'] == notification_from_db.to
|
||||||
assert data['service'] == notification_from_db.service
|
assert data['service'] == notification_from_db.service
|
||||||
assert data['template'] == notification_from_db.template
|
assert data['template'] == notification_from_db.template
|
||||||
assert 'sent' == notification_from_db.status
|
assert 'sending' == notification_from_db.status
|
||||||
|
|
||||||
|
|
||||||
def test_get_notification_for_job(sample_notification):
|
def test_get_notification_for_job(sample_notification):
|
||||||
@@ -694,7 +694,7 @@ def test_get_all_notifications_for_job(notify_db, notify_db_session, sample_job)
|
|||||||
|
|
||||||
|
|
||||||
def test_update_notification(sample_notification, sample_template):
|
def test_update_notification(sample_notification, sample_template):
|
||||||
assert sample_notification.status == 'sent'
|
assert sample_notification.status == 'sending'
|
||||||
sample_notification.status = 'failed'
|
sample_notification.status = 'failed'
|
||||||
dao_update_notification(sample_notification)
|
dao_update_notification(sample_notification)
|
||||||
notification_from_db = Notification.query.get(sample_notification.id)
|
notification_from_db = Notification.query.get(sample_notification.id)
|
||||||
@@ -706,7 +706,7 @@ def test_should_delete_notifications_after_one_day(notify_db, notify_db_session)
|
|||||||
sample_notification(notify_db, notify_db_session, created_at=created_at)
|
sample_notification(notify_db, notify_db_session, created_at=created_at)
|
||||||
sample_notification(notify_db, notify_db_session, created_at=created_at)
|
sample_notification(notify_db, notify_db_session, created_at=created_at)
|
||||||
assert len(Notification.query.all()) == 2
|
assert len(Notification.query.all()) == 2
|
||||||
delete_notifications_created_more_than_a_day_ago('sent')
|
delete_notifications_created_more_than_a_day_ago('sending')
|
||||||
assert len(Notification.query.all()) == 0
|
assert len(Notification.query.all()) == 0
|
||||||
|
|
||||||
|
|
||||||
@@ -726,7 +726,7 @@ def test_should_not_delete_sent_notifications_before_one_day(notify_db, notify_d
|
|||||||
sample_notification(notify_db, notify_db_session, created_at=valid, to_field="valid")
|
sample_notification(notify_db, notify_db_session, created_at=valid, to_field="valid")
|
||||||
|
|
||||||
assert len(Notification.query.all()) == 2
|
assert len(Notification.query.all()) == 2
|
||||||
delete_notifications_created_more_than_a_day_ago('sent')
|
delete_notifications_created_more_than_a_day_ago('sending')
|
||||||
assert len(Notification.query.all()) == 1
|
assert len(Notification.query.all()) == 1
|
||||||
assert Notification.query.first().to == 'valid'
|
assert Notification.query.first().to == 'valid'
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ from sqlalchemy.exc import IntegrityError
|
|||||||
|
|
||||||
def test_create_service(sample_user):
|
def test_create_service(sample_user):
|
||||||
assert Service.query.count() == 0
|
assert Service.query.count() == 0
|
||||||
service = Service(name="service_name", email_from="email_from", limit=1000, active=True, restricted=False)
|
service = Service(name="service_name", email_from="email_from", message_limit=1000, active=True, restricted=False)
|
||||||
dao_create_service(service, sample_user)
|
dao_create_service(service, sample_user)
|
||||||
assert Service.query.count() == 1
|
assert Service.query.count() == 1
|
||||||
assert Service.query.first().name == "service_name"
|
assert Service.query.first().name == "service_name"
|
||||||
@@ -27,8 +27,8 @@ def test_create_service(sample_user):
|
|||||||
|
|
||||||
def test_cannot_create_two_services_with_same_name(sample_user):
|
def test_cannot_create_two_services_with_same_name(sample_user):
|
||||||
assert Service.query.count() == 0
|
assert Service.query.count() == 0
|
||||||
service1 = Service(name="service_name", email_from="email_from1", limit=1000, active=True, restricted=False)
|
service1 = Service(name="service_name", email_from="email_from1", message_limit=1000, active=True, restricted=False)
|
||||||
service2 = Service(name="service_name", email_from="email_from2", limit=1000, active=True, restricted=False)
|
service2 = Service(name="service_name", email_from="email_from2", message_limit=1000, active=True, restricted=False)
|
||||||
with pytest.raises(IntegrityError) as excinfo:
|
with pytest.raises(IntegrityError) as excinfo:
|
||||||
dao_create_service(service1, sample_user)
|
dao_create_service(service1, sample_user)
|
||||||
dao_create_service(service2, sample_user)
|
dao_create_service(service2, sample_user)
|
||||||
@@ -37,8 +37,8 @@ def test_cannot_create_two_services_with_same_name(sample_user):
|
|||||||
|
|
||||||
def test_cannot_create_two_services_with_same_email_from(sample_user):
|
def test_cannot_create_two_services_with_same_email_from(sample_user):
|
||||||
assert Service.query.count() == 0
|
assert Service.query.count() == 0
|
||||||
service1 = Service(name="service_name1", email_from="email_from", limit=1000, active=True, restricted=False)
|
service1 = Service(name="service_name1", email_from="email_from", message_limit=1000, active=True, restricted=False)
|
||||||
service2 = Service(name="service_name2", email_from="email_from", limit=1000, active=True, restricted=False)
|
service2 = Service(name="service_name2", email_from="email_from", message_limit=1000, active=True, restricted=False)
|
||||||
with pytest.raises(IntegrityError) as excinfo:
|
with pytest.raises(IntegrityError) as excinfo:
|
||||||
dao_create_service(service1, sample_user)
|
dao_create_service(service1, sample_user)
|
||||||
dao_create_service(service2, sample_user)
|
dao_create_service(service2, sample_user)
|
||||||
@@ -47,14 +47,14 @@ def test_cannot_create_two_services_with_same_email_from(sample_user):
|
|||||||
|
|
||||||
def test_cannot_create_service_with_no_user(notify_db_session):
|
def test_cannot_create_service_with_no_user(notify_db_session):
|
||||||
assert Service.query.count() == 0
|
assert Service.query.count() == 0
|
||||||
service = Service(name="service_name", email_from="email_from", limit=1000, active=True, restricted=False)
|
service = Service(name="service_name", email_from="email_from", message_limit=1000, active=True, restricted=False)
|
||||||
with pytest.raises(FlushError) as excinfo:
|
with pytest.raises(FlushError) as excinfo:
|
||||||
dao_create_service(service, None)
|
dao_create_service(service, None)
|
||||||
assert "Can't flush None value found in collection Service.users" in str(excinfo.value)
|
assert "Can't flush None value found in collection Service.users" in str(excinfo.value)
|
||||||
|
|
||||||
|
|
||||||
def test_should_add_user_to_service(sample_user):
|
def test_should_add_user_to_service(sample_user):
|
||||||
service = Service(name="service_name", email_from="email_from", limit=1000, active=True, restricted=False)
|
service = Service(name="service_name", email_from="email_from", message_limit=1000, active=True, restricted=False)
|
||||||
dao_create_service(service, sample_user)
|
dao_create_service(service, sample_user)
|
||||||
assert sample_user in Service.query.first().users
|
assert sample_user in Service.query.first().users
|
||||||
new_user = User(
|
new_user = User(
|
||||||
@@ -69,7 +69,7 @@ def test_should_add_user_to_service(sample_user):
|
|||||||
|
|
||||||
|
|
||||||
def test_should_remove_user_from_service(sample_user):
|
def test_should_remove_user_from_service(sample_user):
|
||||||
service = Service(name="service_name", email_from="email_from", limit=1000, active=True, restricted=False)
|
service = Service(name="service_name", email_from="email_from", message_limit=1000, active=True, restricted=False)
|
||||||
dao_create_service(service, sample_user)
|
dao_create_service(service, sample_user)
|
||||||
new_user = User(
|
new_user = User(
|
||||||
name='Test User',
|
name='Test User',
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ def test_process_sms_response_updates_notification_stats_for_valid_request(notif
|
|||||||
assert len(stats) == 1
|
assert len(stats) == 1
|
||||||
assert stats[0].sms_requested == 1
|
assert stats[0].sms_requested == 1
|
||||||
assert stats[0].sms_delivered == 0
|
assert stats[0].sms_delivered == 0
|
||||||
assert stats[0].sms_error == 0
|
assert stats[0].sms_failed == 0
|
||||||
success, error = process_sms_client_response(status='0', reference=str(sample_notification.id),
|
success, error = process_sms_client_response(status='0', reference=str(sample_notification.id),
|
||||||
client_name='Firetext')
|
client_name='Firetext')
|
||||||
assert error is None
|
assert error is None
|
||||||
@@ -67,7 +67,7 @@ def test_process_sms_response_updates_notification_stats_for_valid_request(notif
|
|||||||
assert len(stats) == 1
|
assert len(stats) == 1
|
||||||
assert stats[0].sms_requested == 1
|
assert stats[0].sms_requested == 1
|
||||||
assert stats[0].sms_delivered == 1
|
assert stats[0].sms_delivered == 1
|
||||||
assert stats[0].sms_error == 0
|
assert stats[0].sms_failed == 0
|
||||||
|
|
||||||
|
|
||||||
def test_process_sms_response_updates_notification_stats_for_valid_request_with_failed_status(notify_api,
|
def test_process_sms_response_updates_notification_stats_for_valid_request_with_failed_status(notify_api,
|
||||||
@@ -79,7 +79,7 @@ def test_process_sms_response_updates_notification_stats_for_valid_request_with_
|
|||||||
assert len(stats) == 1
|
assert len(stats) == 1
|
||||||
assert stats[0].sms_requested == 1
|
assert stats[0].sms_requested == 1
|
||||||
assert stats[0].sms_delivered == 0
|
assert stats[0].sms_delivered == 0
|
||||||
assert stats[0].sms_error == 0
|
assert stats[0].sms_failed == 0
|
||||||
success, error = process_sms_client_response(status='1', reference=str(sample_notification.id),
|
success, error = process_sms_client_response(status='1', reference=str(sample_notification.id),
|
||||||
client_name='Firetext')
|
client_name='Firetext')
|
||||||
assert success == "{} callback succeeded. reference {} updated".format('Firetext', sample_notification.id)
|
assert success == "{} callback succeeded. reference {} updated".format('Firetext', sample_notification.id)
|
||||||
@@ -88,4 +88,4 @@ def test_process_sms_response_updates_notification_stats_for_valid_request_with_
|
|||||||
assert len(stats) == 1
|
assert len(stats) == 1
|
||||||
assert stats[0].sms_requested == 1
|
assert stats[0].sms_requested == 1
|
||||||
assert stats[0].sms_delivered == 0
|
assert stats[0].sms_delivered == 0
|
||||||
assert stats[0].sms_error == 1
|
assert stats[0].sms_failed == 1
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ def test_get_notification_by_id(notify_api, sample_notification):
|
|||||||
headers=[auth_header])
|
headers=[auth_header])
|
||||||
|
|
||||||
notification = json.loads(response.get_data(as_text=True))['data']['notification']
|
notification = json.loads(response.get_data(as_text=True))['data']['notification']
|
||||||
assert notification['status'] == 'sent'
|
assert notification['status'] == 'sending'
|
||||||
assert notification['template'] == {
|
assert notification['template'] == {
|
||||||
'id': str(sample_notification.template.id),
|
'id': str(sample_notification.template.id),
|
||||||
'name': sample_notification.template.name,
|
'name': sample_notification.template.name,
|
||||||
@@ -74,7 +74,7 @@ def test_get_all_notifications(notify_api, sample_notification):
|
|||||||
headers=[auth_header])
|
headers=[auth_header])
|
||||||
|
|
||||||
notifications = json.loads(response.get_data(as_text=True))
|
notifications = json.loads(response.get_data(as_text=True))
|
||||||
assert notifications['notifications'][0]['status'] == 'sent'
|
assert notifications['notifications'][0]['status'] == 'sending'
|
||||||
assert notifications['notifications'][0]['template'] == {
|
assert notifications['notifications'][0]['template'] == {
|
||||||
'id': str(sample_notification.template.id),
|
'id': str(sample_notification.template.id),
|
||||||
'name': sample_notification.template.name,
|
'name': sample_notification.template.name,
|
||||||
@@ -400,13 +400,13 @@ def test_filter_by_multiple_statuss(notify_api,
|
|||||||
method='GET')
|
method='GET')
|
||||||
|
|
||||||
response = client.get(
|
response = client.get(
|
||||||
'/notifications?status=delivered&status=sent',
|
'/notifications?status=delivered&status=sending',
|
||||||
headers=[auth_header])
|
headers=[auth_header])
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
notifications = json.loads(response.get_data(as_text=True))
|
notifications = json.loads(response.get_data(as_text=True))
|
||||||
assert len(notifications['notifications']) == 2
|
assert len(notifications['notifications']) == 2
|
||||||
set(['delivered', 'sent']) == set(
|
set(['delivered', 'sending']) == set(
|
||||||
[x['status'] for x in notifications['notifications']])
|
[x['status'] for x in notifications['notifications']])
|
||||||
|
|
||||||
|
|
||||||
@@ -1001,7 +1001,7 @@ def test_no_limit_for_live_service(notify_api,
|
|||||||
with notify_api.test_request_context():
|
with notify_api.test_request_context():
|
||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
|
|
||||||
sample_service.limit = 1
|
sample_service.message_limit = 1
|
||||||
notify_db.session.add(sample_service)
|
notify_db.session.add(sample_service)
|
||||||
notify_db.session.commit()
|
notify_db.session.commit()
|
||||||
|
|
||||||
@@ -1211,7 +1211,7 @@ def test_firetext_callback_should_update_notification_status(notify_api, sample_
|
|||||||
with notify_api.test_request_context():
|
with notify_api.test_request_context():
|
||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
original = get_notification_by_id(sample_notification.id)
|
original = get_notification_by_id(sample_notification.id)
|
||||||
assert original.status == 'sent'
|
assert original.status == 'sending'
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path='/notifications/sms/firetext',
|
path='/notifications/sms/firetext',
|
||||||
@@ -1231,14 +1231,14 @@ def test_firetext_callback_should_update_notification_status(notify_api, sample_
|
|||||||
assert get_notification_by_id(sample_notification.id).status == 'delivered'
|
assert get_notification_by_id(sample_notification.id).status == 'delivered'
|
||||||
assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_delivered == 1
|
assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_delivered == 1
|
||||||
assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_requested == 1
|
assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_requested == 1
|
||||||
assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_error == 0
|
assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_failed == 0
|
||||||
|
|
||||||
|
|
||||||
def test_firetext_callback_should_update_notification_status_failed(notify_api, sample_notification):
|
def test_firetext_callback_should_update_notification_status_failed(notify_api, sample_notification):
|
||||||
with notify_api.test_request_context():
|
with notify_api.test_request_context():
|
||||||
with notify_api.test_client() as client:
|
with notify_api.test_client() as client:
|
||||||
original = get_notification_by_id(sample_notification.id)
|
original = get_notification_by_id(sample_notification.id)
|
||||||
assert original.status == 'sent'
|
assert original.status == 'sending'
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path='/notifications/sms/firetext',
|
path='/notifications/sms/firetext',
|
||||||
@@ -1257,7 +1257,7 @@ def test_firetext_callback_should_update_notification_status_failed(notify_api,
|
|||||||
assert updated.status == 'failed'
|
assert updated.status == 'failed'
|
||||||
assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_delivered == 0
|
assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_delivered == 0
|
||||||
assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_requested == 1
|
assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_requested == 1
|
||||||
assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_error == 1
|
assert dao_get_notification_statistics_for_service(sample_notification.service_id)[0].sms_failed == 1
|
||||||
|
|
||||||
|
|
||||||
def test_firetext_callback_should_update_notification_status_sent(notify_api, notify_db, notify_db_session):
|
def test_firetext_callback_should_update_notification_status_sent(notify_api, notify_db, notify_db_session):
|
||||||
@@ -1275,16 +1275,17 @@ def test_firetext_callback_should_update_notification_status_sent(notify_api, no
|
|||||||
headers=[('Content-Type', 'application/x-www-form-urlencoded')])
|
headers=[('Content-Type', 'application/x-www-form-urlencoded')])
|
||||||
|
|
||||||
json_resp = json.loads(response.get_data(as_text=True))
|
json_resp = json.loads(response.get_data(as_text=True))
|
||||||
|
print(json_resp)
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert json_resp['result'] == 'success'
|
assert json_resp['result'] == 'success'
|
||||||
assert json_resp['message'] == 'Firetext callback succeeded. reference {} updated'.format(
|
assert json_resp['message'] == 'Firetext callback succeeded. reference {} updated'.format(
|
||||||
notification.id
|
notification.id
|
||||||
)
|
)
|
||||||
updated = get_notification_by_id(notification.id)
|
updated = get_notification_by_id(notification.id)
|
||||||
assert updated.status == 'sent'
|
assert updated.status == 'delivered'
|
||||||
assert dao_get_notification_statistics_for_service(notification.service_id)[0].sms_delivered == 0
|
assert dao_get_notification_statistics_for_service(notification.service_id)[0].sms_delivered == 1
|
||||||
assert dao_get_notification_statistics_for_service(notification.service_id)[0].sms_requested == 1
|
assert dao_get_notification_statistics_for_service(notification.service_id)[0].sms_requested == 1
|
||||||
assert dao_get_notification_statistics_for_service(notification.service_id)[0].sms_error == 0
|
assert dao_get_notification_statistics_for_service(notification.service_id)[0].sms_failed == 0
|
||||||
|
|
||||||
|
|
||||||
def test_firetext_callback_should_update_multiple_notification_status_sent(notify_api, notify_db, notify_db_session):
|
def test_firetext_callback_should_update_multiple_notification_status_sent(notify_api, notify_db, notify_db_session):
|
||||||
@@ -1317,7 +1318,7 @@ def test_firetext_callback_should_update_multiple_notification_status_sent(notif
|
|||||||
|
|
||||||
assert dao_get_notification_statistics_for_service(notification1.service_id)[0].sms_delivered == 3
|
assert dao_get_notification_statistics_for_service(notification1.service_id)[0].sms_delivered == 3
|
||||||
assert dao_get_notification_statistics_for_service(notification1.service_id)[0].sms_requested == 3
|
assert dao_get_notification_statistics_for_service(notification1.service_id)[0].sms_requested == 3
|
||||||
assert dao_get_notification_statistics_for_service(notification1.service_id)[0].sms_error == 0
|
assert dao_get_notification_statistics_for_service(notification1.service_id)[0].sms_failed == 0
|
||||||
|
|
||||||
|
|
||||||
def test_process_mmg_response_return_200_when_cid_is_send_sms_code(notify_api):
|
def test_process_mmg_response_return_200_when_cid_is_send_sms_code(notify_api):
|
||||||
@@ -1458,7 +1459,7 @@ def test_ses_callback_should_update_notification_status(
|
|||||||
reference='ref'
|
reference='ref'
|
||||||
)
|
)
|
||||||
|
|
||||||
assert get_notification_by_id(notification.id).status == 'sent'
|
assert get_notification_by_id(notification.id).status == 'sending'
|
||||||
|
|
||||||
response = client.post(
|
response = client.post(
|
||||||
path='/notifications/email/ses',
|
path='/notifications/email/ses',
|
||||||
@@ -1472,7 +1473,7 @@ def test_ses_callback_should_update_notification_status(
|
|||||||
assert get_notification_by_id(notification.id).status == 'delivered'
|
assert get_notification_by_id(notification.id).status == 'delivered'
|
||||||
assert dao_get_notification_statistics_for_service(notification.service_id)[0].emails_delivered == 1
|
assert dao_get_notification_statistics_for_service(notification.service_id)[0].emails_delivered == 1
|
||||||
assert dao_get_notification_statistics_for_service(notification.service_id)[0].emails_requested == 1
|
assert dao_get_notification_statistics_for_service(notification.service_id)[0].emails_requested == 1
|
||||||
assert dao_get_notification_statistics_for_service(notification.service_id)[0].emails_error == 0
|
assert dao_get_notification_statistics_for_service(notification.service_id)[0].emails_failed == 0
|
||||||
|
|
||||||
|
|
||||||
def test_ses_callback_should_update_multiple_notification_status_sent(
|
def test_ses_callback_should_update_multiple_notification_status_sent(
|
||||||
@@ -1527,7 +1528,7 @@ def test_ses_callback_should_update_multiple_notification_status_sent(
|
|||||||
|
|
||||||
assert dao_get_notification_statistics_for_service(notification1.service_id)[0].emails_delivered == 3
|
assert dao_get_notification_statistics_for_service(notification1.service_id)[0].emails_delivered == 3
|
||||||
assert dao_get_notification_statistics_for_service(notification1.service_id)[0].emails_requested == 3
|
assert dao_get_notification_statistics_for_service(notification1.service_id)[0].emails_requested == 3
|
||||||
assert dao_get_notification_statistics_for_service(notification1.service_id)[0].emails_error == 0
|
assert dao_get_notification_statistics_for_service(notification1.service_id)[0].emails_failed == 0
|
||||||
|
|
||||||
|
|
||||||
def test_should_handle_invite_email_callbacks(notify_api, notify_db, notify_db_session):
|
def test_should_handle_invite_email_callbacks(notify_api, notify_db, notify_db_session):
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ def test_create_service(notify_api, sample_user):
|
|||||||
data = {
|
data = {
|
||||||
'name': 'created service',
|
'name': 'created service',
|
||||||
'user_id': str(sample_user.id),
|
'user_id': str(sample_user.id),
|
||||||
'limit': 1000,
|
'message_limit': 1000,
|
||||||
'restricted': False,
|
'restricted': False,
|
||||||
'active': False,
|
'active': False,
|
||||||
'email_from': 'created.service'}
|
'email_from': 'created.service'}
|
||||||
@@ -218,7 +218,7 @@ def test_should_not_create_service_with_missing_user_id_field(notify_api):
|
|||||||
data = {
|
data = {
|
||||||
'email_from': 'service',
|
'email_from': 'service',
|
||||||
'name': 'created service',
|
'name': 'created service',
|
||||||
'limit': 1000,
|
'message_limit': 1000,
|
||||||
'restricted': False,
|
'restricted': False,
|
||||||
'active': False
|
'active': False
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ def test_should_not_create_service_with_missing_if_user_id_is_not_in_database(no
|
|||||||
'email_from': 'service',
|
'email_from': 'service',
|
||||||
'user_id': fake_uuid,
|
'user_id': fake_uuid,
|
||||||
'name': 'created service',
|
'name': 'created service',
|
||||||
'limit': 1000,
|
'message_limit': 1000,
|
||||||
'restricted': False,
|
'restricted': False,
|
||||||
'active': False
|
'active': False
|
||||||
}
|
}
|
||||||
@@ -289,7 +289,7 @@ def test_should_not_create_service_if_missing_data(notify_api, sample_user):
|
|||||||
assert json_resp['result'] == 'error'
|
assert json_resp['result'] == 'error'
|
||||||
assert 'Missing data for required field.' in json_resp['message']['name']
|
assert 'Missing data for required field.' in json_resp['message']['name']
|
||||||
assert 'Missing data for required field.' in json_resp['message']['active']
|
assert 'Missing data for required field.' in json_resp['message']['active']
|
||||||
assert 'Missing data for required field.' in json_resp['message']['limit']
|
assert 'Missing data for required field.' in json_resp['message']['message_limit']
|
||||||
assert 'Missing data for required field.' in json_resp['message']['restricted']
|
assert 'Missing data for required field.' in json_resp['message']['restricted']
|
||||||
|
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ def test_should_not_create_service_with_duplicate_name(notify_api,
|
|||||||
data = {
|
data = {
|
||||||
'name': sample_service.name,
|
'name': sample_service.name,
|
||||||
'user_id': str(sample_service.users[0].id),
|
'user_id': str(sample_service.users[0].id),
|
||||||
'limit': 1000,
|
'message_limit': 1000,
|
||||||
'restricted': False,
|
'restricted': False,
|
||||||
'active': False,
|
'active': False,
|
||||||
'email_from': 'sample.service2'}
|
'email_from': 'sample.service2'}
|
||||||
@@ -331,7 +331,7 @@ def test_create_service_should_throw_duplicate_key_constraint_for_existing_email
|
|||||||
data = {
|
data = {
|
||||||
'name': 'First SERVICE',
|
'name': 'First SERVICE',
|
||||||
'user_id': str(first_service.users[0].id),
|
'user_id': str(first_service.users[0].id),
|
||||||
'limit': 1000,
|
'message_limit': 1000,
|
||||||
'restricted': False,
|
'restricted': False,
|
||||||
'active': False,
|
'active': False,
|
||||||
'email_from': 'first.service'}
|
'email_from': 'first.service'}
|
||||||
@@ -547,7 +547,7 @@ def test_default_permissions_are_added_for_user_service(notify_api,
|
|||||||
data = {
|
data = {
|
||||||
'name': 'created service',
|
'name': 'created service',
|
||||||
'user_id': str(sample_user.id),
|
'user_id': str(sample_user.id),
|
||||||
'limit': 1000,
|
'message_limit': 1000,
|
||||||
'restricted': False,
|
'restricted': False,
|
||||||
'active': False,
|
'active': False,
|
||||||
'email_from': 'created.service'}
|
'email_from': 'created.service'}
|
||||||
|
|||||||
@@ -27,28 +27,23 @@ def notify_api(request):
|
|||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def notify_db(notify_api, request):
|
def notify_db(notify_api, request):
|
||||||
try:
|
Migrate(notify_api, db)
|
||||||
Migrate(notify_api, db)
|
Manager(db, MigrateCommand)
|
||||||
Manager(db, MigrateCommand)
|
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
ALEMBIC_CONFIG = os.path.join(BASE_DIR, 'migrations')
|
||||||
ALEMBIC_CONFIG = os.path.join(BASE_DIR, 'migrations')
|
config = Config(ALEMBIC_CONFIG + '/alembic.ini')
|
||||||
config = Config(ALEMBIC_CONFIG + '/alembic.ini')
|
config.set_main_option("script_location", ALEMBIC_CONFIG)
|
||||||
config.set_main_option("script_location", ALEMBIC_CONFIG)
|
|
||||||
|
|
||||||
with notify_api.app_context():
|
with notify_api.app_context():
|
||||||
upgrade(config, 'head')
|
upgrade(config, 'head')
|
||||||
|
|
||||||
def teardown():
|
def teardown():
|
||||||
db.session.remove()
|
db.session.remove()
|
||||||
db.engine.execute("drop sequence services_id_seq cascade")
|
db.drop_all()
|
||||||
db.drop_all()
|
db.engine.execute("drop table alembic_version")
|
||||||
db.engine.execute("drop table alembic_version")
|
db.get_engine(notify_api).dispose()
|
||||||
db.get_engine(notify_api).dispose()
|
|
||||||
|
|
||||||
request.addfinalizer(teardown)
|
request.addfinalizer(teardown)
|
||||||
except:
|
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
|
||||||
return db
|
return db
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user