1
1
""" API Tests """
2
- import unittest
3
- import sys
4
- import pdb
5
2
import functools
3
+ import logging
4
+ import pdb
5
+ import random
6
+ import sys
6
7
import traceback
8
+ import unittest
7
9
from collections import OrderedDict
10
+ from copy import copy
8
11
from tempfile import mkstemp
9
12
10
- from httmock import all_requests , HTTMock , urlmatch
11
13
import wordpress
12
- from wordpress import auth
13
- from wordpress import __default_api_version__ , __default_api__
14
- from wordpress .helpers import UrlUtils , SeqUtils , StrUtils
15
- from wordpress .transport import API_Requests_Wrapper
14
+ from wordpress import __default_api__ , __default_api_version__ , auth
16
15
from wordpress .api import API
17
16
from wordpress .auth import OAuth
18
- import random
19
- import platform
17
+ from wordpress .helpers import SeqUtils , StrUtils , UrlUtils
18
+ from wordpress .transport import API_Requests_Wrapper
19
+
20
+ from httmock import HTTMock , all_requests , urlmatch
20
21
21
22
try :
22
23
from urllib .parse import urlencode , quote , unquote , parse_qs , parse_qsl , urlparse , urlunparse
@@ -32,12 +33,16 @@ def debug_on(*exceptions):
32
33
def decorator (f ):
33
34
@functools .wraps (f )
34
35
def wrapper (* args , ** kwargs ):
36
+ prev_root = copy (logging .root )
35
37
try :
38
+ logging .basicConfig (level = logging .DEBUG )
36
39
return f (* args , ** kwargs )
37
40
except exceptions :
38
41
info = sys .exc_info ()
39
42
traceback .print_exception (* info )
40
43
pdb .post_mortem (info [2 ])
44
+ finally :
45
+ logging .root = prev_root
41
46
return wrapper
42
47
return decorator
43
48
@@ -807,7 +812,7 @@ class WCApiTestCases(unittest.TestCase):
807
812
""" Tests for WC API V3 """
808
813
def setUp (self ):
809
814
self .api_params = {
810
- 'url' :'http://ich.local:8888/woocommerce /' ,
815
+ 'url' :'http://localhost:18080/wptest /' ,
811
816
'api' :'wc-api' ,
812
817
'version' :'v3' ,
813
818
'consumer_key' :'ck_0297450a41484f27184d1a8a3275f9bab5b69143' ,
@@ -871,7 +876,7 @@ class WCApiTestCasesNew(unittest.TestCase):
871
876
""" Tests for New WC API """
872
877
def setUp (self ):
873
878
self .api_params = {
874
- 'url' :'http://ich.local:8888/woocommerce /' ,
879
+ 'url' :'http://localhost:18080/wptest /' ,
875
880
'api' :'wp-json' ,
876
881
'version' :'wc/v2' ,
877
882
'consumer_key' :'ck_0297450a41484f27184d1a8a3275f9bab5b69143' ,
@@ -914,32 +919,31 @@ def test_APIPutWithSimpleQuery(self):
914
919
@unittest .skip ("Should only work on my machine" )
915
920
class WPAPITestCases (unittest .TestCase ):
916
921
def setUp (self ):
917
- self .creds_store = '~/wc-api-creds.json'
922
+ self .creds_store = '~/wc-api-creds-test .json'
918
923
self .api_params = {
919
- 'url' :'http://ich.local:8888/woocommerce /' ,
924
+ 'url' :'http://localhost:18080/wptest /' ,
920
925
'api' :'wp-json' ,
921
- 'version' :'wp/v1 ' ,
922
- 'consumer_key' :'ox0p2NZSOja8 ' ,
923
- 'consumer_secret' :'6Ye77tGlYgxjCexn1m7zGs0GLYmmoGXeHM82jgmw3kqffNLe ' ,
926
+ 'version' :'wp/v2 ' ,
927
+ 'consumer_key' :'tYG1tAoqjBEM ' ,
928
+ 'consumer_secret' :'s91fvylVrqChwzzDbEJHEWyySYtAmlIsqqYdjka1KyVDdAyB ' ,
924
929
'callback' :'http://127.0.0.1/oauth1_callback' ,
925
- 'wp_user' :'woocommerce ' ,
926
- 'wp_pass' :'woocommerce ' ,
930
+ 'wp_user' :'wptest ' ,
931
+ 'wp_pass' :'gZ*gZk#v0t5$j#NQ@9 ' ,
927
932
'oauth1a_3leg' :True ,
928
933
'creds_store' : self .creds_store
929
934
}
935
+ self .wpapi = API (** self .api_params )
936
+ self .wpapi .auth .clear_stored_creds ()
930
937
931
- @debug_on ()
932
938
def test_APIGet (self ):
933
- wpapi = API (** self .api_params )
934
- wpapi .auth .clear_stored_creds ()
935
- response = wpapi .get ('users' )
939
+ response = self .wpapi .get ('users' )
936
940
self .assertIn (response .status_code , [200 ,201 ])
937
941
response_obj = response .json ()
938
- self .assertEqual (response_obj [0 ]['name' ], 'woocommerce' )
942
+ self .assertEqual (response_obj [0 ]['name' ], self . api_params [ 'wp_user' ] )
939
943
944
+ @debug_on ()
940
945
def test_APIGetWithSimpleQuery (self ):
941
- wpapi = API (** self .api_params )
942
- response = wpapi .get ('media?page=2&per_page=2' )
946
+ response = self .wpapi .get ('media?page=2&per_page=2' )
943
947
# print UrlUtils.beautify_response(response)
944
948
self .assertIn (response .status_code , [200 ,201 ])
945
949
0 commit comments