Skip to content

Commit 4cd2d35

Browse files
authored
Merge pull request #51 from hpe-container-platform-community/add_flake8_hpecp_to_travis
add -s to pytest
2 parents 7cba3da + 9d5d397 commit 4cd2d35

12 files changed

+272
-109
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
install:
4848
- pip3 install flake8 # TODO: install 'flake8-docstrings'
4949
script:
50-
- flake8 bin/ hpecp/ # TODO: add docstring 'flake8 --docstring-convention numpy hpecp/ bin/ tests/'
50+
- flake8 bin/ hpecp/ tests/ # TODO: add docstring 'flake8 --docstring-convention numpy hpecp/ bin/ tests/'
5151
- stage: format
5252
name: "Check code formatting"
5353
python: 3.8

DEVELOPING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ tox -e py27 -- tests/library/client_test.py:TestCreateFromProperties.test_create
110110
Aim for 100% test coverage to ensure library will work with all specified python versions.
111111

112112
```
113-
coverage erase && coverage run --source hpecp setup.py test && coverage report -m
113+
coverage erase && coverage run --source hpecp,bin setup.py test && coverage report -m
114114
```
115115

116116

tests/cli/cli_test.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
import requests
2828
from mock import patch
2929

30-
sys.path.insert(0, os.path.abspath("../../"))
31-
from bin import cli
32-
3330

3431
class MockResponse:
3532
def __init__(
@@ -66,7 +63,9 @@ def mocked_requests_post(*args, **kwargs):
6663
json_data={},
6764
status_code=200,
6865
headers={
69-
"location": "/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71"
66+
"location": (
67+
"/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71"
68+
)
7069
},
7170
)
7271
raise RuntimeError("Unhandle POST request: " + args[0])
@@ -120,10 +119,7 @@ def mocked_requests_get(*args, **kwargs):
120119
)
121120
raise RuntimeError("Unhandle GET request: " + args[0])
122121

123-
@patch("requests.post", side_effect=mocked_requests_post)
124-
@patch("requests.get", side_effect=mocked_requests_get)
125-
def test_example(self, mock_post, mock_get):
126-
122+
def setUp(self):
127123
file_data = dedent(
128124
"""[default]
129125
api_host = 127.0.0.1
@@ -135,17 +131,28 @@ def test_example(self, mock_post, mock_get):
135131
password = admin123"""
136132
)
137133

138-
tmp = tempfile.NamedTemporaryFile(delete=True)
139-
try:
140-
tmp.write(file_data.encode("utf-8"))
141-
tmp.flush()
134+
self.tmpFile = tempfile.NamedTemporaryFile(delete=True)
135+
self.tmpFile.write(file_data.encode("utf-8"))
136+
self.tmpFile.flush()
137+
138+
sys.path.insert(0, os.path.abspath("../../"))
139+
from bin import cli
142140

143-
cli.HPECP_CONFIG_FILE = tmp.name
141+
self.cli = cli
142+
self.cli.HPECP_CONFIG_FILE = self.tmpFile.name
144143

145-
hpecp = cli.CLI()
146-
hpecp.k8scluster.list()
144+
def tearDown(self):
145+
self.tmpFile.close()
147146

148-
self.assertTrue(True)
147+
def test_autocomplete_bash(self):
148+
149+
hpecp = self.cli.CLI()
150+
hpecp.autocomplete.bash()
151+
152+
# TODO move this to tests/library/k8s_cluster_test.py
153+
@patch("requests.post", side_effect=mocked_requests_post)
154+
@patch("requests.get", side_effect=mocked_requests_get)
155+
def test_k8scluster_list(self, mock_post, mock_get):
149156

150-
finally:
151-
tmp.close()
157+
hpecp = self.cli.CLI()
158+
hpecp.k8scluster.list()

tests/cli/k8s_cluster_test.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,16 @@
1919
# OTHER DEALINGS IN THE SOFTWARE.
2020

2121
from unittest import TestCase
22-
from mock import Mock, patch, mock_open
22+
from mock import patch
2323

2424
from textwrap import dedent
2525
import sys
2626
import tempfile
2727
import os
28-
import json
2928
import requests
30-
from requests.exceptions import RequestException
3129

3230
sys.path.insert(0, os.path.abspath("../../"))
33-
from bin import cli
31+
from bin import cli # noqa: E402
3432

3533

