Changeset View
Changeset View
Standalone View
Standalone View
swh/web/tests/data.py
Show First 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | INDEXER_TOOL = { | ||||
"tool_version": "1.0", | "tool_version": "1.0", | ||||
"tool_configuration": {}, | "tool_configuration": {}, | ||||
} | } | ||||
ORIGIN_METADATA_KEY = "keywords" | ORIGIN_METADATA_KEY = "keywords" | ||||
ORIGIN_METADATA_VALUE = "git" | ORIGIN_METADATA_VALUE = "git" | ||||
ORIGIN_MASTER_REVISION = {} | ORIGIN_MASTER_REVISION = {} | ||||
ORIGIN_MASTER_DIRECTORY = {} | |||||
def _add_origin( | def _add_origin( | ||||
storage, search, counters, origin_url, visit_type="git", snapshot_branches={} | storage, search, counters, origin_url, visit_type="git", snapshot_branches={} | ||||
): | ): | ||||
storage.origin_add([Origin(url=origin_url)]) | storage.origin_add([Origin(url=origin_url)]) | ||||
search.origin_update( | search.origin_update( | ||||
[{"url": origin_url, "has_visits": True, "visit_types": [visit_type]}] | [{"url": origin_url, "has_visits": True, "visit_types": [visit_type]}] | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | for origin in _TEST_ORIGINS: | ||||
object_type=ObjectType.SNAPSHOT, object_id=snp.id | object_type=ObjectType.SNAPSHOT, object_id=snp.id | ||||
), | ), | ||||
) | ) | ||||
) | ) | ||||
if b"master" in branch_name: | if b"master" in branch_name: | ||||
# Add some origin intrinsic metadata for tests | # Add some origin intrinsic metadata for tests | ||||
metadata = common_metadata | metadata = common_metadata | ||||
metadata.update(origin.get("metadata", {})) | metadata.update(origin.get("metadata", {})) | ||||
revision = storage.revision_get([branch_data.target])[0] | |||||
origin_metadata = OriginIntrinsicMetadataRow( | origin_metadata = OriginIntrinsicMetadataRow( | ||||
id=origin["url"], | id=origin["url"], | ||||
from_revision=branch_data.target, | from_directory=revision.directory, | ||||
indexer_configuration_id=idx_tool["id"], | indexer_configuration_id=idx_tool["id"], | ||||
metadata=metadata, | metadata=metadata, | ||||
mappings=[], | mappings=[], | ||||
) | ) | ||||
idx_storage.origin_intrinsic_metadata_add([origin_metadata]) | idx_storage.origin_intrinsic_metadata_add([origin_metadata]) | ||||
search.origin_update( | search.origin_update( | ||||
[{"url": origin["url"], "intrinsic_metadata": metadata}] | [{"url": origin["url"], "intrinsic_metadata": metadata}] | ||||
) | ) | ||||
ORIGIN_MASTER_REVISION[origin["url"]] = hash_to_hex( | ORIGIN_MASTER_REVISION[origin["url"]] = hash_to_hex( | ||||
branch_data.target | branch_data.target | ||||
) | ) | ||||
ORIGIN_MASTER_DIRECTORY[origin["url"]] = hash_to_hex( | |||||
revision.directory | |||||
) | |||||
elif target_type == "release": | elif target_type == "release": | ||||
release = storage.release_get([branch_data.target])[0] | release = storage.release_get([branch_data.target])[0] | ||||
origin_revisions.add(release.target) | origin_revisions.add(release.target) | ||||
releases.add(hash_to_hex(branch_data.target)) | releases.add(hash_to_hex(branch_data.target)) | ||||
swhids.append( | swhids.append( | ||||
QualifiedSWHID( | QualifiedSWHID( | ||||
object_type=ObjectType.RELEASE, | object_type=ObjectType.RELEASE, | ||||
object_id=branch_data.target, | object_id=branch_data.target, | ||||
▲ Show 20 Lines • Show All 208 Lines • Show Last 20 Lines |