newsletters: check response by status code instead of json attribute

This commit is contained in:
Serghei Mihai 2016-05-06 11:48:48 +02:00
parent 6ca4e35ce6
commit 5820af546d
2 changed files with 10 additions and 6 deletions

View File

@ -123,8 +123,8 @@ class NewslettersCell(CellBase):
endpoint = self.url + 'newsletters/'
url = get_signed_url(endpoint, self.url, **kwargs)
response = requests.get(url)
json_response = response.json()
if json_response['err'] == 0:
if response.ok:
json_response = response.json()
return self.filter_data(json_response['data'])
return []
@ -132,8 +132,8 @@ class NewslettersCell(CellBase):
endpoint = self.url + 'subscriptions/'
url = get_signed_url(endpoint, self.url, **kwargs)
response = requests.get(url)
json_response = response.json()
if json_response['err'] == 0:
if response.ok:
json_response = response.json()
return self.filter_data(json_response['data'])
return []

View File

@ -158,13 +158,17 @@ def mocked_requests_get(*args, **kwargs):
class MockResponse:
def __init__(self, json_data):
self.json_data = json_data
def ok(self):
return True
def json(self):
return self.json_data
if 'newsletters' in url:
return MockResponse({'err': 0, 'data': NEWSLETTERS})
return MockResponse({'data': NEWSLETTERS})
else:
return MockResponse({'err': 0, 'data': SUBSCRIPTIONS})
return MockResponse({'data': SUBSCRIPTIONS})
@mock.patch('combo.apps.newsletters.models.requests.get',
side_effect=mocked_requests_get)