Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0ce4eb6

Browse files
author
derwentx
committed
merge changes from #3
1 parent 7aba142 commit 0ce4eb6

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

‎.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
language: python
22
sudo: required
3+
env:
4+
- CODECOV_TOKEN: "da32b183-0d8b-4dc2-9bf9-e1743a39b2c8"
35
services:
46
- docker
57
python:
@@ -14,4 +16,6 @@ install:
1416
- docker exec -it wpapipython_woocommerce_1 bash -c 'until [ -f .done ]; do sleep 1; done; echo "complete"'
1517
# command to run tests
1618
script:
17-
- pytest
19+
- py.test --cov=wordpress tests.py
20+
after_success:
21+
- codecov

‎requirements-test.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
-r requirements.txt
22
httmock==1.2.3
3-
nose==1.3.7
43
six
54
pytest
5+
pytest-cov==2.5.1
6+
coverage
7+
codecov

‎wordpress/api.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from json import dumps as jsonencode
1212

1313
from six import binary_type, text_type
14-
from wordpress.auth import BasicAuth, OAuth, OAuth_3Leg
14+
from wordpress.auth import BasicAuth, OAuth, OAuth_3Leg, NoAuth
1515
from wordpress.helpers import StrUtils, UrlUtils
1616
from wordpress.transport import API_Requests_Wrapper
1717

@@ -35,6 +35,8 @@ def __init__(self, url, consumer_key, consumer_secret, **kwargs):
3535
auth_class = BasicAuth
3636
elif kwargs.get('oauth1a_3leg'):
3737
auth_class = OAuth_3Leg
38+
elif kwargs.get('no_auth'):
39+
auth_class = NoAuth
3840

3941
if kwargs.get('version', '').startswith('wc') and kwargs.get('oauth1a_3leg'):
4042
self.logger.warn("WooCommerce JSON Api does not seem to support 3leg")
@@ -170,10 +172,10 @@ def request_post_mortem(self, response=None):
170172
text_type(response.status_code),
171173
UrlUtils.beautify_response(response),
172174
text_type(response_headers),
173-
repr(request_body)[:1000]
175+
StrUtils.to_binary(request_body)[:1000]
174176
)
175177
if reason:
176-
msg += "\nBecause of %s" % reason
178+
msg += "\nBecause of %s" % StrUtils.to_binary(reason)
177179
if remedy:
178180
msg += "\n%s" % remedy
179181
raise UserWarning(msg)

‎wordpress/auth.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ def get_auth(self):
9494
if not self.query_string_auth:
9595
return HTTPBasicAuth(self.consumer_key, self.consumer_secret)
9696

97+
class NoAuth(Auth):
98+
"""
99+
Just a dummy Auth object to allow header based
100+
authorization per request
101+
"""
102+
def get_auth_url(self, endpoint_url, method, **kwargs):
103+
return endpoint_url
97104

98105
class OAuth(Auth):
99106
""" Signs string with oauth consumer_key and consumer_secret """

‎wordpress/transport.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(self, url, **kwargs):
3333
self.timeout = kwargs.get("timeout", 5)
3434
self.verify_ssl = kwargs.get("verify_ssl", True)
3535
self.session = Session()
36+
self.headers = kwargs.get("headers", {})
3637

3738
@property
3839
def is_ssl(self):
@@ -86,6 +87,10 @@ def request(self, method, url, auth=None, params=None, data=None, **kwargs):
8687
}
8788
if data is not None:
8889
headers["content-type"] = "application/json;charset=utf-8"
90+
headers = SeqUtils.combine_ordered_dicts(
91+
headers,
92+
self.headers
93+
)
8994
headers = SeqUtils.combine_ordered_dicts(
9095
headers,
9196
kwargs.get('headers', {})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /