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 | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import ObjectType, Release | from swh.model.model import ObjectType, Release, Revision, RevisionType | ||||
from swh.model.tests import swh_model_data | from swh.model.tests import swh_model_data | ||||
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(): | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | with_content = Release( | ||||
target_type=ObjectType.CONTENT, | target_type=ObjectType.CONTENT, | ||||
target=get_contents()[0].sha1_git, | target=get_contents()[0].sha1_git, | ||||
message=b"foo", | message=b"foo", | ||||
synthetic=False, | synthetic=False, | ||||
) | ) | ||||
return [with_revision, with_release, with_directory, with_content] | return [with_revision, with_release, with_directory, with_content] | ||||
GRAPHQL_EXTRA_TEST_OBJECTS = {"release": get_releases_with_target()} | def get_revisions_with_parents(): | ||||
""" | |||||
Revisions with real revisions as parents | |||||
""" | |||||
return [ | |||||
Revision( | |||||
ardumont: is it necessary to hard-code that id here?
If the revision object does not declare it, it will… | |||||
Done Inline ActionsIf I let that compute the SWHID, how do I use the same object while testing? jayeshv: If I let that compute the SWHID, how do I use the same object while testing?
This revision is… | |||||
Not Done Inline ActionsYou can have the objects be declared at the module level and then refer to them both in function (and/or fixture) and in test. ardumont: You can have the objects be declared at the module level and then refer to them both in… | |||||
Done Inline ActionsGot it, Thanks. I will make another diff for those change. This I will land jayeshv: Got it, Thanks. I will make another diff for those change. This I will land | |||||
Not Done Inline ActionsI agree with ardumont, hard-coding SWHIDs could be avoided here. You should wrap that revision in a fixture (without declaring the id as it is automatically computed when accessing the field) anlambert: I agree with ardumont, hard-coding SWHIDs could be avoided here.
You should wrap that revision… | |||||
Done Inline ActionsThanks, I will do that jayeshv: Thanks, I will do that | |||||
id=hash_to_bytes("37580d63b8dcc0ec73e74994e66896858542844c"), | |||||
message=b"hello", | |||||
date=swh_model_data.DATES[0], | |||||
committer=swh_model_data.COMMITTERS[0], | |||||
author=swh_model_data.COMMITTERS[0], | |||||
committer_date=swh_model_data.DATES[0], | |||||
type=RevisionType.GIT, | |||||
directory=b"\x01" * 20, | |||||
synthetic=False, | |||||
parents=(get_revisions()[0].id, get_revisions()[1].id), | |||||
) | |||||
] | |||||
GRAPHQL_EXTRA_TEST_OBJECTS = { | |||||
"release": get_releases_with_target(), | |||||
"revision": get_revisions_with_parents(), | |||||
} | |||||
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) |
is it necessary to hard-code that id here?
If the revision object does not declare it, it will be recomputed once it's accessed, it might be better that way (same goes for other dag model object).