Skip to content

Commit e08138a

Browse files
committed
updated test_helper.py to add a fake for the dynamic API version request
Updated fake() to reflect the use of a url
1 parent ea84f13 commit e08138a

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

shopify/api_version.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import json
33
from six.moves.urllib import request
44

5-
65
class InvalidVersionError(Exception):
76
pass
87

@@ -28,7 +27,7 @@ def define_version(cls, version):
2827
def define_known_versions(cls):
2928
req = request.urlopen("https://app.shopify.com/services/apis.json")
3029
data = json.loads(req.read().decode("utf-8"))
31-
for api in data['apis']:
30+
for api in data['apis']:
3231
if api['handle'] == 'admin':
3332
for release in api['versions']:
3433
if release['handle'] == 'unstable':

test/fixtures/api_version.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"apis":[{"handle":"admin","versions":[{"handle":"2019-04","latest_supported":false,"display_name":"2019-04 (Unsupported)","supported":true},{"handle":"2019-07","latest_supported":false,"display_name":"2019-07 (Unsupported)","supported":true},{"handle":"2019-10","latest_supported":false,"display_name":"2019-10 (Unsupported)","supported":true},{"handle":"2020-01","latest_supported":false,"display_name":"2020-01","supported":true},{"handle":"2020-04","latest_supported":false,"display_name":"2020-04","supported":true},{"handle":"2020-07","latest_supported":false,"display_name":"2020-07","supported":true},{"handle":"2020-10","latest_supported":true,"display_name":"2020-10 (Latest)","supported":true},{"handle":"2021-01","latest_supported":false,"display_name":"2021-01 (Release candidate)","supported":false},{"handle":"unstable","latest_supported":false,"display_name":"unstable","supported":false}]},{"handle":"storefront","versions":[{"handle":"2019-07","latest_supported":false,"display_name":"2019-07 (Unsupported)","supported":true},{"handle":"2019-10","latest_supported":false,"display_name":"2019-10 (Unsupported)","supported":true},{"handle":"2020-01","latest_supported":false,"display_name":"2020-01","supported":true},{"handle":"2020-04","latest_supported":false,"display_name":"2020-04","supported":true},{"handle":"2020-07","latest_supported":false,"display_name":"2020-07","supported":true},{"handle":"2020-10","latest_supported":true,"display_name":"2020-10 (Latest)","supported":true},{"handle":"2021-01","latest_supported":false,"display_name":"2021-01 (Release candidate)","supported":false},{"handle":"unstable","latest_supported":false,"display_name":"unstable","supported":false}]}]}

test/test_helper.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ def setUp(self):
2020
self.http = http_fake.TestHandler
2121
self.http.set_response(Exception('Bad request'))
2222
self.http.site = 'https://this-is-my-test-show.myshopify.com'
23+
self.fake('apis',
24+
url='https://app.shopify.com/services/apis.json',
25+
method='GET',
26+
code=200,
27+
response_headers={'Content-type': 'application/json'},
28+
body=self.load_fixture('api_version'),
29+
has_user_agent=False
30+
)
2331

2432
def load_fixture(self, name, format='json'):
2533
with open(os.path.dirname(__file__)+'/fixtures/%s.%s' % (name, format), 'rb') as f:
@@ -35,13 +43,10 @@ def fake(self, endpoint, **kwargs):
3543
extension = ""
3644
else:
3745
extension = ".%s" % (kwargs.pop('extension', 'json'))
38-
39-
url = "https://this-is-my-test-show.myshopify.com%s/%s%s" % (prefix, endpoint, extension)
40-
try:
41-
url = kwargs['url']
42-
except KeyError:
43-
pass
44-
46+
if kwargs.get('url'):
47+
url = kwargs.get('url')
48+
else:
49+
url = "https://this-is-my-test-show.myshopify.com%s/%s%s" % (prefix, endpoint, extension)
4550
headers = {}
4651
if kwargs.pop('has_user_agent', True):
4752
userAgent = 'ShopifyPythonAPI/%s Python/%s' % (shopify.VERSION, sys.version.split(' ', 1)[0])

0 commit comments

Comments
 (0)