예제 #1
0
def test_create_contents_with_attachment_url(session, loop):
    """Assert the test can create notification contents with attachment url."""
    notification = NotificationFactory.create_model(
        session, notification_info=NotificationFactory.Models.PENDING_1)

    request_content: ContentRequest = ContentRequest(
        **ContentFactory.RequestData.CONTENT_REQUEST_3)

    result = loop.run_until_complete(
        ContentCRUD.create_content(session,
                                   request_content,
                                   notification_id=notification.id))

    assert result.subject == ContentFactory.RequestData.CONTENT_REQUEST_3[
        'subject']

    result_attachment = loop.run_until_complete(
        AttachmentCRUD.find_attachments_by_content_id(session, result.id))

    assert result_attachment[
        0].file_name == AttachmentFactory.RequestData.FILE_REQUEST_1[
            'fileName']
    assert result_attachment[
        1].file_name == AttachmentFactory.RequestData.FILE_REQUEST_2[
            'fileName']
예제 #2
0
def test_find_no_notification_by_status_time(session, loop):
    """Assert the test can not retrieve notification by status and time frame."""
    notification = NotificationFactory.create_model(session,
                                                    notification_info=NotificationFactory.Models.OVER_1_HOUR)

    result = loop.run_until_complete(
        NotifyService.find_notifications_by_status(session, notification.status_code)
    )
    assert not result
예제 #3
0
def test_find_notification_by_status(session, loop):
    """Assert the test can retrieve notification by status."""
    notification = NotificationFactory.create_model(session)

    result = loop.run_until_complete(
        NotifyService.find_notifications_by_status(session, notification.status_code)
    )
    assert result[0].id == NotificationFactory.Models.PENDING_1['id']
    assert result[0].recipients == NotificationFactory.Models.PENDING_1['recipients']
예제 #4
0
def test_find_notification_by_id(session, loop):
    """Assert the test can retrieve notification by id."""
    notification = NotificationFactory.create_model(session)

    result = loop.run_until_complete(
        NotificaitonCRUD.find_notification_by_id(session, notification.id)
    )
    assert result.id == NotificationFactory.Models.PENDING_1['id']
    assert result.recipients == NotificationFactory.Models.PENDING_1['recipients']
예제 #5
0
def test_find_notification_by_status_time(session, loop):
    """Assert the test can retrieve notification by status and time frame."""
    notification = NotificationFactory.create_model(session,
                                                    notification_info=NotificationFactory.Models.LESS_1_HOUR)

    result = loop.run_until_complete(
        NotifyService.find_notifications_by_status(session, notification.status_code)
    )
    assert result[0] == notification
    assert result[0].id == NotificationFactory.Models.LESS_1_HOUR['id']
    assert result[0].recipients == NotificationFactory.Models.LESS_1_HOUR['recipients']
예제 #6
0
def test_find_content_by_notification_id(session, loop):
    """Assert the test can retrieve notification contents with notification id."""
    notification = NotificationFactory.create_model(
        session, notification_info=NotificationFactory.Models.PENDING_1)
    ContentFactory.create_model(session,
                                notification.id,
                                content_info=ContentFactory.Models.CONTENT_1)

    result = loop.run_until_complete(
        ContentCRUD.find_content_by_notification_id(session, notification.id))
    assert result.id == ContentFactory.Models.CONTENT_1['id']
    assert result.subject == ContentFactory.Models.CONTENT_1['subject']
예제 #7
0
def test_update_notification(session, loop):
    """Assert the test can update notification."""
    notification = NotificationFactory.create_model(session)

    notification.sent_date = datetime.now()
    notification.status_code = 'FAILURE'
    result = loop.run_until_complete(
        NotificaitonCRUD.update_notification(session, notification)
    )
    assert result == notification
    assert result.id == NotificationFactory.Models.PENDING_1['id']
    assert result.recipients == NotificationFactory.Models.PENDING_1['recipients']
    assert result.status_code == 'FAILURE'
