Changeset View
Changeset View
Standalone View
Standalone View
swh/indexer/tests/test_metadata.py
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
DIRECTORY_METADATA_CONFIG = { | DIRECTORY_METADATA_CONFIG = { | ||||
**BASE_TEST_CONFIG, | **BASE_TEST_CONFIG, | ||||
"tools": TRANSLATOR_TOOL, | "tools": TRANSLATOR_TOOL, | ||||
} | } | ||||
DEPOSIT_REMD = RawExtrinsicMetadata( | DEPOSIT_REMD = RawExtrinsicMetadata( | ||||
target=ExtendedSWHID( | target=ExtendedSWHID( | ||||
object_type=ExtendedObjectType.ORIGIN, | object_type=ExtendedObjectType.DIRECTORY, | ||||
object_id=b"\x01" * 20, | object_id=b"\x02" * 20, | ||||
), | ), | ||||
discovery_date=datetime.datetime.now(tz=datetime.timezone.utc), | discovery_date=datetime.datetime.now(tz=datetime.timezone.utc), | ||||
authority=MetadataAuthority( | authority=MetadataAuthority( | ||||
type=MetadataAuthorityType.DEPOSIT_CLIENT, | type=MetadataAuthorityType.DEPOSIT_CLIENT, | ||||
url="https://example.org/", | url="https://example.org/", | ||||
), | ), | ||||
fetcher=MetadataFetcher( | fetcher=MetadataFetcher( | ||||
name="example-fetcher", | name="example-fetcher", | ||||
version="1.0.0", | version="1.0.0", | ||||
), | ), | ||||
format="sword-v2-atom-codemeta-v2", | format="sword-v2-atom-codemeta-v2", | ||||
metadata="""<?xml version="1.0"?> | metadata="""<?xml version="1.0"?> | ||||
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" | <atom:entry xmlns:atom="http://www.w3.org/2005/Atom" | ||||
xmlns="https://doi.org/10.5063/schema/codemeta-2.0"> | xmlns="https://doi.org/10.5063/schema/codemeta-2.0"> | ||||
<name>My Software</name> | <name>My Software</name> | ||||
<author> | <author> | ||||
<name>Author 1</name> | <name>Author 1</name> | ||||
<email>foo@example.org</email> | <email>foo@example.org</email> | ||||
</author> | </author> | ||||
<author> | <author> | ||||
<name>Author 2</name> | <name>Author 2</name> | ||||
</author> | </author> | ||||
</atom:entry> | </atom:entry> | ||||
""".encode(), | """.encode(), | ||||
origin="https://example.org/jdoe/myrepo", | |||||
) | ) | ||||
GITHUB_REMD = RawExtrinsicMetadata( | GITHUB_REMD = RawExtrinsicMetadata( | ||||
target=ExtendedSWHID( | target=ExtendedSWHID( | ||||
object_type=ExtendedObjectType.ORIGIN, | object_type=ExtendedObjectType.ORIGIN, | ||||
object_id=b"\x01" * 20, | object_id=b"\x01" * 20, | ||||
), | ), | ||||
discovery_date=datetime.datetime.now(tz=datetime.timezone.utc), | discovery_date=datetime.datetime.now(tz=datetime.timezone.utc), | ||||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | def test_extrinsic_metadata_indexer_firstparty_deposit(self, mocker): | ||||
) | ) | ||||
assert tool is not None | assert tool is not None | ||||
assert metadata_indexer.process_journal_objects( | assert metadata_indexer.process_journal_objects( | ||||
{"raw_extrinsic_metadata": [DEPOSIT_REMD.to_dict()]} | {"raw_extrinsic_metadata": [DEPOSIT_REMD.to_dict()]} | ||||
) == {"status": "eventful", "origin_extrinsic_metadata:add": 1} | ) == {"status": "eventful", "origin_extrinsic_metadata:add": 1} | ||||
assert metadata_indexer.storage.method_calls == [ | assert metadata_indexer.storage.method_calls == [ | ||||
call.origin_get_by_sha1([b"\x01" * 20]) | call.origin_get_by_sha1( | ||||
[b"\xb1\x0c\\\xd2w\x1b\xdd\xac\x07\xdb\xdf>\x93O1\xd0\xc9L\x0c\xcf"] | |||||
) | |||||
] | ] | ||||
results = list( | results = list( | ||||
metadata_indexer.idx_storage.origin_extrinsic_metadata_get([origin]) | metadata_indexer.idx_storage.origin_extrinsic_metadata_get([origin]) | ||||
) | ) | ||||
assert results == [ | assert results == [ | ||||
OriginExtrinsicMetadataRow( | OriginExtrinsicMetadataRow( | ||||
id="https://example.org/jdoe/myrepo", | id="https://example.org/jdoe/myrepo", | ||||
Show All 25 Lines | def test_extrinsic_metadata_indexer_thirdparty_deposit(self, mocker): | ||||
) | ) | ||||
assert tool is not None | assert tool is not None | ||||
assert metadata_indexer.process_journal_objects( | assert metadata_indexer.process_journal_objects( | ||||
{"raw_extrinsic_metadata": [DEPOSIT_REMD.to_dict()]} | {"raw_extrinsic_metadata": [DEPOSIT_REMD.to_dict()]} | ||||
) == {"status": "uneventful", "origin_extrinsic_metadata:add": 0} | ) == {"status": "uneventful", "origin_extrinsic_metadata:add": 0} | ||||
assert metadata_indexer.storage.method_calls == [ | assert metadata_indexer.storage.method_calls == [ | ||||
call.origin_get_by_sha1([b"\x01" * 20]) | call.origin_get_by_sha1( | ||||
[b"\xb1\x0c\\\xd2w\x1b\xdd\xac\x07\xdb\xdf>\x93O1\xd0\xc9L\x0c\xcf"] | |||||
) | |||||
] | ] | ||||
results = list( | results = list( | ||||
metadata_indexer.idx_storage.origin_extrinsic_metadata_get([origin]) | metadata_indexer.idx_storage.origin_extrinsic_metadata_get([origin]) | ||||
) | ) | ||||
assert results == [] | assert results == [] | ||||
def test_extrinsic_metadata_indexer_nonforge_authority(self, mocker): | def test_extrinsic_metadata_indexer_nonforge_authority(self, mocker): | ||||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |