Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/tests/data.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import datetime | |||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Directory, | Directory, | ||||
DirectoryEntry, | DirectoryEntry, | ||||
ObjectType, | ObjectType, | ||||
OriginVisitStatus, | |||||
Release, | Release, | ||||
Revision, | Revision, | ||||
RevisionType, | RevisionType, | ||||
) | ) | ||||
from swh.model.tests import swh_model_data | from swh.model.tests import swh_model_data | ||||
UTC = datetime.timezone.utc | |||||
def populate_search_data(search): | def populate_search_data(search): | ||||
search.origin_update({"url": origin.url} for origin in get_origins()) | search.origin_update({"url": origin.url} for origin in get_origins()) | ||||
def get_origins(): | def get_origins(): | ||||
return swh_model_data.ORIGINS | return swh_model_data.ORIGINS | ||||
▲ Show 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | return [ | ||||
type="dir", | type="dir", | ||||
target=get_directories()[1].id, | target=get_directories()[1].id, | ||||
), | ), | ||||
) | ) | ||||
) | ) | ||||
] | ] | ||||
def get_visit_with_multiple_status(): | |||||
return [ | |||||
OriginVisitStatus( | |||||
origin=get_origins()[0].url, | |||||
date=datetime.datetime(2014, 5, 7, 4, 20, 39, 432222, tzinfo=UTC), | |||||
visit=1, | |||||
type="git", | |||||
status="ongoing", | |||||
snapshot=None, | |||||
metadata=None, | |||||
) | |||||
] | |||||
GRAPHQL_EXTRA_TEST_OBJECTS = { | GRAPHQL_EXTRA_TEST_OBJECTS = { | ||||
"release": get_releases_with_target(), | "release": get_releases_with_target(), | ||||
"revision": get_revisions_with_parents(), | "revision": get_revisions_with_parents(), | ||||
"directory": get_directories_with_nested_path(), | "directory": get_directories_with_nested_path(), | ||||
"origin_visit_status": get_visit_with_multiple_status(), | |||||
} | } | ||||
def populate_dummy_data(storage): | def populate_dummy_data(storage): | ||||
for object_type, objects in swh_model_data.TEST_OBJECTS.items(): | for object_type, objects in swh_model_data.TEST_OBJECTS.items(): | ||||
method = getattr(storage, object_type + "_add") | method = getattr(storage, object_type + "_add") | ||||
method(objects) | method(objects) | ||||
for object_type, objects in GRAPHQL_EXTRA_TEST_OBJECTS.items(): | for object_type, objects in GRAPHQL_EXTRA_TEST_OBJECTS.items(): | ||||
method = getattr(storage, object_type + "_add") | method = getattr(storage, object_type + "_add") | ||||
method(objects) | method(objects) |