@@ -208,7 +208,7 @@ def test_param_validation_of_param_values_with_lists(self):
208
208
}
209
209
self .assertEqual (True , shopify .Session .validate_hmac (params ))
210
210
211
- def test_return_token_if_hmac_is_valid (self ):
211
+ def test_return_token_and_scope_if_hmac_is_valid (self ):
212
212
shopify .Session .secret = "secret"
213
213
params = {"code" : "any-code" , "timestamp" : time .time ()}
214
214
hmac = shopify .Session .calculate_hmac (params )
@@ -218,12 +218,13 @@ def test_return_token_if_hmac_is_valid(self):
218
218
None ,
219
219
url = "https://localhost.myshopify.com/admin/oauth/access_token" ,
220
220
method = "POST" ,
221
- body = '{"access_token" : "token"}' ,
221
+ body = '{"access_token" : "token", "scope": "read_products,write_orders" }' ,
222
222
has_user_agent = False ,
223
223
)
224
224
session = shopify .Session ("http://localhost.myshopify.com" , "unstable" )
225
225
token = session .request_token (params )
226
226
self .assertEqual ("token" , token )
227
+ self .assertEqual (shopify .ApiAccess ("read_products,write_orders" ), session .access_scopes )
227
228
228
229
def test_raise_error_if_hmac_is_invalid (self ):
229
230
shopify .Session .secret = "secret"
@@ -257,6 +258,32 @@ def test_raise_error_if_timestamp_is_too_old(self):
257
258
session = shopify .Session ("http://localhost.myshopify.com" , "unstable" )
258
259
session = session .request_token (params )
259
260
261
+ def test_access_scopes_are_nil_by_default (self ):
262
+ session = shopify .Session ("testshop.myshopify.com" , "unstable" , "any-token" )
263
+ self .assertIsNone (session .access_scopes )
264
+
265
+ def test_access_scopes_when_valid_scopes_passed_in (self ):
266
+ session = shopify .Session (
267
+ shop_url = "testshop.myshopify.com" ,
268
+ version = "unstable" ,
269
+ token = "any-token" ,
270
+ access_scopes = "read_products, write_orders" ,
271
+ )
272
+
273
+ expected_access_scopes = shopify .ApiAccess ("read_products, write_orders" )
274
+ self .assertEqual (expected_access_scopes , session .access_scopes )
275
+
276
+ def test_access_scopes_set_with_api_access_object_passed_in (self ):
277
+ session = shopify .Session (
278
+ shop_url = "testshop.myshopify.com" ,
279
+ version = "unstable" ,
280
+ token = "any-token" ,
281
+ access_scopes = shopify .ApiAccess ("read_products, write_orders" ),
282
+ )
283
+
284
+ expected_access_scopes = shopify .ApiAccess ("read_products, write_orders" )
285
+ self .assertEqual (expected_access_scopes , session .access_scopes )
286
+
260
287
def normalize_url (self , url ):
261
288
scheme , netloc , path , query , fragment = urllib .parse .urlsplit (url )
262
289
query = "&" .join (sorted (query .split ("&" )))
0 commit comments