예제 #8
0
def test_find_notification_by_status_time(session, loop):
    """Assert the test can retrieve notifications by status and time frame."""
    notification = NotificationFactory.create_model(session,
                                                    notification_info=NotificationFactory.Models.LESS_1_HOUR)

    result = loop.run_until_complete(
        NotificaitonCRUD.find_notifications_by_status_time(session,
                                                           notification.status_code,
                                                           get_api_settings().DELIVERY_FAILURE_RETRY_TIME_FRAME)
    )
    assert result[0] == notification
    assert result[0].id == NotificationFactory.Models.LESS_1_HOUR['id']
    assert result[0].recipients == NotificationFactory.Models.LESS_1_HOUR['recipients']
예제 #9
0
def test_update_notification(session, loop):
    """Assert the test can update notification."""
    notification = NotificationFactory.create_model(session)

    update_notification: NotificationUpdate = NotificationUpdate(id=notification.id,
                                                                 sent_date=datetime.now(),
                                                                 notify_status='FAILURE')
    result = loop.run_until_complete(
        NotifyService.update_notification_status(session, update_notification)
    )

    assert result.id == NotificationFactory.Models.PENDING_1['id']
    assert result.recipients == NotificationFactory.Models.PENDING_1['recipients']
    assert result.status_code == 'FAILURE'
예제 #10
0
def test_find_notification_by_id(session, loop):
    """Assert the test can retrieve notification by id."""
    notification = NotificationFactory.create_model(session, notification_info=NotificationFactory.Models.PENDING_1)
    content = ContentFactory.create_model(session, notification.id, content_info=ContentFactory.Models.CONTENT_1)
    AttachmentFactory.create_model(session, content.id, attachment_info=AttachmentFactory.Models.FILE_1)

    result = loop.run_until_complete(
        NotifyService.find_notification(session, notification.id)
    )

    assert result.id == NotificationFactory.Models.PENDING_1['id']
    assert result.recipients == NotificationFactory.Models.PENDING_1['recipients']
    assert result.content.subject == ContentFactory.Models.CONTENT_1['subject']
    assert result.content.attachments[0].file_name == AttachmentFactory.Models.FILE_1['file_name']
예제 #11
0
def test_create_contents(session, loop):
    """Assert the test can create notification contents."""
    notification = NotificationFactory.create_model(
        session, notification_info=NotificationFactory.Models.PENDING_1)

    request_content: ContentRequest = ContentRequest(
        **ContentFactory.RequestData.CONTENT_REQUEST_1)

    result = loop.run_until_complete(
        ContentCRUD.create_content(session,
                                   request_content,
                                   notification_id=notification.id))

    assert result.subject == ContentFactory.RequestData.CONTENT_REQUEST_1[
        'subject']
예제 #12
0
def test_get_by_id(session, app, client, jwt):  # pylint: disable=unused-argument
    """Assert the test can retrieve notification details by id."""
    notification = NotificationFactory.create_model(
        session, notification_info=NotificationFactory.Models.PENDING_1)
    ContentFactory.create_model(session,
                                notification.id,
                                content_info=ContentFactory.Models.CONTENT_1)

    headers = JwtFactory.factory_auth_header(
        jwt=jwt, claims=JwtClaimsFactory.public_user_role)
    res = client.get('/api/v1/notify/{}'.format(notification.id),
                     headers=headers)
    response_data = res.json()
    assert res.status_code == 200
    assert response_data['recipients'] == NotificationFactory.Models.PENDING_1[
        'recipients']
    assert response_data['content'][
        'subject'] == ContentFactory.Models.CONTENT_1['subject']
예제 #13
0
def test_get_by_id_no_token(session, app, client):  # pylint: disable=unused-argument
    """Assert the test cannot retrieve notification details with no token."""
    notification = NotificationFactory.create_model(session)

    res = client.get('/api/v1/notify/{}'.format(notification.id))
    assert res.status_code == 403