Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/tests/test_loader.py
# Copyright (C) 2019-2021 The Software Heritage developers | # Copyright (C) 2019-2021 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 | ||||
import hashlib | import hashlib | ||||
import logging | import logging | ||||
import string | import string | ||||
from unittest.mock import Mock, call, patch | from unittest.mock import Mock, call, patch | ||||
import attr | import attr | ||||
import pytest | import pytest | ||||
from swh.loader.core.loader import ( | |||||
SENTRY_ORIGIN_URL_TAG_NAME, | |||||
SENTRY_VISIT_TYPE_TAG_NAME, | |||||
) | |||||
from swh.loader.package.loader import BasePackageInfo, PackageLoader | from swh.loader.package.loader import BasePackageInfo, PackageLoader | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Origin, | Origin, | ||||
OriginVisit, | OriginVisit, | ||||
OriginVisitStatus, | OriginVisitStatus, | ||||
Person, | Person, | ||||
Release, | Release, | ||||
Revision, | Revision, | ||||
▲ Show 20 Lines • Show All 490 Lines • ▼ Show 20 Lines | class DummyPackageLoader(PackageLoader): | ||||
pass | pass | ||||
monkeypatch.delenv("SWH_CONFIG_FILENAME", raising=False) | monkeypatch.delenv("SWH_CONFIG_FILENAME", raising=False) | ||||
with pytest.raises( | with pytest.raises( | ||||
AssertionError, match="SWH_CONFIG_FILENAME environment variable is undefined" | AssertionError, match="SWH_CONFIG_FILENAME environment variable is undefined" | ||||
): | ): | ||||
DummyPackageLoader.from_configfile(url="some-url") | DummyPackageLoader.from_configfile(url="some-url") | ||||
class StubPackageLoaderWithError(StubPackageLoader): | |||||
def get_versions(self, *args, **kwargs): | |||||
raise Exception("error") | |||||
def test_loader_sentry_tags_on_error(swh_storage, sentry_events): | |||||
origin_url = "http://example.org/package/name" | |||||
loader = StubPackageLoaderWithError(swh_storage, origin_url) | |||||
loader.load() | |||||
sentry_tags = sentry_events[0]["tags"] | |||||
assert sentry_tags.get(SENTRY_ORIGIN_URL_TAG_NAME) == origin_url | |||||
assert ( | |||||
sentry_tags.get(SENTRY_VISIT_TYPE_TAG_NAME) | |||||
== StubPackageLoaderWithError.visit_type | |||||
) |