# Path: app/connectors/access_queue.py
# def send_messages_to_queue(type, notifications):
#     q = get_queue_for_type(type)
#     for notification in notifications:
#         q.send_message(MessageBody=json.dumps(notification.serialize()),
#                        MessageAttributes={'type': {'StringValue': type, 'DataType': 'String'}})
#     return True
# 
# def get_messages_from_queue(type):
#     q = get_queue_for_type(type)
#     return q.receive_messages(MessageAttributeNames=['type'], MaxNumberOfMessages=10)
# 
# Path: app/models.py
# class Notification(db.Model):
#     __tablename__ = 'notifications'
# 
#     id = db.Column(db.Integer, primary_key=True)
# 
#     job_id = db.Column(db.BigInteger, db.ForeignKey('jobs.id'), index=True, unique=False)
#     job = db.relationship('Job', backref=db.backref('notifications', lazy='dynamic'))
# 
#     to = db.Column(db.String(255), nullable=False)
#     message = db.Column(db.String(255), nullable=False)
#     created_at = db.Column(db.DateTime, index=False, unique=False, nullable=False)
#     sent_at = db.Column(db.DateTime, index=False, unique=False, nullable=True)
#     delivered_at = db.Column(db.DateTime, index=False, unique=False, nullable=True)
#     status = db.Column(db.String(255), nullable=False)
#     method = db.Column(db.String(255), nullable=False)
#     sender_id = db.Column(db.String(255), index=True, nullable=True)
#     sender = db.Column(db.String(255), index=True, nullable=True)
# 
#     def serialize(self):
#         serialized = {
#             'id': self.id,
#             'to': self.to,
#             'message': self.message,
#             'createdAt': none_or_formatted_date(self.created_at),
#             'sentAt': none_or_formatted_date(self.sent_at),
#             'deliveredAt': none_or_formatted_date(self.delivered_at),
#             'status': self.status,
#             'method': self.method,
#             'jobId': self.job_id,
#             'sender': self.sender
#         }
# 
#         return filter_null_value_fields(serialized)
# 
# class Job(db.Model):
#     __tablename__ = 'jobs'
# 
#     id = db.Column(db.Integer, primary_key=True)
#     name = db.Column(db.String(255), nullable=False)
#     filename = db.Column(db.String(255), nullable=True)
# 
#     created_at = db.Column(db.DateTime, index=False, unique=False, nullable=False)
# 
#     service_id = db.Column(db.BigInteger, db.ForeignKey('services.id'), index=True, unique=False)
#     service = db.relationship('Service', backref=db.backref('jobs', lazy='dynamic'))
# 
#     def serialize(self):
#         serialized = {
#             'id': self.id,
#             'name': self.name,
#             'filename': self.filename,
#             'createdAt': self.created_at.strftime(DATETIME_FORMAT),
#             'serviceId': self.service_id
#         }
# 
#         return filter_null_value_fields(serialized)


from datetime import datetime
from flask import json
from app.connectors.access_queue import send_messages_to_queue, get_messages_from_queue
from app.models import Notification, Job
import moto
import boto3




notification = Notification(to='mock@example.com',
                            message='notification message',
                            status='created',
                            method='email',
                            created_at=datetime.utcnow(),
                            job=Job(id=1234, name='jobname',
                                    filename='filename',
                                    created_at=datetime.utcnow(), service_id=1234))


@moto.mock_sqs
def test_send_messages_to_queue_adds_message_queue(notify_api):
    q = set_up_mock_queue('email')
    q.send_message(MessageBody=json.dumps(notification.serialize()),
                   MessageAttributes={'type': {'StringValue': 'email', 'DataType': 'String'}})

    messages = [notification]
    b = send_messages_to_queue('email', messages)
    assert b is True


@moto.mock_sqs
def test_send_sms_messages_to_queue_adds_message_queue(notify_api):
    q = set_up_mock_queue('sms')

# Path: app/connectors/access_queue.py
# def send_messages_to_queue(type, notifications):
#     q = get_queue_for_type(type)
#     for notification in notifications:
#         q.send_message(MessageBody=json.dumps(notification.serialize()),
#                        MessageAttributes={'type': {'StringValue': type, 'DataType': 'String'}})
#     return True
# 
# def get_messages_from_queue(type):
#     q = get_queue_for_type(type)
#     return q.receive_messages(MessageAttributeNames=['type'], MaxNumberOfMessages=10)
# 
# Path: app/models.py
# class Notification(db.Model):
#     __tablename__ = 'notifications'
# 
#     id = db.Column(db.Integer, primary_key=True)
# 
#     job_id = db.Column(db.BigInteger, db.ForeignKey('jobs.id'), index=True, unique=False)
#     job = db.relationship('Job', backref=db.backref('notifications', lazy='dynamic'))
# 
#     to = db.Column(db.String(255), nullable=False)
#     message = db.Column(db.String(255), nullable=False)
#     created_at = db.Column(db.DateTime, index=False, unique=False, nullable=False)
#     sent_at = db.Column(db.DateTime, index=False, unique=False, nullable=True)
#     delivered_at = db.Column(db.DateTime, index=False, unique=False, nullable=True)
#     status = db.Column(db.String(255), nullable=False)
#     method = db.Column(db.String(255), nullable=False)
#     sender_id = db.Column(db.String(255), index=True, nullable=True)
#     sender = db.Column(db.String(255), index=True, nullable=True)
# 
#     def serialize(self):
#         serialized = {
#             'id': self.id,
#             'to': self.to,
#             'message': self.message,
#             'createdAt': none_or_formatted_date(self.created_at),
#             'sentAt': none_or_formatted_date(self.sent_at),
#             'deliveredAt': none_or_formatted_date(self.delivered_at),
#             'status': self.status,
#             'method': self.method,
#             'jobId': self.job_id,
#             'sender': self.sender
#         }
# 
#         return filter_null_value_fields(serialized)
# 
# class Job(db.Model):
#     __tablename__ = 'jobs'
# 
#     id = db.Column(db.Integer, primary_key=True)
#     name = db.Column(db.String(255), nullable=False)
#     filename = db.Column(db.String(255), nullable=True)
# 
#     created_at = db.Column(db.DateTime, index=False, unique=False, nullable=False)
# 
#     service_id = db.Column(db.BigInteger, db.ForeignKey('services.id'), index=True, unique=False)
#     service = db.relationship('Service', backref=db.backref('jobs', lazy='dynamic'))
# 
#     def serialize(self):
#         serialized = {
#             'id': self.id,
#             'name': self.name,
#             'filename': self.filename,
#             'createdAt': self.created_at.strftime(DATETIME_FORMAT),
#             'serviceId': self.service_id
#         }
# 
#         return filter_null_value_fields(serialized)


# Path: tests/app/connectors/test_access_queue.py
from datetime import datetime
from flask import json
from app.connectors.access_queue import send_messages_to_queue, get_messages_from_queue
from app.models import Notification, Job
import moto
import boto3





notification = Notification(to='mock@example.com',
                            message='notification message',
                            status='created',
                            method='email',
                            created_at=datetime.utcnow(),
                            job=Job(id=1234, name='jobname',
                                    filename='filename',
                                    created_at=datetime.utcnow(), service_id=1234))


@moto.mock_sqs
def test_send_messages_to_queue_adds_message_queue(notify_api):
    q = set_up_mock_queue('email')
    q.send_message(MessageBody=json.dumps(notification.serialize()),
                   MessageAttributes={'type': {'StringValue': 'email', 'DataType': 'String'}})

    messages = [notification]
    b = send_messages_to_queue('email', messages)
    assert b is True


@moto.mock_sqs
def test_send_sms_messages_to_queue_adds_message_queue(notify_api):
    q = set_up_mock_queue('sms')

    sms = Notification(to='+441234512345',