from grocernet import create_app
from grocernet.util import email

app = create_app(testing=True)


def test_email_token():
    secret_key = "<KEY>"
    token = email.generate_email_confirmation_token(
        "<EMAIL>", secret_key)
    assert token != "<EMAIL>"

    email_address = email.confirm_email_confirmation_token(token, secret_key)
    assert email_address == "<EMAIL>"


def test_invalid_token():
    token = "invalid token"

    result = email.confirm_email_confirmation_token(token, "asdf")
    assert not result


def test_send_email():
    with app.app_context():
        with app.test_request_context():
            with email.mail.record_messages() as outbox:
                email.send_email("test", "<EMAIL>",
                                 "<p>Hello</p>")

                assert len(outbox) == 1
                assert outbox[0].subject == 'test'
                assert outbox[0].sender == app.config['MAIL_DEFAULT_SENDER']


def test_censor_out_email():
    addr = "<EMAIL>"
    assert email.censor_email(addr) == "<EMAIL>"

from grocernet import create_app
from grocernet.util import email

app = create_app(testing=True)


def test_email_token():
    secret_key = "<KEY>"
    token = email.generate_email_confirmation_token(
        "<EMAIL>", secret_key)
    assert token != "<EMAIL>"

    email_address = email.confirm_email_confirmation_token(token, secret_key)
    assert email_address == "<EMAIL>"


def test_invalid_token():
    token = "invalid token"

    result = email.confirm_email_confirmation_token(token, "asdf")
    assert not result


def test_send_email():
    with app.app_context():
        with app.test_request_context():
            with email.mail.record_messages() as outbox:
                email.send_email("test", "<EMAIL>",
                                 "<p>Hello</p>")

                assert len(outbox) == 1
                assert outbox[0].subject == 'test'
                assert outbox[0].sender == app.config['MAIL_DEFAULT_SENDER']


def test_censor_out_email():
    addr = "<EMAIL>"
    assert email.censor_email(addr) == "<EMAIL>"
