swh_scheduler = <swh.scheduler.backend.SchedulerBackend object at 0x7fa5990506a0>
requests_mock = <requests_mock.mocker.Mocker object at 0x7fa599050b00>
datadir = '/var/lib/jenkins/workspace/DLS/tests-on-diff/.tox/py3/lib/python3.7/site-packages/swh/lister/gitlab/tests/data'
mocker = <pytest_mock.plugin.MockerFixture object at 0x7fa5990504a8>
def test_lister_gitlab_rate_limit(swh_scheduler, requests_mock, datadir, mocker):
"""Gitlab lister supports rate-limit
"""
instance = "gite.lirmm.fr"
url = api_url(instance)
lister = GitLabLister(swh_scheduler, url=url, instance=instance)
url_page1 = lister.page_url(1)
response1 = gitlab_page_response(datadir, instance, 1)
url_page2 = lister.page_url(2)
response2 = gitlab_page_response(datadir, instance, 2)
requests_mock.get(
url_page1,
[{"json": response1, "headers": {"Link": f"<{url_page2}>; rel=next"}}],
additional_matcher=_match_request,
)
requests_mock.get(
url_page2,
[
# rate limited twice
{"status_code": codes.forbidden, "headers": {"RateLimit-Remaining": "0"}},
{"status_code": codes.forbidden, "headers": {"RateLimit-Remaining": "0"}},
# ok
{"json": response2},
],
additional_matcher=_match_request,
)
# To avoid this test being too slow, we mock sleep within the retry behavior
mock_sleep = mocker.patch.object(lister.get_page_result.retry, "sleep")
> listed_result = lister.run()
.tox/py3/lib/python3.7/site-packages/swh/lister/gitlab/tests/test_lister.py:193:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.tox/py3/lib/python3.7/site-packages/swh/lister/pattern.py:123: in run
full_stats.origins += self.send_origins(origins)
.tox/py3/lib/python3.7/site-packages/swh/lister/pattern.py:224: in send_origins
ret = self.scheduler.record_listed_origins(origins)
.tox/py3/lib/python3.7/site-packages/swh/core/db/common.py:62: in _meth
return meth(self, *args, db=db, cur=cur, **kwargs)
.tox/py3/lib/python3.7/site-packages/swh/scheduler/backend.py:253: in record_listed_origins
fetch=True,
.tox/py3/lib/python3.7/site-packages/psycopg2/extras.py:1284: in execute_values
for page in _paginate(argslist, page_size=page_size):
.tox/py3/lib/python3.7/site-packages/psycopg2/extras.py:1178: in _paginate
page.append(next(it))
.tox/py3/lib/python3.7/site-packages/swh/scheduler/backend.py:250: in <genexpr>
argslist=(attr.asdict(origin) for origin in listed_origins),
.tox/py3/lib/python3.7/site-packages/swh/lister/gitlab/lister.py:180: in get_origins_from_page
last_update=repo["last_activity_at"],
<attrs generated init swh.scheduler.model.ListedOrigin>:18: in __init__
__attr_validator_last_update(self, __attr_last_update, self.last_update)
.tox/py3/lib/python3.7/site-packages/attr/_make.py:2723: in __call__
v(inst, attr, value)
.tox/py3/lib/python3.7/site-packages/attrs_strict/_type_validation.py:95: in _validator
_validate_elements(attribute, field, attribute.type)
.tox/py3/lib/python3.7/site-packages/attrs_strict/_type_validation.py:123: in _validate_elements
_handle_union(attribute, value, expected_type)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
attribute = Attribute(name='last_update', default=None, validator=_AndValidator(_validators=(<function type_validator.<locals>._va...y({}), type=typing.Union[datetime.datetime, NoneType], converter=None, kw_only=False, inherited=False, on_setattr=None)
value = '2021-01-14T11:32:50.672Z'
expected_type = typing.Union[datetime.datetime, NoneType]
def _handle_union(attribute, value, expected_type):
union_has_none_type = any(
elem is None.__class__ for elem in expected_type.__args__
)
if value is None and union_has_none_type:
return
for arg in expected_type.__args__:
try:
_validate_elements(attribute, value, arg)
return
except ValueError:
pass
> raise UnionError(value, attribute.name, expected_type)
E attrs_strict._error.UnionError: Value of last_update 2021-01-14T11:32:50.672Z is not of type typing.Union[datetime.datetime, NoneType]
.tox/py3/lib/python3.7/site-packages/attrs_strict/_type_validation.py:248: UnionError
TEST RESULT
TEST RESULT
- Run At
- Jan 25 2021, 6:44 PM