3634
class MockResponse:
@@ -68,7 +66,9 @@ def mocked_requests_post(*args, **kwargs):
6866
json_data={},
6967
status_code=200,
7068
headers={
71-
"location": "/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71"
69+
"location": (
70+
"/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71"
71+
)
7272
},
7373
)
7474
raise RuntimeError("Unhandle POST request: " + args[0])
@@ -90,31 +90,46 @@ def mocked_requests_get(*args, **kwargs):
9090
"1.14.10": {
9191
"_version": "1.0",
9292
"min_upgrade_version": "1.13.0",
93-
"relnote_url": "https://v1-14.docs.kubernetes.io/docs/setup/release/notes/",
93+
"relnote_url": (
94+
"https://v1-14.docs.kubernetes.io/docs/setup"
95+
"/release/notes/"
96+
),
9497
"hpecsi": "1.14",
9598
},
9699
"1.15.7": {
97100
"_version": "1.0",
98101
"min_upgrade_version": "1.14.0",
99-
"relnote_url": "https://v1-15.docs.kubernetes.io/docs/setup/release/notes/",
102+
"relnote_url": (
103+
"https://v1-15.docs.kubernetes.io/docs/setup"
104+
"/release/notes/"
105+
),
100106
"hpecsi": "1.15",
101107
},
102108
"1.16.4": {
103109
"_version": "1.0",
104110
"min_upgrade_version": "1.15.0",
105-
"relnote_url": "https://v1-16.docs.kubernetes.io/docs/setup/release/notes/",
111+
"relnote_url": (
112+
"https://v1-16.docs.kubernetes.io/docs/setup"
113+
"/release/notes/"
114+
),
106115
"hpecsi": "1.16",
107116
},
108117
"1.17.0": {
109118
"_version": "1.0",
110119
"min_upgrade_version": "1.16.0",
111-
"relnote_url": "https://v1-17.docs.kubernetes.io/docs/setup/release/notes/",
120+
"relnote_url": (
121+
"https://v1-17.docs.kubernetes.io/docs/setup"
122+
"/release/notes/"
123+
),
112124
"hpecsi": "1.17",
113125
},
114126
"1.18.0": {
115127
"_version": "1.0",
116128
"min_upgrade_version": "1.17.0",
117-
"relnote_url": "https://kubernetes.io/docs/setup/release/notes/",
129+
"relnote_url": (
130+
"https://kubernetes.io/docs/setup"
131+
"/release/notes/"
132+
),
118133
"hpecsi": "1.18",
119134
},
120135
},

tests/library/client_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,11 @@
1919
# OTHER DEALINGS IN THE SOFTWARE.
2020

2121
from unittest import TestCase
22-
from mock import Mock, patch, mock_open
22+
from mock import patch
2323

2424
from textwrap import dedent
25-
import sys
2625
import tempfile
27-
import os
28-
import json
2926
import requests
30-
from requests.exceptions import RequestException
3127
from hpecp import ContainerPlatformClient
3228

3329

@@ -98,7 +94,9 @@ def mocked_requests_post(*args, **kwargs):
9894
json_data={},
9995
status_code=200,
10096
headers={
101-
"location": "/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71"
97+
"location": (
98+
"/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71"
99+
)
102100
},
103101
)
104102
raise RuntimeError("Unhandle POST request: " + args[0])
@@ -135,7 +133,9 @@ def mocked_requests_post_ssl(*args, **kwargs):
135133
json_data={},
136134
status_code=200,
137135
headers={
138-
"location": "/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71"
136+
"location": (
137+
"/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71"
138+
)
139139
},
140140
)
141141
raise RuntimeError("Unhandle POST request: " + args[0])

tests/library/config_test.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,9 @@
1919
# OTHER DEALINGS IN THE SOFTWARE.
2020

2121
from unittest import TestCase
22-
from mock import Mock, patch
22+
from mock import patch
2323

24-
import sys
25-
import tempfile
26-
import os
27-
import json
2824
import requests
29-
from requests.exceptions import RequestException
3025
from hpecp import ContainerPlatformClient
3126

3227

@@ -63,15 +58,19 @@ def mocked_requests_post(*args, **kwargs):
6358
json_data={},
6459
status_code=200,
6560
headers={
66-
"location": "/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71"
61+
"location": (
62+
"/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71"
63+
)
6764
},
6865
)
6966
elif args[0] == "https://127.0.0.1:8080/api/v2/config/auth":
7067
return MockResponse(
7168
json_data={},
7269
status_code=200,
7370
headers={
74-
"location": "/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71"
71+
"location": (
72+
"/api/v1/session/df1bfacb-xxxx-xxxx-xxxx-c8f57d8f3c71"
73+
)
7574
},
7675
)
7776
raise RuntimeError("Unhandle POST request: " + args[0])
@@ -94,7 +93,10 @@ def test_epic_tenant_list(self, mock_post):
9493
"bind_pwd": "5ambaPwd@",
9594
"user_attribute": "sAMAccountName",
9695
"bind_type": "search_bind",
97-
"bind_dn": "cn=Administrator,CN=Users,DC=samdom,DC=example,DC=com",
96+
"bind_dn": (
97+
"cn=Administrator,CN=Users,DC=samdom"
98+
",DC=example,DC=com"
99+
),
98100
"host": "1.1.1.1",
99101
"security_protocol": "ldaps",
100102
"base_dn": "CN=Users,DC=samdom,DC=example,DC=com",

0 commit comments

Comments
 (0)