Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/gogs/tests/test_lister.py
Show First 20 Lines • Show All 133 Lines • ▼ Show 20 Lines | ): | ||||
assert ( | assert ( | ||||
lister.get_state_from_scheduler().last_seen_next_link == P3 | lister.get_state_from_scheduler().last_seen_next_link == P3 | ||||
) # P3 didn't provide any next link so it remains the last_seen_next_link | ) # P3 didn't provide any next link so it remains the last_seen_next_link | ||||
def test_gogs_auth_instance( | def test_gogs_auth_instance( | ||||
swh_scheduler, requests_mock, trygogs_p1, trygogs_p2, trygogs_p3_empty | swh_scheduler, requests_mock, trygogs_p1, trygogs_p2, trygogs_p3_empty | ||||
): | ): | ||||
"""Covers token authentication, token from credentials, | """Covers without authentication, token authentication, token from credentials, | ||||
instance inference from URL.""" | instance inference from URL.""" | ||||
api_token = "secret" | api_token = "secret" | ||||
instance = "try_gogs" | instance = "try_gogs" | ||||
# Test lister initialization without api_token or credentials: | # Test lister initialization without api_token or credentials: | ||||
with pytest.raises(ValueError, match="No credentials or API token provided"): | |||||
kwargs1 = dict(url=TRY_GOGS_URL, instance=instance) | kwargs1 = dict(url=TRY_GOGS_URL, instance=instance) | ||||
GogsLister(scheduler=swh_scheduler, **kwargs1) | lister = GogsLister(scheduler=swh_scheduler, **kwargs1) | ||||
assert "Authorization" not in lister.session.headers | |||||
# Test lister initialization using api_token: | # Test lister initialization using api_token: | ||||
kwargs2 = dict(url=TRY_GOGS_URL, api_token=api_token, instance=instance) | kwargs2 = dict(url=TRY_GOGS_URL, api_token=api_token, instance=instance) | ||||
lister = GogsLister(scheduler=swh_scheduler, **kwargs2) | lister = GogsLister(scheduler=swh_scheduler, **kwargs2) | ||||
assert lister.session.headers["Authorization"].lower() == "token %s" % api_token | assert lister.session.headers["Authorization"].lower() == "token %s" % api_token | ||||
# Test lister initialization with credentials and run it: | # Test lister initialization with credentials and run it: | ||||
creds = {"gogs": {instance: [{"username": "u", "password": api_token}]}} | creds = {"gogs": {instance: [{"username": "u", "password": api_token}]}} | ||||
▲ Show 20 Lines • Show All 171 Lines • Show Last 20 Lines |