Use a uniform User-Agent on all listers
This also adds tests to make sure that we properly send our version number to upstreams.
This commit is contained in:
parent
62dc4dc257
commit
ff7fdf24db
9 changed files with 48 additions and 8 deletions
|
@ -13,6 +13,7 @@ from requests.adapters import HTTPAdapter
|
|||
from .models import CGitModel
|
||||
|
||||
from swh.core.utils import grouper
|
||||
from swh.lister import USER_AGENT
|
||||
from swh.lister.core.lister_base import ListerBase
|
||||
|
||||
|
||||
|
@ -72,6 +73,9 @@ class CGitLister(ListerBase):
|
|||
self.instance = instance
|
||||
self.session = Session()
|
||||
self.session.mount(self.url, HTTPAdapter(max_retries=3))
|
||||
self.session.headers = {
|
||||
'User-Agent': USER_AGENT,
|
||||
}
|
||||
|
||||
def run(self):
|
||||
total = 0
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
# See top-level LICENSE file for more information
|
||||
|
||||
|
||||
from swh.lister import __version__
|
||||
|
||||
|
||||
def test_lister_no_page(requests_mock_datadir, swh_listers):
|
||||
lister = swh_listers['cgit']
|
||||
|
||||
|
@ -64,3 +67,16 @@ def test_lister_run(requests_mock_datadir, swh_listers):
|
|||
assert kwargs == {}
|
||||
assert row['policy'] == 'recurring'
|
||||
assert row['priority'] is None
|
||||
|
||||
|
||||
def test_lister_requests(requests_mock_datadir, swh_listers):
|
||||
lister = swh_listers['cgit']
|
||||
lister.url = 'https://git.tizen/cgit/'
|
||||
lister.run()
|
||||
|
||||
assert len(requests_mock_datadir.request_history) != 0
|
||||
for request in requests_mock_datadir.request_history:
|
||||
assert 'User-Agent' in request.headers
|
||||
user_agent = request.headers['User-Agent']
|
||||
assert 'Software Heritage Lister' in user_agent
|
||||
assert __version__ in user_agent
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue