"""Tests for notifications."""

from django.core import mail


def test_message_url_nologin(client, message):
    """Test message factory url requires login."""
    response = client.get('/notifications/{}'.format(message.url))
    print(response.content)
    assert response.status_code == 302


def test_message_url(authed_client, message):
    """Test message factory url renders something."""
    response = authed_client.get('/notifications/{}'.format(message.url))
    assert response.status_code == 200


def test_send_notifications(notification_history):
    """Test sending a notification produces an email."""

    notification_history.sent = False
    notification_history.save()

    from notifications.tasks import send_notifications
    send_notifications()

    # A new user email is generated by the UserFactory as well as the
    # notification that we're sending, so there are 2 outgoing messages
    assert len(mail.outbox) == 2
