<commit_before># Copyright (C) 2018-2021  The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information

from datetime import timedelta

from hypothesis import given
import iso8601
import pytest

from swh.model.model import OriginVisit, OriginVisitStatus
from swh.storage.utils import now
from swh.web.common.exc import NotFoundExc
from swh.web.common.origin_visits import get_origin_visit, get_origin_visits
from swh.web.common.typing import OriginInfo
from swh.web.tests.strategies import new_origin, new_snapshots


@given(new_origin(), new_snapshots(3))
def test_get_origin_visits(mocker, archive_data, new_origin, new_snapshots):
    from swh.web.common import archive

    mocker.patch.object(archive, "MAX_LIMIT", 2)

    archive_data.origin_add([new_origin])
    archive_data.snapshot_add(new_snapshots)
    for i, snapshot in enumerate(new_snapshots):
        visit_date = now() + timedelta(days=i * 10)
        visit = archive_data.origin_visit_add(
            [OriginVisit(origin=new_origin.url, date=visit_date, type="git",)]
        )[0]
        visit_status = OriginVisitStatus(
            origin=new_origin.url,
            visit=visit.visit,
            date=visit_date + timedelta(minutes=5),
            status="full",
            snapshot=snapshot.id,
        )
        archive_data.origin_visit_status_add([visit_status])
<commit_msg>tests: Fix flaky test introduced in e72b1e7a9d18<commit_after># Copyright (C) 2018-2021  The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU Affero General Public License version 3, or any later version
# See top-level LICENSE file for more information

from datetime import timedelta

from hypothesis import given, settings
import iso8601
import pytest

from swh.model.model import OriginVisit, OriginVisitStatus
from swh.storage.utils import now
from swh.web.common.exc import NotFoundExc
from swh.web.common.origin_visits import get_origin_visit, get_origin_visits
from swh.web.common.typing import OriginInfo
from swh.web.tests.strategies import new_origin, new_snapshots


@settings(max_examples=1)
@given(new_origin(), new_snapshots(3))
def test_get_origin_visits(mocker, archive_data, new_origin, new_snapshots):
    from swh.web.common import archive

    mocker.patch.object(archive, "MAX_LIMIT", 2)

    archive_data.origin_add([new_origin])
    archive_data.snapshot_add(new_snapshots)
    for i, snapshot in enumerate(new_snapshots):
        visit_date = now() + timedelta(days=i * 10)
        visit = archive_data.origin_visit_add(
            [OriginVisit(origin=new_origin.url, date=visit_date, type="git",)]
        )[0]
        visit_status = OriginVisitStatus(
            origin=new_origin.url,
            visit=visit.visit,
            date=visit_date + timedelta(minutes=5),
            status="full",
            snapshot=snapshot.id,
        )
        archive_data.origin_visit_status_add([visit_status])

{'fraction_non_alphanumeric': 0.08074335148990708, 'fraction_numerical': 0.014738865748157642, 'mean_word_length': 4.027375201288245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '516572', 'n_tokens_mistral': 979, 'n_tokens_neox': 931, 'n_words': 242}