Changeset View
Changeset View
Standalone View
Standalone View
swh/clearlydefined/tests/test_mapping_utils.py
Show All 21 Lines | from swh.clearlydefined.mapping_utils import ( | ||||
FETCHER, | FETCHER, | ||||
MappingStatus, | MappingStatus, | ||||
map_definition, | map_definition, | ||||
map_row, | map_row, | ||||
map_sha1_with_swhid, | map_sha1_with_swhid, | ||||
) | ) | ||||
from swh.model import from_disk | from swh.model import from_disk | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.identifiers import parse_swhid | from swh.model.identifiers import ExtendedSWHID | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Content, | Content, | ||||
Directory, | Directory, | ||||
DirectoryEntry, | DirectoryEntry, | ||||
MetadataTargetType, | |||||
Person, | Person, | ||||
RawExtrinsicMetadata, | RawExtrinsicMetadata, | ||||
Revision, | Revision, | ||||
RevisionType, | RevisionType, | ||||
Timestamp, | Timestamp, | ||||
TimestampWithTimezone, | TimestampWithTimezone, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | |||||
def test_map_row_for_definitions_with_gitsha1(swh_storage, datadir): | def test_map_row_for_definitions_with_gitsha1(swh_storage, datadir): | ||||
add_revision_data(swh_storage) | add_revision_data(swh_storage) | ||||
expected = ( | expected = ( | ||||
MappingStatus.MAPPED, | MappingStatus.MAPPED, | ||||
[ | [ | ||||
RawExtrinsicMetadata( | RawExtrinsicMetadata( | ||||
type=MetadataTargetType.REVISION, | target=ExtendedSWHID.from_string( | ||||
target=parse_swhid( | |||||
"swh:1:rev:4c66129b968ab8122964823d1d77677f50884cf6" | "swh:1:rev:4c66129b968ab8122964823d1d77677f50884cf6" | ||||
), | ), | ||||
discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | ||||
authority=AUTHORITY, | authority=AUTHORITY, | ||||
fetcher=FETCHER, | fetcher=FETCHER, | ||||
format="clearlydefined-definition-json", | format="clearlydefined-definition-json", | ||||
origin="http://central.maven.org/maven2/za/co/absa/cobrix/cobol-parser/" | origin="http://central.maven.org/maven2/za/co/absa/cobrix/cobol-parser/" | ||||
"0.4.0/cobol-parser-0.4.0-sources.jar", | "0.4.0/cobol-parser-0.4.0-sources.jar", | ||||
Show All 19 Lines | |||||
def test_map_row_for_scancode(swh_storage, datadir): | def test_map_row_for_scancode(swh_storage, datadir): | ||||
add_content_data(swh_storage) | add_content_data(swh_storage) | ||||
expected = ( | expected = ( | ||||
MappingStatus.UNMAPPED, | MappingStatus.UNMAPPED, | ||||
[ | [ | ||||
RawExtrinsicMetadata( | RawExtrinsicMetadata( | ||||
type=MetadataTargetType.CONTENT, | target=ExtendedSWHID.from_string( | ||||
target=parse_swhid( | |||||
"swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd" | "swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd" | ||||
), | ), | ||||
discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | ||||
authority=AUTHORITY, | authority=AUTHORITY, | ||||
fetcher=FETCHER, | fetcher=FETCHER, | ||||
format="clearlydefined-harvest-scancode-json", | format="clearlydefined-harvest-scancode-json", | ||||
origin=None, | origin=None, | ||||
metadata=json.dumps( | metadata=json.dumps( | ||||
Show All 18 Lines | |||||
def test_map_row_for_scancode_true_mapping_status(swh_storage, datadir): | def test_map_row_for_scancode_true_mapping_status(swh_storage, datadir): | ||||
add_content_data(swh_storage) | add_content_data(swh_storage) | ||||
expected = ( | expected = ( | ||||
MappingStatus.MAPPED, | MappingStatus.MAPPED, | ||||
[ | [ | ||||
RawExtrinsicMetadata( | RawExtrinsicMetadata( | ||||
type=MetadataTargetType.CONTENT, | target=ExtendedSWHID.from_string( | ||||
target=parse_swhid( | |||||
"swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd" | "swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd" | ||||
), | ), | ||||
discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | ||||
authority=AUTHORITY, | authority=AUTHORITY, | ||||
fetcher=FETCHER, | fetcher=FETCHER, | ||||
format="clearlydefined-harvest-scancode-json", | format="clearlydefined-harvest-scancode-json", | ||||
origin=None, | origin=None, | ||||
metadata=json.dumps( | metadata=json.dumps( | ||||
Show All 18 Lines | |||||
def test_map_row_for_licensee(swh_storage, datadir): | def test_map_row_for_licensee(swh_storage, datadir): | ||||
add_content_data(swh_storage) | add_content_data(swh_storage) | ||||
expected = ( | expected = ( | ||||
MappingStatus.UNMAPPED, | MappingStatus.UNMAPPED, | ||||
[ | [ | ||||
RawExtrinsicMetadata( | RawExtrinsicMetadata( | ||||
type=MetadataTargetType.CONTENT, | target=ExtendedSWHID.from_string( | ||||
target=parse_swhid( | |||||
"swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa" | "swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa" | ||||
), | ), | ||||
discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | ||||
authority=AUTHORITY, | authority=AUTHORITY, | ||||
fetcher=FETCHER, | fetcher=FETCHER, | ||||
format="clearlydefined-harvest-licensee-json", | format="clearlydefined-harvest-licensee-json", | ||||
origin=None, | origin=None, | ||||
metadata=json.dumps( | metadata=json.dumps( | ||||
Show All 19 Lines | |||||
def test_map_row_for_licensee_true_mapping_status(swh_storage, datadir): | def test_map_row_for_licensee_true_mapping_status(swh_storage, datadir): | ||||
add_content_data(swh_storage) | add_content_data(swh_storage) | ||||
expected = ( | expected = ( | ||||
MappingStatus.MAPPED, | MappingStatus.MAPPED, | ||||
[ | [ | ||||
RawExtrinsicMetadata( | RawExtrinsicMetadata( | ||||
type=MetadataTargetType.CONTENT, | target=ExtendedSWHID.from_string( | ||||
target=parse_swhid( | |||||
"swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa" | "swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa" | ||||
), | ), | ||||
discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | ||||
authority=AUTHORITY, | authority=AUTHORITY, | ||||
fetcher=FETCHER, | fetcher=FETCHER, | ||||
format="clearlydefined-harvest-licensee-json", | format="clearlydefined-harvest-licensee-json", | ||||
origin=None, | origin=None, | ||||
metadata=json.dumps( | metadata=json.dumps( | ||||
Show All 19 Lines | |||||
def test_map_row_for_clearlydefined(swh_storage, datadir): | def test_map_row_for_clearlydefined(swh_storage, datadir): | ||||
add_content_data(swh_storage) | add_content_data(swh_storage) | ||||
expected = ( | expected = ( | ||||
MappingStatus.UNMAPPED, | MappingStatus.UNMAPPED, | ||||
[ | [ | ||||
RawExtrinsicMetadata( | RawExtrinsicMetadata( | ||||
type=MetadataTargetType.CONTENT, | target=ExtendedSWHID.from_string( | ||||
target=parse_swhid( | |||||
"swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa" | "swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa" | ||||
), | ), | ||||
discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | ||||
authority=AUTHORITY, | authority=AUTHORITY, | ||||
fetcher=FETCHER, | fetcher=FETCHER, | ||||
format="clearlydefined-harvest-clearlydefined-json", | format="clearlydefined-harvest-clearlydefined-json", | ||||
origin=None, | origin=None, | ||||
metadata=json.dumps( | metadata=json.dumps( | ||||
json.loads( | json.loads( | ||||
file_data(os.path.join(datadir, "clearlydefined_metadata.json")) | file_data(os.path.join(datadir, "clearlydefined_metadata.json")) | ||||
) | ) | ||||
).encode("utf-8"), | ).encode("utf-8"), | ||||
), | ), | ||||
RawExtrinsicMetadata( | RawExtrinsicMetadata( | ||||
type=MetadataTargetType.CONTENT, | target=ExtendedSWHID.from_string( | ||||
target=parse_swhid( | |||||
"swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd" | "swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd" | ||||
), | ), | ||||
discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | ||||
authority=AUTHORITY, | authority=AUTHORITY, | ||||
fetcher=FETCHER, | fetcher=FETCHER, | ||||
format="clearlydefined-harvest-clearlydefined-json", | format="clearlydefined-harvest-clearlydefined-json", | ||||
origin=None, | origin=None, | ||||
metadata=json.dumps( | metadata=json.dumps( | ||||
Show All 21 Lines | |||||
def test_map_row_for_clearlydefined_true_mapping_status(swh_storage, datadir): | def test_map_row_for_clearlydefined_true_mapping_status(swh_storage, datadir): | ||||
add_content_data(swh_storage) | add_content_data(swh_storage) | ||||
expected = ( | expected = ( | ||||
MappingStatus.MAPPED, | MappingStatus.MAPPED, | ||||
[ | [ | ||||
RawExtrinsicMetadata( | RawExtrinsicMetadata( | ||||
type=MetadataTargetType.CONTENT, | target=ExtendedSWHID.from_string( | ||||
target=parse_swhid( | |||||
"swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa" | "swh:1:cnt:36fade77193cb6d2bd826161a0979d64c28ab4fa" | ||||
), | ), | ||||
discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | ||||
authority=AUTHORITY, | authority=AUTHORITY, | ||||
fetcher=FETCHER, | fetcher=FETCHER, | ||||
format="clearlydefined-harvest-clearlydefined-json", | format="clearlydefined-harvest-clearlydefined-json", | ||||
origin=None, | origin=None, | ||||
metadata=json.dumps( | metadata=json.dumps( | ||||
json.loads( | json.loads( | ||||
file_data(os.path.join(datadir, "clearlydefined_metadata.json")) | file_data(os.path.join(datadir, "clearlydefined_metadata.json")) | ||||
) | ) | ||||
).encode("utf-8"), | ).encode("utf-8"), | ||||
), | ), | ||||
RawExtrinsicMetadata( | RawExtrinsicMetadata( | ||||
type=MetadataTargetType.CONTENT, | target=ExtendedSWHID.from_string( | ||||
target=parse_swhid( | |||||
"swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd" | "swh:1:cnt:d81cc0710eb6cf9efd5b920a8453e1e07157b6cd" | ||||
), | ), | ||||
discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | discovery_date=datetime(year=2021, month=2, day=6, tzinfo=timezone.utc), | ||||
authority=AUTHORITY, | authority=AUTHORITY, | ||||
fetcher=FETCHER, | fetcher=FETCHER, | ||||
format="clearlydefined-harvest-clearlydefined-json", | format="clearlydefined-harvest-clearlydefined-json", | ||||
origin=None, | origin=None, | ||||
metadata=json.dumps( | metadata=json.dumps( | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |