Skip to content

Commit 2215257

Browse files
Quick fix to UsageAutomation._get_usage_template_download_location(): Before, the URL sent contained the path '/usage/files/usage/products/' instead of '/usage/files/'.
1 parent 4f5016b commit 2215257

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

connect/resource/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def _fix_request_kwargs(self, prev_kwargs, path, **kwargs):
7474
""" Set correct kwargs for requests """
7575
fixed_kwargs = prev_kwargs.copy()
7676
fixed_kwargs.update(kwargs)
77-
if 'get_url' not in fixed_kwargs:
78-
fixed_kwargs['get_url'] = self.get_url(path)
77+
if 'url' not in fixed_kwargs:
78+
fixed_kwargs['url'] = self.get_url(path)
7979
if 'headers' not in fixed_kwargs:
8080
fixed_kwargs['headers'] = self.headers
8181
return fixed_kwargs

connect/resource/usage_automation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def submit_usage(self, usage_file, usage_records):
153153
def _get_usage_template_download_location(self, product_id):
154154
# type: (str) -> str
155155
try:
156-
response = self.api.get(path='/usage/products/' + product_id + '/template/')
156+
response = self.api.get(url='{}/usage/products/{}/template/'
157+
.format(self.config.api_url, product_id))
157158
response_dict = json.loads(response)
158159
return response_dict['template_link']
159160
except (requests.exceptions.RequestException, KeyError, TypeError, ValueError):

tests/test_usage.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from datetime import date, timedelta
1111

1212
import pytest
13-
from mock import patch, MagicMock
13+
from mock import patch, MagicMock, call
1414

1515
from connect.models import usage
1616
from connect.models.exception import FileRetrievalError
@@ -47,12 +47,20 @@ def test_process():
4747
resource.process()
4848

4949

50-
@patch('requests.get', MagicMock(side_effect=[
51-
Response(ok=True, content='{"template_link": "..."}', status_code=200),
52-
Response(ok=True, content='template_contents', status_code=200)]))
53-
def test_get_usage_template_ok():
50+
@patch('requests.get')
51+
def test_get_usage_template_ok(get_mock):
52+
get_mock.side_effect = [
53+
Response(ok=True, content='{"template_link": "..."}', status_code=200),
54+
Response(ok=True, content='template_contents', status_code=200)]
5455
resource = UsageAutomation()
5556
assert resource.get_usage_template(Product(id='PRD-638-321-603')) == 'template_contents'
57+
get_mock.assert_has_calls([
58+
call(
59+
url='http://localhost:8080/api/public/v1//usage/products/PRD-638-321-603/template/',
60+
headers={'Content-Type': 'application/json', 'Authorization': 'ApiKey XXXX:YYYYY'},
61+
params=None),
62+
call('...')
63+
])
5664

5765

5866
@patch('requests.get', MagicMock(return_value=Response(

0 commit comments

Comments
 (0)