def test_daily_digest():
    ArticleFactory.create_batch(10)
    subscriptions = SubscriptionFactory.create_batch(10)

    daily_digest()

    for subscription in subscriptions:
        emails = Email.objects.filter(receivers=subscription.email)
        if subscription.confirmed_at:
            assert emails.exists() is True
        else:
            assert emails.exists() is False
Beispiel #2
0
def test_site_statistics():
    ArticleFactory.create_batch(10, publish=True)

    site_statistics()

    recent = dt.date.today() - dt.timedelta(days=28)

    for source in Source.objects.all():
        events = Event.objects.views().for_source(source)
        articles = source.articles.published()
        latest_article_date = (
            articles.order_by("-date").first().date.strftime("%Y-%m-%d")
        )
        recent_views = events.filter(created_at__date__gte=recent).count()

        assert source.data["article_count"] == articles.count()
        assert source.data["latest_article_date"] == latest_article_date
        assert source.data["recent_views"] == recent_views
Beispiel #3
0
def test_show_articles_action(admin_client):
    topics = TopicFactory.create_batch(5)
    selected = choice(topics)
    ArticleFactory.create_batch(10)

    url = reverse("admin:lynx_topic_changelist")
    data = {
        "post": "yes",
        "_selected_action": [selected.pk],
        "action": "show_articles",
    }

    response = admin_client.post(url, data, follow=True)

    request = response.request
    slugs = selected.slug

    assert request["PATH_INFO"] == reverse("admin:lynx_article_changelist")
    assert request["QUERY_STRING"] == f"topics__slug__in={slugs}"
Beispiel #4
0
def articles():
    return ArticleFactory.create_batch(10)
Beispiel #5
0
def articles(author):
    LabelFactory.create_batch(5)
    SourceFactory.create_batch(20)
    TopicFactory.create_batch(20)
    return ArticleFactory.create_batch(100, authors=[author])
def articles():
    LabelFactory.create_batch(5)
    AuthorFactory.create_batch(10)
    TopicFactory.create_batch(20)
    NotificationFactory.create_batch(20)
    return ArticleFactory.create_batch(100)
Beispiel #7
0
def articles(source):
    LabelFactory.create_batch(5)
    AuthorFactory.create_batch(10)
    TopicFactory.create_batch(20)
    return ArticleFactory.create_batch(100, source=source)
def articles(topic):
    LabelFactory.create_batch(5)
    AuthorFactory.create_batch(10)
    SourceFactory.create_batch(20)
    return ArticleFactory.create_batch(100, topics=[topic])
Beispiel #9
0
def articles(today):
    LabelFactory.create_batch(5)
    AuthorFactory.create_batch(10)
    TopicFactory.create_batch(10)
    SourceFactory.create_batch(10)
    return ArticleFactory.create_batch(10, date=today)