datadir = '/var/lib/jenkins/workspace/DLDBASE/tests-on-diff/.tox/py3/lib/python3.7/site-packages/swh/loader/package/crates/tests/data'
requests_mock_datadir = <requests_mock.mocker.Mocker object at 0x7f2549cf6358>
swh_storage = <swh.storage.proxies.retry.RetryingProxyStorage object at 0x7f2549cf6518>
expected = [{'artifacts': [{'checksums': {'sha256': '48a45b46c2a8c38348adb1205b13c3c5eb0174e0c0fec52cc88e9fb1de14c54d'}, 'filenam...38:33.047581+00:00', 'version': '0.3.0', 'yanked': False}, ...], 'url': 'https://crates.io/api/v1/crates/micro-timer'}]
def test_crates_loader_load_one_version(
datadir, requests_mock_datadir, swh_storage, expected
):
loader = CratesLoader(
swh_storage,
url=expected[0]["url"],
artifacts=expected[0]["artifacts"],
crates_metadata=expected[0]["crates_metadata"],
)
actual_load_status = loader.load()
assert actual_load_status["status"] == "eventful"
assert actual_load_status["snapshot_id"] is not None
expected_snapshot_id = "779fa94645a772fb9992c2bf80bf5e2ecfdb1b5c"
expected_release_id = "bb6f9b125867a8b4fa0b2febf890a317744e0140"
assert expected_snapshot_id == actual_load_status["snapshot_id"]
expected_snapshot = Snapshot(
id=hash_to_bytes(actual_load_status["snapshot_id"]),
branches={
b"releases/0.0.1/hg-core-0.0.1.crate": SnapshotBranch(
target=hash_to_bytes(expected_release_id),
target_type=TargetType.RELEASE,
),
b"HEAD": SnapshotBranch(
target=b"releases/0.0.1/hg-core-0.0.1.crate",
target_type=TargetType.ALIAS,
),
},
)
check_snapshot(expected_snapshot, swh_storage)
stats = get_stats(swh_storage)
assert {
"content": 1,
"directory": 2,
"origin": 1,
"origin_visit": 1,
"release": 1,
"revision": 0,
"skipped_content": 0,
"snapshot": 1,
} == stats
release = swh_storage.release_get([hash_to_bytes(expected_release_id)])[0]
assert release == Release(
name=b"0.0.1",
message=b"Synthetic release for Crate source package hg-core version 0.0.1\n",
target=hash_to_bytes("674c3b0b54628d55b93a79dc7adf304efc01b371"),
target_type=ObjectType.DIRECTORY,
synthetic=True,
author=Person.from_fullname(b"Georges Racinet <georges.racinet@octobus.net>"),
date=TimestampWithTimezone.from_iso8601("2019-04-16T18:48:11.404457+00:00"),
id=hash_to_bytes(expected_release_id),
)
release_swhid = CoreSWHID(
object_type=OType.RELEASE, object_id=hash_to_bytes(expected_release_id)
)
directory_swhid = ExtendedSWHID(
object_type=ExtendedObjectType.DIRECTORY, object_id=release.target
)
metadata_authority = MetadataAuthority(
type=MetadataAuthorityType.FORGE,
url="https://crates.io/",
)
expected_metadata = [
RawExtrinsicMetadata(
target=directory_swhid,
authority=metadata_authority,
fetcher=MetadataFetcher(
name="swh.loader.package.crates.loader.CratesLoader",
version=__version__,
),
discovery_date=loader.visit_date,
format="original-artifacts-json",
metadata=json.dumps(
[
{
"checksums": {
"sha256": "48a45b46c2a8c38348adb1205b13c3c5eb0174e0c0fec52cc88e9fb1de14c54d" # noqa: B950
},
"filename": "hg-core-0.0.1.crate",
"url": "https://static.crates.io/crates/hg-core/hg-core-0.0.1.crate", # noqa: B950
}
]
).encode(),
origin=expected[0]["url"],
release=release_swhid,
),
RawExtrinsicMetadata(
target=directory_swhid,
authority=metadata_authority,
fetcher=MetadataFetcher(
name="swh.loader.package.crates.loader.CratesLoader",
version=__version__,
),
discovery_date=loader.visit_date,
format="crates-package-json",
metadata=json.dumps(
[{"yanked": False, "last_update": "2019-04-16T18:48:11.404457+00:00"}]
).encode(),
origin=expected[0]["url"],
release=release_swhid,
),
]
> assert swh_storage.raw_extrinsic_metadata_get(
directory_swhid,
metadata_authority,
) == PagedResult(
next_page_token=None,
results=expected_metadata,
)
E assert PagedResult(results=[RawExtrinsicMetadata(target=ExtendedSWHID.from_string('swh:1:dir:674c3b0b54628d55b93a79dc7adf304efc01b371'), discovery_date=datetime.datetime(2022, 10, 7, 5, 50, 55, tzinfo=datetime.timezone.utc), authority=MetadataAuthority(type=MetadataAuthorityType.FORGE, url='https://crates.io/', metadata=None), fetcher=MetadataFetcher(name='swh.loader.package.crates.loader.CratesLoader', version='4.2.1.dev19+g818c349', metadata=None), format='crates-package-json', metadata=b'[{"yanked": false, "last_update": "2019-04-16T18:48:11.404457+00:00"}]', origin='https://crates.io/api/v1/crates/hg-core', visit=None, snapshot=None, release=CoreSWHID.from_string('swh:1:rel:bb6f9b125867a8b4fa0b2febf890a317744e0140'), revision=None, path=None, directory=None, id=hash_to_bytes('7f1b113f3d134bc7d8ca2c9daa16160a7e7f7f8e')), RawExtrinsicMetadata(target=ExtendedSWHID.from_string('swh:1:dir:674c3b0b54628d55b93a79dc7adf304efc01b371'), discovery_date=datetime.datetime(2022, 10, 7, 5, 50, 55, tzinfo=datetime.timezone.utc), authority=MetadataAuthority(type=MetadataAuthorityType.FORGE, url='https://crates.io/', metadata=None), fetcher=MetadataFetcher(name='swh.loader.package.crates.loader.CratesLoader', version='4.2.1.dev19+g818c349', metadata=None), format='original-artifacts-json', metadata=b'[{"checksums": {"sha256": "48a45b46c2a8c38348adb1205b13c3c5eb0174e0c0fec52cc88e9fb1de14c54d"}, "filename": "hg-core-0.0.1.crate", "url": "https://static.crates.io/crates/hg-core/hg-core-0.0.1.crate"}]', origin='https://crates.io/api/v1/crates/hg-core', visit=None, snapshot=None, release=CoreSWHID.from_string('swh:1:rel:bb6f9b125867a8b4fa0b2febf890a317744e0140'), revision=None, path=None, directory=None, id=hash_to_bytes('d8b56a31a92f1887bd3912a226e8729f12b8e488'))], next_page_token=None) == PagedResult(results=[RawExtrinsicMetadata(target=ExtendedSWHID.from_string('swh:1:dir:674c3b0b54628d55b93a79dc7adf304efc01b371'), discovery_date=datetime.datetime(2022, 10, 7, 5, 50, 55, tzinfo=datetime.timezone.utc), authority=MetadataAuthority(type=MetadataAuthorityType.FORGE, url='https://crates.io/', metadata=None), fetcher=MetadataFetcher(name='swh.loader.package.crates.loader.CratesLoader', version='4.2.1.dev19+g818c349', metadata=None), format='original-artifacts-json', metadata=b'[{"checksums": {"sha256": "48a45b46c2a8c38348adb1205b13c3c5eb0174e0c0fec52cc88e9fb1de14c54d"}, "filename": "hg-core-0.0.1.crate", "url": "https://static.crates.io/crates/hg-core/hg-core-0.0.1.crate"}]', origin='https://crates.io/api/v1/crates/hg-core', visit=None, snapshot=None, release=CoreSWHID.from_string('swh:1:rel:bb6f9b125867a8b4fa0b2febf890a317744e0140'), revision=None, path=None, directory=None, id=hash_to_bytes('d8b56a31a92f1887bd3912a226e8729f12b8e488')), RawExtrinsicMetadata(target=ExtendedSWHID.from_string('swh:1:dir:674c3b0b54628d55b93a79dc7adf304efc01b371'), discovery_date=datetime.datetime(2022, 10, 7, 5, 50, 55, tzinfo=datetime.timezone.utc), authority=MetadataAuthority(type=MetadataAuthorityType.FORGE, url='https://crates.io/', metadata=None), fetcher=MetadataFetcher(name='swh.loader.package.crates.loader.CratesLoader', version='4.2.1.dev19+g818c349', metadata=None), format='crates-package-json', metadata=b'[{"yanked": false, "last_update": "2019-04-16T18:48:11.404457+00:00"}]', origin='https://crates.io/api/v1/crates/hg-core', visit=None, snapshot=None, release=CoreSWHID.from_string('swh:1:rel:bb6f9b125867a8b4fa0b2febf890a317744e0140'), revision=None, path=None, directory=None, id=hash_to_bytes('7f1b113f3d134bc7d8ca2c9daa16160a7e7f7f8e'))], next_page_token=None)
E
E Matching attributes:
E ['next_page_token']
E Differing attributes:
E ['results']
E
E Drill down into differing attribute results:
E results: [RawExtrinsicMetadata(target=ExtendedSWHID.from_string('swh:1:dir:674c3b0b54628d55b93a79dc7adf304efc01b371'), discovery_date=datetime.datetime(2022, 10, 7, 5, 50, 55, tzinfo=datetime.timezone.utc), authority=MetadataAuthority(type=MetadataAuthorityType.FORGE, url='https://crates.io/', metadata=None), fetcher=MetadataFetcher(name='swh.loader.package.crates.loader.CratesLoader', version='4.2.1.dev19+g818c349', metadata=None), format='crates-package-json', metadata=b'[{"yanked": false, "last_update": "2019-04-16T18:48:11.404457+00:00"}]', origin='https://crates.io/api/v1/crates/hg-core', visit=None, snapshot=None, release=CoreSWHID.from_string('swh:1:rel:bb6f9b125867a8b4fa0b2febf890a317744e0140'), revision=None, path=None, directory=None, id=hash_to_bytes('7f1b113f3d134bc7d8ca2c9daa16160a7e7f7f8e')), RawExtrinsicMetadata(target=ExtendedSWHID.from_string('swh:1:dir:674c3b0b54628d55b93a79dc7adf304efc01b371'), discovery_date=datetime.datetime(2022, 10, 7, 5, 50, 55, tzinfo=datetime.timezone.utc), authority=MetadataAuthority(type=MetadataAuthorityType.FORGE, url='https://crates.io/', metadata=None), fetcher=MetadataFetcher(name='swh.loader.package.crates.loader.CratesLoader', version='4.2.1.dev19+g818c349', metadata=None), format='original-artifacts-json', metadata=b'[{"checksums": {"sha256": "48a45b46c2a8c38348adb1205b13c3c5eb0174e0c0fec52cc88e9fb1de14c54d"}, "filename": "hg-core-0.0.1.crate", "url": "https://static.crates.io/crates/hg-core/hg-core-0.0.1.crate"}]', origin='https://crates.io/api/v1/crates/hg-core', visit=None, snapshot=None, release=CoreSWHID.from_string('swh:1:rel:bb6f9b125867a8b4fa0b2febf890a317744e0140'), revision=None, path=None, directory=None, id=hash_to_bytes('d8b56a31a92f1887bd3912a226e8729f12b8e488'))] != [RawExtrinsicMetadata(target=ExtendedSWHID.from_string('swh:1:dir:674c3b0b54628d55b93a79dc7adf304efc01b371'), discovery_date=datetime.datetime(2022, 10, 7, 5, 50, 55, tzinfo=datetime.timezone.utc), authority=MetadataAuthority(type=MetadataAuthorityType.FORGE, url='https://crates.io/', metadata=None), fetcher=MetadataFetcher(name='swh.loader.package.crates.loader.CratesLoader', version='4.2.1.dev19+g818c349', metadata=None), format='original-artifacts-json', metadata=b'[{"checksums": {"sha256": "48a45b46c2a8c38348adb1205b13c3c5eb0174e0c0fec52cc88e9fb1de14c54d"}, "filename": "hg-core-0.0.1.crate", "url": "https://static.crates.io/crates/hg-core/hg-core-0.0.1.crate"}]', origin='https://crates.io/api/v1/crates/hg-core', visit=None, snapshot=None, release=CoreSWHID.from_string('swh:1:rel:bb6f9b125867a8b4fa0b2febf890a317744e0140'), revision=None, path=None, directory=None, id=hash_to_bytes('d8b56a31a92f1887bd3912a226e8729f12b8e488')), RawExtrinsicMetadata(target=ExtendedSWHID.from_string('swh:1:dir:674c3b0b54628d55b93a79dc7adf304efc01b371'), discovery_date=datetime.datetime(2022, 10, 7, 5, 50, 55, tzinfo=datetime.timezone.utc), authority=MetadataAuthority(type=MetadataAuthorityType.FORGE, url='https://crates.io/', metadata=None), fetcher=MetadataFetcher(name='swh.loader.package.crates.loader.CratesLoader', version='4.2.1.dev19+g818c349', metadata=None), format='crates-package-json', metadata=b'[{"yanked": false, "last_update": "2019-04-16T18:48:11.404457+00:00"}]', origin='https://crates.io/api/v1/crates/hg-core', visit=None, snapshot=None, release=CoreSWHID.from_string('swh:1:rel:bb6f9b125867a8b4fa0b2febf890a317744e0140'), revision=None, path=None, directory=None, id=hash_to_bytes('7f1b113f3d134bc7d8ca2c9daa16160a7e7f7f8e'))]
E At index 0 diff: RawExtrinsicMetadata(target=ExtendedSWHID.from_string('swh:1:dir:674c3b0b54628d55b93a79dc7adf304efc01b371'), discovery_date=datetime.datetime(2022, 10, 7, 5, 50, 55, tzinfo=datetime.timezone.utc), authority=MetadataAuthority(type=MetadataAuthorityType.FORGE, url='https://crates.io/', metadata=None), fetcher=MetadataFetcher(name='swh.loader.package.crates.loader.CratesLoader', version='4.2.1.dev19+g818c349', metadata=None), format='crates-package-json', metadata=b'[{"yanked": false, "last_update": "2019-04-16T18:48:11.404457+00:00"}]', origin='https://crates.io/api/v1/crates/hg-core', visit=None, snapshot=None, release=CoreSWHID.from_string('swh:1:rel:bb6f9b125867a8b4fa0b2febf890a317744e0140'), revision=None, path=None, directory=None, id=hash_to_bytes('7f1b113f3d134bc7d8ca2c9daa16160a7e7f7f8e')) != RawExtrinsicMetadata(target=ExtendedSWHID.from_string('swh:1:dir:674c3b0b54628d55b93a79dc7adf304efc01b371'), discovery_date=datetime.datetime(2022, 10, 7, 5, 50, 55, tzinfo=datetime.timezone.utc), authority=MetadataAuthority(type=MetadataAuthorityType.FORGE, url='https://crates.io/', metadata=None), fetcher=MetadataFetcher(name='swh.loader.package.crates.loader.CratesLoader', version='4.2.1.dev19+g818c349', metadata=None), format='original-artifacts-json', metadata=b'[{"checksums": {"sha256": "48a45b46c2a8c38348adb1205b13c3c5eb0174e0c0fec52cc88e9fb1de14c54d"}, "filename": "hg-core-0.0.1.crate", "url": "https://static.crates.io/crates/hg-core/hg-core-0.0.1.crate"}]', origin='https://crates.io/api/v1/crates/hg-core', visit=None, snapshot=None, release=CoreSWHID.from_string('swh:1:rel:bb6f9b125867a8b4fa0b2febf890a317744e0140'), revision=None, path=None, directory=None, id=hash_to_bytes('d8b56a31a92f1887bd3912a226e8729f12b8e488'))
E Full diff:
E [
E + RawExtrinsicMetadata(target=ExtendedSWHID.from_string('swh:1:dir:674c3b0b54628d55b93a79dc7adf304efc01b371'), discovery_date=datetime.datetime(2022, 10, 7, 5, 50, 55, tzinfo=datetime.timezone.utc), authority=MetadataAuthority(type=MetadataAuthorityType.FORGE, url='https://crates.io/', metadata=None), fetcher=MetadataFetcher(name='swh.loader.package.crates.loader.CratesLoader', version='4.2.1.dev19+g818c349', metadata=None), format='crates-package-json', metadata=b'[{"yanked": false, "last_update": "2019-04-16T18:48:11.404457+00:00"}]', origin='https://crates.io/api/v1/crates/hg-core', visit=None, snapshot=None, release=CoreSWHID.from_string('swh:1:rel:bb6f9b125867a8b4fa0b2febf890a317744e0140'), revision=None, path=None, directory=None, id=hash_to_bytes('7f1b113f3d134bc7d8ca2c9daa16160a7e7f7f8e')),
E RawExtrinsicMetadata(target=ExtendedSWHID.from_string('swh:1:dir:674c3b0b54628d55b93a79dc7adf304efc01b371'), discovery_date=datetime.datetime(2022, 10, 7, 5, 50, 55, tzinfo=datetime.timezone.utc), authority=MetadataAuthority(type=MetadataAuthorityType.FORGE, url='https://crates.io/', metadata=None), fetcher=MetadataFetcher(name='swh.loader.package.crates.loader.CratesLoader', version='4.2.1.dev19+g818c349', metadata=None), format='original-artifacts-json', metadata=b'[{"checksums": {"sha256": "48a45b46c2a8c38348adb1205b13c3c5eb0174e0c0fec52cc88e9fb1de14c54d"}, "filename": "hg-core-0.0.1.crate", "url": "https://static.crates.io/crates/hg-core/hg-core-0.0.1.crate"}]', origin='https://crates.io/api/v1/crates/hg-core', visit=None, snapshot=None, release=CoreSWHID.from_string('swh:1:rel:bb6f9b125867a8b4fa0b2febf890a317744e0140'), revision=None, path=None, directory=None, id=hash_to_bytes('d8b56a31a92f1887bd3912a226e8729f12b8e488')),
E - RawExtrinsicMetadata(target=ExtendedSWHID.from_string('swh:1:dir:674c3b0b54628d55b93a79dc7adf304efc01b371'), discovery_date=datetime.datetime(2022, 10, 7, 5, 50, 55, tzinfo=datetime.timezone.utc), authority=MetadataAuthority(type=MetadataAuthorityType.FORGE, url='https://crates.io/', metadata=None), fetcher=MetadataFetcher(name='swh.loader.package.crates.loader.CratesLoader', version='4.2.1.dev19+g818c349', metadata=None), format='crates-package-json', metadata=b'[{"yanked": false, "last_update": "2019-04-16T18:48:11.404457+00:00"}]', origin='https://crates.io/api/v1/crates/hg-core', visit=None, snapshot=None, release=CoreSWHID.from_string('swh:1:rel:bb6f9b125867a8b4fa0b2febf890a317744e0140'), revision=None, path=None, directory=None, id=hash_to_bytes('7f1b113f3d134bc7d8ca2c9daa16160a7e7f7f8e')),
E ]
.tox/py3/lib/python3.7/site-packages/swh/loader/package/crates/tests/test_crates.py:207: AssertionError
TEST RESULT
TEST RESULT
- Run At
- Oct 7 2022, 7:51 AM