Clean up code

- Remove unneeded return instructions
- Clarify tests code regarding request_index computations
This commit is contained in:
Antoine R. Dumont (@ardumont) 2019-06-24 18:06:28 +02:00
parent 45428c25df
commit 5ec3067b0d
No known key found for this signature in database
GPG key ID: 52E2E9840D10C3B8
4 changed files with 12 additions and 21 deletions

View file

@ -148,8 +148,6 @@ class IndexingLister(ListerBase):
t = self.db_session.query(func.min(self.MODEL.indexable)).first()
if t:
return t[0]
else:
return None
def db_last_index(self):
"""Look in the db for the largest indexable value
@ -160,8 +158,6 @@ class IndexingLister(ListerBase):
t = self.db_session.query(func.max(self.MODEL.indexable)).first()
if t:
return t[0]
else:
return None
def disable_deleted_repo_tasks(self, start, end, keep_these):
"""Disable tasks for repos that no longer exist between start and end.

View file

@ -67,8 +67,6 @@ class HttpListerTesterBase(abc.ABC):
m = self.test_re.search(request.path_url)
if m and (len(m.groups()) > 0):
return m.group(1)
else:
return None
def mock_response(self, request, context):
self.fl.reset_backoff()
@ -76,16 +74,17 @@ class HttpListerTesterBase(abc.ABC):
context.status_code = 200
custom_headers = self.response_headers(request)
context.headers.update(custom_headers)
if self.request_index(request) == str(self.first_index):
with open('swh/lister/%s/tests/%s' % (self.lister_subdir,
self.good_api_response_file),
'r', encoding='utf-8') as r:
return r.read()
req_index = self.request_index(request)
if req_index == str(self.first_index):
response_file = self.good_api_response_file
else:
with open('swh/lister/%s/tests/%s' % (self.lister_subdir,
self.bad_api_response_file),
'r', encoding='utf-8') as r:
return r.read()
response_file = self.bad_api_response_file
with open('swh/lister/%s/tests/%s' % (self.lister_subdir,
response_file),
'r', encoding='utf-8') as r:
return r.read()
def mock_limit_n_response(self, n, request, context):
self.fl.reset_backoff()

View file

@ -34,15 +34,12 @@ class GitHubLister(IndexingHttpLister):
reset_at = int(response.headers['X-RateLimit-Reset'])
delay = min(reset_at - time.time(), 3600)
return True, delay
else:
return False, 0
return False, 0
def get_next_target_from_response(self, response):
if 'next' in response.links:
next_url = response.links['next']['url']
return int(self.API_URL_INDEX_RE.match(next_url).group(1))
else:
return None
def transport_response_simplified(self, response):
repos = response.json()

View file

@ -91,8 +91,7 @@ class PhabricatorLister(IndexingHttpLister):
body = response.json()['result']['cursor']
if body['after'] != 'null':
return body['after']
else:
return None
return None
def transport_response_simplified(self, response):
repos = response.json()