Ejemplo n.º 1
0
def test_send_comment_moderation_email(email_backend_setup, admin_user):
    """Email should be sent with a different subject and body depending on whether it needs moderation."""

    site_title = "foobar blog"
    site_url = "http://example.com"
    comment_body = "hello world"
    from_email = "*****@*****.**"
    moderation_email = "*****@*****.**"

    ConfigFactory(site_url=site_url, site_title=site_title, from_email=from_email, moderation_email=moderation_email)
    post = PostFactory(author=admin_user)

    # Test spam first
    comment = CommentFactory(body=comment_body, post=post, spam=True, approved=False)
    send_comment_moderation_email(comment)
    sent_msg = mail.outbox[0]
    path = reverse('tangerine:manage_comment', kwargs={'comment_id': comment.id})

    assert len(mail.outbox) == 1
    assert sent_msg.subject == "A new comment on {} requires moderation".format(site_title)
    assert comment_body in sent_msg.body  # Content is wrapped in email template, so not identical
    assert "{}{}".format(site_url, path) in sent_msg.body  # Email includes comment moderation link
    assert sent_msg.from_email == from_email
    assert moderation_email in sent_msg.recipients()

    # Then ham
    comment = CommentFactory(body=comment_body, post=post, spam=False, approved=True)
    send_comment_moderation_email(comment)
    sent_msg = mail.outbox[1]
    assert sent_msg.subject == "A new comment on {} has been automatically published".format(site_title)
Ejemplo n.º 2
0
def test_comment_approval():
    config = ConfigFactory()

    # Comments from authenticated users should always be approved.
    # auto_approve_previous_commentors in settings defaults to True.
    # Second arg to get_comment_approval() is a bool: whether they're authenticated or not.
    assert get_comment_approval('*****@*****.**', True) is True

    # Comments from unauthenticated users should be approved IF they are in the ApprovedCommentor table
    # and auto_approve_previous_commentors is True in settings.
    assert get_comment_approval('*****@*****.**', False) is False

    ApprovedCommentor.objects.create(email='*****@*****.**')
    assert get_comment_approval('*****@*****.**', False) is True

    # Now change the config preference and try an email that IS stored in the table. Should now NOT be approved.
    config.auto_approve_previous_commentors = False
    config.save()
    assert get_comment_approval('*****@*****.**', False) is False
Ejemplo n.º 3
0
def test_submit_aksimet_spam():
    """Akismet API will believe what we tell it (return True if we say it's spam and vice versa). So simple check."""

    if hasattr(settings, 'AKISMET_KEY'):

        ConfigFactory(akismet_key=settings.AKISMET_KEY, site_url=settings.SITE_URL)
        post = PostFactory()

        c1 = CommentFactory(post=post, email='*****@*****.**', spam=True)

        assert akismet_spam_ham(c1) is True
Ejemplo n.º 4
0
def test_approval_toggle():
    config = ConfigFactory()  # auto_approve defaults to True
    post = PostFactory()

    c1 = CommentFactory(post=post, approved=False)
    assert not c1.approved
    assert not ApprovedCommentor.objects.filter(email=c1.email).exists()
    toggle_approval(c1)
    assert c1.approved
    assert ApprovedCommentor.objects.filter(email=c1.email).exists()

    # With auto_approve disabled, state is toggled but commenter is never in ApprovedCommentors
    config.auto_approve_previous_commentors = False
    config.save()

    c2 = CommentFactory(post=post, approved=False)
    assert not c2.approved
    assert not ApprovedCommentor.objects.filter(email=c2.email).exists()
    toggle_approval(c2)
    assert c2.approved
    assert not ApprovedCommentor.objects.filter(email=c2.email).exists()
Ejemplo n.º 5
0
def test_future_posts(settings):
    # If `show_future` enabled in config, show Posts with future timestamps in calls to Post.pub.all().
    # Exclude otherwise. Default for `show_future` is False.

    settings.USE_TZ = False
    config = ConfigFactory()

    past_pub_date = datetime.datetime.strptime(
        '{} {} {} {} {} {}'.format(2017, 2, 2, 3, 3, 3), '%Y %m %d %H %M %S')
    past_post = PostFactory(pub_date=make_aware(past_pub_date))
    future_pub_date = datetime.datetime.strptime(
        '{} {} {} {} {} {}'.format(2037, 2, 2, 3, 3, 3), '%Y %m %d %H %M %S')
    future_post = PostFactory(pub_date=make_aware(future_pub_date))

    # By default, should not include future_post
    assert past_post in Post.pub.all()
    assert future_post not in Post.pub.all()

    # If show_future enabled in config, DO show future_post in queries
    config.show_future = True
    config.save()
    assert future_post in Post.pub.all()
Ejemplo n.º 6
0
def test_spam_check():
    """For now we are just testing our route to the Akismet API and whether we store submitted comments
    as spam or not. Later expand this into multiple tests to support multiple spam checking engines.

    Devs who want to run this test *must* add to their *test* settings:
    AKISMET_KEY = 'abc123' and SITE_URL = 'https://your.registered.domain'
    (but with real values). Otherwise we can't run tests that call their API with YOUR credentials.
    See https://akismet.com/development/api/#detailed-docs for notes on testing Akismet API calls."""

    if hasattr(settings, 'AKISMET_KEY'):

        ConfigFactory(akismet_key=settings.AKISMET_KEY, site_url=settings.SITE_URL)
        post = PostFactory()

        # Good comment:
        c1 = CommentFactory(post=post, email='*****@*****.**')
        c2 = CommentFactory(post=post)

        assert spam_check(c1) is True
        assert spam_check(c2) is False
Ejemplo n.º 7
0
def cats_and_posts():
    ConfigFactory()

    CategoryFactory.create_batch(10)
    PostFactory.create_batch(30)
Ejemplo n.º 8
0
def test_get_settings():
    ConfigFactory()
    config = get_settings()
    assert len(config['site_title']) > 5
    assert len(config['tagline']) > 5
    assert config['num_posts_per_list_view'] > 1
Ejemplo n.º 9
0
def config():
    # Set up base configuration data (site title, etc.)
    ConfigFactory()