Skip to content

Commit 6ce9fbe

Browse files
author
derwentx
committed
update tests for travis
1 parent e1f3102 commit 6ce9fbe

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ install:
1111
- pip install .
1212
- pip install -r requirements-test.txt
1313
# command to run tests
14-
script: nosetests
14+
script:
15+
- pytest

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
httmock==1.2.3
33
nose==1.3.7
44
six
5+
pytest

tests.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -858,18 +858,18 @@ def test_retrieve_access_creds(self):
858858
'YYYYYYYYYYYY'
859859
)
860860

861-
@unittest.skipIf(platform.uname()[1] != "Derwents-MBP.lan", "should only work on my machine")
861+
@unittest.skipIf(platform.uname()[1] != "Derwents-MacBook-Pro.local", "should only work on my machine")
862862
class WCApiTestCasesBase(unittest.TestCase):
863863
""" Base class for WC API Test cases """
864864
def setUp(self):
865865
Auth.force_timestamp = CURRENT_TIMESTAMP
866866
Auth.force_nonce = SHITTY_NONCE
867867
self.api_params = {
868-
'url':'http://localhost:18080/wptest/',
868+
'url':'http://derwent-mac.ddns.me:18080/wptest/',
869869
'api':'wc-api',
870870
'version':'v3',
871-
'consumer_key':'ck_e1dd4a9c85f49b9685f7964a154eecb29af39d5a',
872-
'consumer_secret':'cs_8ef3e5d21f8a0c28cd7bc4643e92111a0326b6b1',
871+
'consumer_key':'ck_6f1cf1a528fd94ec3d18a8af91eea94cfc8233bf',
872+
'consumer_secret':'cs_d9055bdeff59dc992105064f4607de0ffa05ca5e',
873873
}
874874

875875
class WCApiTestCasesLegacy(WCApiTestCasesBase):
@@ -975,14 +975,14 @@ class WCApiTestCases3Leg(WCApiTestCases):
975975
""" Tests for New wp-json/wc/v2 API with 3-leg """
976976
oauth1a_3leg = True
977977

978-
@unittest.skipIf(platform.uname()[1] != "Derwents-MBP.lan", "should only work on my machine")
978+
@unittest.skipIf(platform.uname()[1] != "Derwents-MacBook-Pro.local", "should only work on my machine")
979979
class WPAPITestCasesBase(unittest.TestCase):
980980
def setUp(self):
981981
Auth.force_timestamp = CURRENT_TIMESTAMP
982982
Auth.force_nonce = SHITTY_NONCE
983983
self.creds_store = '~/wc-api-creds-test.json'
984984
self.api_params = {
985-
'url':'http://localhost:18080/wptest/',
985+
'url':'http://derwent-mac.ddns.me:18080/wptest/',
986986
'api':'wp-json',
987987
'version':'wp/v2',
988988
'consumer_key':'tYG1tAoqjBEM',

wordpress/api.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,21 +100,24 @@ def request_post_mortem(self, response=None):
100100
if hasattr(response.request, 'body'):
101101
request_body = response.request.body
102102

103+
try_hostname_mismatch = False
104+
103105
if isinstance(response_json, dict) and ('code' in response_json or 'message' in response_json):
104106
reason = u" - ".join([
105107
unicode(response_json.get(key)) for key in ['code', 'message', 'data'] \
106108
if key in response_json
107109
])
110+
code = response_json.get('code')
108111

109-
if 'code' == 'rest_user_invalid_email':
112+
if code == 'rest_user_invalid_email':
110113
remedy = "Try checking the email %s doesn't already exist" % \
111114
request_body.get('email')
112115

113-
elif 'code' == 'json_oauth1_consumer_mismatch':
116+
elif code == 'json_oauth1_consumer_mismatch':
114117
remedy = "Try deleting the cached credentials at %s" % \
115118
self.auth.creds_store
116119

117-
elif 'code' == 'woocommerce_rest_cannot_view':
120+
elif code == 'woocommerce_rest_cannot_view':
118121
if not self.auth.query_string_auth:
119122
remedy = "Try enabling query_string_auth"
120123
else:
@@ -131,14 +134,21 @@ def request_post_mortem(self, response=None):
131134
" - Try enabling HTTPS and using basic authentication\n"
132135
)
133136

137+
elif code == 'woocommerce_rest_authentication_error':
138+
try_hostname_mismatch = True
139+
134140
response_headers = {}
135141
if hasattr(response, 'headers'):
136142
response_headers = response.headers
137143

138-
if not reason:
144+
if not reason or try_hostname_mismatch:
139145
requester_api_url = self.requester.api_url
146+
links = []
140147
if hasattr(response, 'links') and response.links:
141148
links = response.links
149+
elif 'Link' in response_headers:
150+
links = [response_headers['Link']]
151+
if links:
142152
first_link_key = list(links)[0]
143153
header_api_url = links[first_link_key].get('url', '')
144154
if header_api_url:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy