Exemple #1
0
def test_doubling_issue(session, test_user):
    """Test to check that a row doubling issue between tags and discussions has not been regressed.

    This is for bug #65.
    """
    epoch_start = datetime(2018, 1, 3)
    bm = make_bookmark(
        tag_triples=set([("a", epoch_start, False), ("b", epoch_start, False)])
    )
    set_bookmark(session, test_user.user_uuid, bm)

    discussions = [
        Discussion(
            external_id=str(random_numeric_id()),
            source=DiscussionSource.REDDIT,
            url=bm.url,
            comment_count=1,
            created_at=datetime(2018, 1, 3),
            title="example",
        ),
        Discussion(
            external_id=str(random_numeric_id()),
            source=DiscussionSource.HN,
            url=bm.url,
            comment_count=0,
            created_at=datetime(2018, 1, 3),
            title="example",
        ),
    ]

    upsert_discussions(session, discussions)
    bookmarks = list(f for f in BookmarkViewQueryBuilder(session, test_user).execute())
    assert len(bookmarks) == 1
Exemple #2
0
def on_discussion_crawl_requested(message: PickleMessage,
                                  ctx: missive.HandlingContext):
    event = cast(FetchDiscussionsCommand, message.get_obj())
    session = get_session(ctx)
    http_client = get_http_client(ctx)
    url = get_url_by_url_uuid(session, event.url_uuid)
    if url is None:
        # FIXME: improve this...
        raise RuntimeError("url does not exist!")
    log.info("fetching discussions for %s from %s", url, event.source)
    client: Union[discussion_clients.HNAlgoliaClient,
                  discussion_clients.RedditDiscussionClient]
    if event.source == DiscussionSource.HN:
        client = discussion_clients.HNAlgoliaClient(http_client)
    else:
        client = get_reddit_client(ctx)

    try:
        upsert_discussions(session, client.discussions_for_url(url))
        record_discussion_fetch(session, url, event.source)
    except discussion_clients.DiscussionAPIError as e:
        log.error(
            "got bad response (%s) from %s: %s",
            e.response_status(),
            e.source,
            e.response_text(),
        )
        session.rollback()
    else:
        session.commit()
    ctx.ack()
Exemple #3
0
def test_discussion_digests(session, test_user):
    bm = make_bookmark()
    set_bookmark(session, test_user.user_uuid, bm)

    discussions = [
        Discussion(
            external_id=str(random_numeric_id()),
            source=DiscussionSource.HN,
            url=bm.url,
            comment_count=1,
            created_at=datetime(2018, 1, 3),
            title="example",
        ),
        Discussion(
            external_id=str(random_numeric_id()),
            source=DiscussionSource.HN,
            url=bm.url,
            comment_count=0,
            created_at=datetime(2018, 1, 3),
            title="example",
        ),
        Discussion(
            external_id=str(random_numeric_id()),
            source=DiscussionSource.HN,
            url=bm.url,
            comment_count=100,
            created_at=datetime(2018, 1, 3),
            title="example",
        ),
        Discussion(
            external_id=str(random_numeric_id()),
            source=DiscussionSource.REDDIT,
            url=bm.url,
            comment_count=1,
            created_at=datetime(2018, 1, 3),
            title="example",
        ),
    ]

    upsert_discussions(session, discussions)
    (bm1_view,) = (f for f in BookmarkViewQueryBuilder(session, test_user).execute())
    assert bm1_view.discussion_digest.comment_count == 102
    assert bm1_view.discussion_digest.discussion_count == 4
    assert bm1_view.discussion_digest.sources == {
        DiscussionSource.HN,
        DiscussionSource.REDDIT,
    }
Exemple #4
0
def test_discussions(signed_in_client, test_user, session):
    bm = make_bookmark()
    set_bookmark(session, test_user.user_uuid, bm)

    discussions = [
        Discussion(
            external_id=str(random_numeric_id()),
            source=DiscussionSource.HN,
            url=bm.url,
            comment_count=1,
            created_at=datetime(2018, 1, 3),
            title="HN discussion 1",
        )
    ]

    upsert_discussions(session, discussions)

    response = signed_in_client.get(
        flask.url_for(
            "quarchive.discussions",
            username=test_user.username,
            url_uuid=bm.url.url_uuid,
        ))
    assert response.status_code == 200