Changeset View
Changeset View
Standalone View
Standalone View
swh/journal/tests/journal_data.py
# Copyright (C) 2019-2020 The Software Heritage developers | # Copyright (C) 2019-2020 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 | import datetime | ||||
from typing import Dict, Sequence | from typing import Dict, Sequence | ||||
import attr | import attr | ||||
from swh.model.hashutil import MultiHash, hash_to_bytes | from swh.model.hashutil import MultiHash, hash_to_bytes, hash_to_hex | ||||
from swh.journal.serializers import ModelObject | from swh.journal.serializers import ModelObject | ||||
from swh.model.identifiers import SWHID | |||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Content, | Content, | ||||
Directory, | Directory, | ||||
DirectoryEntry, | DirectoryEntry, | ||||
MetadataAuthority, | |||||
MetadataAuthorityType, | |||||
MetadataFetcher, | |||||
MetadataTargetType, | |||||
ObjectType, | ObjectType, | ||||
Origin, | Origin, | ||||
OriginVisit, | OriginVisit, | ||||
OriginVisitStatus, | OriginVisitStatus, | ||||
Person, | Person, | ||||
RawExtrinsicMetadata, | |||||
Release, | Release, | ||||
Revision, | Revision, | ||||
RevisionType, | RevisionType, | ||||
SkippedContent, | SkippedContent, | ||||
Snapshot, | Snapshot, | ||||
SnapshotBranch, | SnapshotBranch, | ||||
TargetType, | TargetType, | ||||
Timestamp, | Timestamp, | ||||
▲ Show 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | Snapshot( | ||||
target_type=TargetType.SNAPSHOT, | target_type=TargetType.SNAPSHOT, | ||||
target=hash_to_bytes("17d0066a4a80aba4a0e913532ee8ff2014f006a9"), | target=hash_to_bytes("17d0066a4a80aba4a0e913532ee8ff2014f006a9"), | ||||
), | ), | ||||
}, | }, | ||||
), | ), | ||||
] | ] | ||||
METADATA_AUTHORITIES = [ | |||||
MetadataAuthority( | |||||
type=MetadataAuthorityType.FORGE, url="http://example.org/", metadata={}, | |||||
), | |||||
] | |||||
METADATA_FETCHERS = [ | |||||
MetadataFetcher(name="test-fetcher", version="1.0.0", metadata={},) | |||||
] | |||||
RAW_EXTRINSIC_METADATA = [ | |||||
RawExtrinsicMetadata( | |||||
type=MetadataTargetType.ORIGIN, | |||||
id="http://example.org/foo.git", | |||||
discovery_date=datetime.datetime(2020, 7, 30, 17, 8, 20, tzinfo=UTC), | |||||
authority=attr.evolve(METADATA_AUTHORITIES[0], metadata=None), | |||||
fetcher=attr.evolve(METADATA_FETCHERS[0], metadata=None), | |||||
format="json", | |||||
metadata=b'{"foo": "bar"}', | |||||
), | |||||
RawExtrinsicMetadata( | |||||
type=MetadataTargetType.CONTENT, | |||||
id=SWHID(object_type="content", object_id=hash_to_hex(CONTENTS[0].sha1_git)), | |||||
discovery_date=datetime.datetime(2020, 7, 30, 17, 8, 20, tzinfo=UTC), | |||||
authority=attr.evolve(METADATA_AUTHORITIES[0], metadata=None), | |||||
fetcher=attr.evolve(METADATA_FETCHERS[0], metadata=None), | |||||
format="json", | |||||
metadata=b'{"foo": "bar"}', | |||||
), | |||||
] | |||||
TEST_OBJECTS: Dict[str, Sequence[ModelObject]] = { | TEST_OBJECTS: Dict[str, Sequence[ModelObject]] = { | ||||
"content": CONTENTS, | "content": CONTENTS, | ||||
"directory": DIRECTORIES, | "directory": DIRECTORIES, | ||||
"metadata_authority": METADATA_AUTHORITIES, | |||||
"metadata_fetcher": METADATA_FETCHERS, | |||||
"origin": ORIGINS, | "origin": ORIGINS, | ||||
"origin_visit": ORIGIN_VISITS, | "origin_visit": ORIGIN_VISITS, | ||||
"origin_visit_status": ORIGIN_VISIT_STATUSES, | "origin_visit_status": ORIGIN_VISIT_STATUSES, | ||||
"raw_extrinsic_metadata": RAW_EXTRINSIC_METADATA, | |||||
"release": RELEASES, | "release": RELEASES, | ||||
"revision": REVISIONS, | "revision": REVISIONS, | ||||
"snapshot": SNAPSHOTS, | "snapshot": SNAPSHOTS, | ||||
"skipped_content": SKIPPED_CONTENTS, | "skipped_content": SKIPPED_CONTENTS, | ||||
} | } |