@@ -272,12 +272,21 @@ def woo_test_mock(*args, **kwargs):
272
272
273
273
class OAuthTestcases (unittest .TestCase ):
274
274
def setUp (self ):
275
- self .consumer_key = "ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
276
- self .consumer_secret = "cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
277
- self .api = wordpress .API (
278
- url = "http://woo.test" ,
275
+ self .base_url = "http://localhost:8888/wordpress/"
276
+ self .api_name = 'wc-api'
277
+ self .api_ver = 'v3'
278
+ self .endpoint = 'products/99'
279
+ self .signature_method = "HMAC-SHA1"
280
+ self .consumer_key = "ck_681c2be361e415519dce4b65ee981682cda78bc6"
281
+ self .consumer_secret = "cs_b11f652c39a0afd3752fc7bb0c56d60d58da5877"
282
+
283
+ self .wcapi = API (
284
+ url = self .base_url ,
279
285
consumer_key = self .consumer_key ,
280
- consumer_secret = self .consumer_secret
286
+ consumer_secret = self .consumer_secret ,
287
+ api = self .api_name ,
288
+ version = self .api_ver ,
289
+ signature_method = self .signature_method
281
290
)
282
291
283
292
# def test_get_sign(self):
@@ -288,41 +297,39 @@ def setUp(self):
288
297
# expected_sig = '8T93S/PDOrEd+N9cm84EDvsPGJ4='
289
298
# self.assertEqual(sig, expected_sig)
290
299
300
+ def test_get_sign_key (self ):
301
+ self .assertEqual (
302
+ self .wcapi .oauth .get_sign_key (self .consumer_secret ),
303
+ "%s&" % self .consumer_secret
304
+ )
305
+
306
+ oauth_token_secret = "PNW9j1yBki3e7M7EqB5qZxbe9n5tR6bIIefSMQ9M2pdyRI9g"
307
+
308
+ self .assertEqual (
309
+ self .wcapi .oauth .get_sign_key (self .consumer_secret , oauth_token_secret ),
310
+ "%s&%s" % (self .consumer_secret , oauth_token_secret )
311
+ )
312
+
313
+
291
314
def test_normalize_params (self ):
292
315
params = dict ([('oauth_callback' , 'localhost:8888/wordpress' ), ('oauth_consumer_key' , 'LCLwTOfxoXGh' ), ('oauth_nonce' , '45474014077032100721477037582' ), ('oauth_signature_method' , 'HMAC-SHA1' ), ('oauth_timestamp' , 1477037582 ), ('oauth_version' , '1.0' )])
293
316
expected_normalized_params = "oauth_callback=localhost%3A8888%2Fwordpress&oauth_consumer_key=LCLwTOfxoXGh&oauth_nonce=45474014077032100721477037582&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1477037582&oauth_version=1.0"
294
317
normalized_params = OAuth .normalize_params (params )
295
318
self .assertEqual (expected_normalized_params , normalized_params )
296
319
297
320
def test_generate_oauth_signature (self ):
298
- base_url = "http://localhost:8888/wordpress/"
299
- api_name = 'wc-api'
300
- api_ver = 'v3'
301
- endpoint = 'products/99'
302
- signature_method = "HMAC-SHA1"
303
- consumer_key = "ck_681c2be361e415519dce4b65ee981682cda78bc6"
304
- consumer_secret = "cs_b11f652c39a0afd3752fc7bb0c56d60d58da5877"
305
-
306
- wcapi = API (
307
- url = base_url ,
308
- consumer_key = consumer_key ,
309
- consumer_secret = consumer_secret ,
310
- api = api_name ,
311
- version = api_ver ,
312
- signature_method = signature_method
313
- )
314
321
315
- endpoint_url = UrlUtils .join_components ([base_url , api_name , api_ver , endpoint ])
322
+ endpoint_url = UrlUtils .join_components ([self . base_url , self . api_name , self . api_ver , self . endpoint ])
316
323
317
324
params = OrderedDict ()
318
- params ["oauth_consumer_key" ] = consumer_key
325
+ params ["oauth_consumer_key" ] = self . consumer_key
319
326
params ["oauth_timestamp" ] = "1477041328"
320
327
params ["oauth_nonce" ] = "166182658461433445531477041328"
321
- params ["oauth_signature_method" ] = signature_method
328
+ params ["oauth_signature_method" ] = self . signature_method
322
329
params ["oauth_version" ] = "1.0"
323
330
params ["oauth_callback" ] = 'localhost:8888/wordpress'
324
331
325
- sig = wcapi .oauth .generate_oauth_signature ("POST" , params , endpoint_url )
332
+ sig = self . wcapi .oauth .generate_oauth_signature ("POST" , params , endpoint_url )
326
333
expected_sig = "517qNKeq/vrLZGj2UH7+q8ILWAg="
327
334
self .assertEqual (sig , expected_sig )
328
335
@@ -433,5 +440,5 @@ def test_get_request_token(self):
433
440
434
441
with HTTMock (self .woo_authentication_mock ):
435
442
access_token , access_token_secret = self .api .oauth .get_request_token ()
436
- self .assertEquals (access_token , [ 'XXXXXXXXXXXX' ] )
437
- self .assertEquals (access_token_secret , [ 'YYYYYYYYYYYY' ] )
443
+ self .assertEquals (access_token , 'XXXXXXXXXXXX' )
444
+ self .assertEquals (access_token_secret , 'YYYYYYYYYYYY' )
0 commit comments