8000 Added tests and .travis.yml · factorlibre/wc-api-python@fe07a43 · GitHub
[go: up one dir, main page]

Skip to content

Commit fe07a43

Browse files
Added tests and .travis.yml
1 parent b65164f commit fe07a43

File tree

5 files changed

+124
-2
lines changed

5 files changed

+124
-2
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
*.pyc
2+
*.pyo
23
__pycache__
4+
build/
5+
dist/
6+
woocommerce.egg-info/
7+
run.py
8+
run3.py

.travis.yml

Lines changed: 14 additions & 0 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: python
2+
python:
3+
- "2.6"
4+
- "2.7"
5+
- "3.2"
6+
- "3.3"
7+
- "3.4"
8+
- "nightly"
9+
# command to install dependencies
10+
install:
11+
- pip install .
12+
- pip install -r requirements-test.txt
13+
# command to run tests
14+
script: nosetests

requirements-test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
-r requirements.txt
2+
httmock==1.2.3
3+
nose==1.3.7

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828
long_description=README,
2929
author="Claudio Sanches @ WooThemes",
3030
url="http://www.woothemes.com",
31-
license="MIT",
32-
packages=["woocommerce"],
31+
license="MIT License",
32+
packages=[
33+
"woocommerce"
34+
],
3335
include_package_data=True,
36+
platforms=['any'],
3437
install_requires=[
3538
"requests"
3639
],

tests.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
""" API Tests """
2+
import unittest
3+
import woocommerce
4+
from httmock import all_requests, HTTMock
5+
6+
7+
class WooCommerceTestCase(unittest.TestCase):
8+
"""Test case for the client methods."""
9+
10+
def setUp(self):
11+
self.consumer_key = "ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
12+
self.consumer_secret = "cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
13+
self.api = woocommerce.API(
14+
url="http://woo.test",
15+
consumer_key=self.consumer_key,
16+
consumer_secret=self.consumer_secret
17+
)
18+
19+
def test_version(self):
20+
""" Test default version """
21+
api = woocommerce.API(
22+
url="https://woo.test",
23+
consumer_key=self.consumer_key,
24+
consumer_secret=self.consumer_secret
25+
)
26+
27+
self.assertEqual(api.version, "v3")
28+
29+
def test_non_ssl(self):
30+
""" Test non-ssl """
31+
api = woocommerce.API(
32+
url="http://woo.test",
33+
consumer_key=self.consumer_key,
34+
consumer_secret=self.consumer_secret
35+
)
36+
self.assertFalse(api.is_ssl)
37+
38+
def test_with_ssl(self):
39+
""" Test non-ssl """
40+
api = woocommerce.API(
41+
url="https://woo.test",
42+
consumer_key=self.consumer_key,
43+
consumer_secret=self.consumer_secret
44+
)
45+
self.assertTrue(api.is_ssl, True)
46+
47+
def test_get(self):
48+
""" Test GET requests """
49+
@all_requests
50+
def woo_test_mock(*args, **kwargs):
51+
""" URL Mock """
52+
return {'status_code': 200,
53+
'content': 'OK'}
54+
55+
with HTTMock(woo_test_mock):
56+
# call requests
57+
status = self.api.get("products").status_code
58+
self.assertEqual(status, 200)
59+
60+
def test_post(self):
61+
""" Test POST requests """
62+
@all_requests
63+
def woo_test_mock(*args, **kwargs):
64+
""" URL Mock """
65+
return {'status_code': 201,
66+
'content': 'OK'}
67+
68+
with HTTMock(woo_test_mock):
69+
# call requests
70+
status = self.api.post("products", {}).status_code
71+
self.assertEqual(status, 201)
72+
73+
def test_put(self):
74+
""" Test PUT requests """
75+
@all_requests
76+
def woo_test_mock(*args, **kwargs):
77+
""" URL Mock """
78+
return {'status_code': 200,
79+
'content': 'OK'}
80+
81+
with HTTMock(woo_test_mock):
82+
# call requests
83+
status = self.api.put("products", {}).status_code
84+
self.assertEqual(status, 200)
85+
86+
def test_delete(self):
87+
""" Test DELETE requests """
88+
@all_requests
89+
def woo_test_mock(*args, **kwargs):
90+
""" URL Mock """
91+
return {'status_code': 200,
92+
'content': 'OK'}
93+
94+
with HTTMock(woo_test_mock):
95+
# call requests
96+
status = self.api.delete("products").status_code
97+
self.assertEqual(status, 200)

0 commit comments

Comments
 (0)
0