Skip to content

Commit 2e19db6

Browse files
committed
fix cicd
1 parent e8040ec commit 2e19db6

10 files changed

Lines changed: 72 additions & 30 deletions

File tree

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 100

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ jobs:
2929
run: pip install --no-cache-dir -U pip black flake8 bandit
3030

3131
- name: Lint with flake8
32-
run: flake8 pyproxy tests benchmark
32+
run: flake8 pyproxy_sdk tests examples
3333

3434
- name: Check with black
35-
run: black --check pyproxy tests benchmark
35+
run: black --check pyproxy_sdk tests examples
3636

3737
- name: Check with bandit
38-
run: bandit -r pyproxy tests benchmark
38+
run: bandit -c bandit.yaml -r pyproxy_sdk tests examples
3939

4040
unittest:
4141
needs: code-scan

bandit.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
skips:
2+
- B106
3+
- B107

examples/delete_domain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
try:
1313
client.delete_filtering("domain", "example.com")
1414
except PyProxyNotFound:
15-
print("This domain is not blocked.")
15+
print("This domain is not blocked.")

examples/delete_url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
try:
1313
client.delete_filtering("url", "example.com/test")
1414
except PyProxyNotFound:
15-
print("This URL is not blocked.")
15+
print("This URL is not blocked.")

examples/get_filtering_rules.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from pyproxy_sdk.client import PyProxyClient
2-
from pyproxy_sdk.exceptions import PyProxyAlreadyExists, PyProxyNotFound
32

43
# Create client
54
client = PyProxyClient(

pyproxy_sdk/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33
that holds the current version number of the application.
44
"""
55

6-
from .client import PyProxyClient
7-
8-
__version__ = "0.1.1"
6+
__version__ = "0.1.1"

pyproxy_sdk/client.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@
99
PyProxyAlreadyExists,
1010
PyProxyNotFound,
1111
PyProxyInvalidInput,
12-
PyProxyServerError
12+
PyProxyServerError,
1313
)
1414

15+
1516
class PyProxyClient:
16-
def __init__(self, base_url: str = "", username: str = "", password: str = "", timeout: int = 10):
17+
def __init__(
18+
self,
19+
base_url: str = "",
20+
username: str = "",
21+
password: str = "",
22+
timeout: int = 10,
23+
):
1724
"""
1825
PyProxy SDK Client
1926
@@ -31,7 +38,7 @@ def __init__(self, base_url: str = "", username: str = "", password: str = "", t
3138
if not password:
3239
raise PyProxyConfigurationError("Password must be provided")
3340

34-
self.base_url = base_url.rstrip('/')
41+
self.base_url = base_url.rstrip("/")
3542
self.auth = HTTPBasicAuth(username, password)
3643
self.timeout = timeout
3744

@@ -60,9 +67,7 @@ def delete_filtering(self, filter_type: str, value: str):
6067
# Internal helpers
6168
def _get(self, path):
6269
response = requests.get(
63-
f"{self.base_url}{path}",
64-
auth=self.auth,
65-
timeout=self.timeout
70+
f"{self.base_url}{path}", auth=self.auth, timeout=self.timeout
6671
)
6772
self._handle_response(response)
6873
return response.json()
@@ -72,7 +77,7 @@ def _post(self, path, json=None):
7277
f"{self.base_url}{path}",
7378
auth=self.auth,
7479
json=json,
75-
timeout=self.timeout
80+
timeout=self.timeout,
7681
)
7782
self._handle_response(response)
7883
return response.json()
@@ -82,7 +87,7 @@ def _delete(self, path, json=None):
8287
f"{self.base_url}{path}",
8388
auth=self.auth,
8489
json=json,
85-
timeout=self.timeout
90+
timeout=self.timeout,
8691
)
8792
self._handle_response(response)
8893
return response.json()
@@ -97,7 +102,9 @@ def _handle_response(self, response):
97102
error_data = {"error": response.text}
98103

99104
status = response.status_code
100-
message = error_data.get("message") or error_data.get("error") or "Unknown error"
105+
message = (
106+
error_data.get("message") or error_data.get("error") or "Unknown error"
107+
)
101108

102109
if status == 400:
103110
raise PyProxyInvalidInput(message)

pyproxy_sdk/exceptions.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
# pyproxy_sdk/exceptions.py
22

3+
34
class PyProxyError(Exception):
45
"""Base class for all PyProxy SDK exceptions."""
6+
57
pass
68

9+
710
class PyProxyConfigurationError(PyProxyError):
8-
"""Raised when client configuration is invalid (e.g. missing URL, username, etc.)"""
11+
"""
12+
Raised when client configuration is invalid
13+
(e.g. missing URL, username, etc.)
14+
"""
15+
916
pass
1017

18+
1119
class PyProxyAlreadyExists(PyProxyError):
1220
"""Raised when trying to add a blocked value that already exists."""
21+
1322
pass
1423

24+
1525
class PyProxyNotFound(PyProxyError):
1626
"""Raised when trying to delete a value that doesn't exist."""
27+
1728
pass
1829

30+
1931
class PyProxyInvalidInput(PyProxyError):
2032
"""Raised when input data is invalid."""
33+
2134
pass
2235

36+
2337
class PyProxyServerError(PyProxyError):
2438
"""Raised for unexpected server errors."""
39+
2540
pass

tests/test_client.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,44 @@
77
PyProxyAlreadyExists,
88
PyProxyNotFound,
99
PyProxyInvalidInput,
10-
PyProxyServerError
10+
PyProxyServerError,
1111
)
1212

13+
1314
class TestPyProxyClient(unittest.TestCase):
1415

1516
def setUp(self):
16-
self.client = PyProxyClient(base_url="http://localhost:5000", username="admin", password="password")
17+
self.client = PyProxyClient(
18+
base_url="http://localhost:5000",
19+
username="admin",
20+
password="password",
21+
)
1722

1823
def test_missing_base_url(self):
1924
with self.assertRaises(PyProxyConfigurationError):
20-
PyProxyClient(base_url=None, username="admin", password="password")
25+
PyProxyClient(
26+
base_url=None,
27+
username="admin",
28+
password="password",
29+
)
2130

2231
def test_missing_username(self):
2332
with self.assertRaises(PyProxyConfigurationError):
24-
PyProxyClient(base_url="http://localhost:5000", username=None, password="password")
33+
PyProxyClient(
34+
base_url="http://localhost:5000",
35+
username=None,
36+
password="password",
37+
)
2538

2639
def test_missing_password(self):
2740
with self.assertRaises(PyProxyConfigurationError):
28-
PyProxyClient(base_url="http://localhost:5000", username="admin", password=None)
41+
PyProxyClient(
42+
base_url="http://localhost:5000",
43+
username="admin",
44+
password=None,
45+
)
2946

30-
@patch('pyproxy_sdk.client.requests.get')
47+
@patch("pyproxy_sdk.client.requests.get")
3148
def test_get_status_success(self, mock_get):
3249
mock_response = Mock()
3350
mock_response.ok = True
@@ -37,7 +54,7 @@ def test_get_status_success(self, mock_get):
3754
result = self.client.get_status()
3855
self.assertEqual(result, {"status": "ok"})
3956

40-
@patch('pyproxy_sdk.client.requests.get')
57+
@patch("pyproxy_sdk.client.requests.get")
4158
def test_server_error(self, mock_get):
4259
mock_response = Mock()
4360
mock_response.ok = False
@@ -48,7 +65,7 @@ def test_server_error(self, mock_get):
4865
with self.assertRaises(PyProxyServerError):
4966
self.client.get_status()
5067

51-
@patch('pyproxy_sdk.client.requests.post')
68+
@patch("pyproxy_sdk.client.requests.post")
5269
def test_add_filtering_already_exists(self, mock_post):
5370
mock_response = Mock()
5471
mock_response.ok = False
@@ -59,7 +76,7 @@ def test_add_filtering_already_exists(self, mock_post):
5976
with self.assertRaises(PyProxyAlreadyExists):
6077
self.client.add_filtering("domain", "example.com")
6178

62-
@patch('pyproxy_sdk.client.requests.delete')
79+
@patch("pyproxy_sdk.client.requests.delete")
6380
def test_delete_filtering_not_found(self, mock_delete):
6481
mock_response = Mock()
6582
mock_response.ok = False
@@ -70,7 +87,7 @@ def test_delete_filtering_not_found(self, mock_delete):
7087
with self.assertRaises(PyProxyNotFound):
7188
self.client.delete_filtering("domain", "example.com")
7289

73-
@patch('pyproxy_sdk.client.requests.post')
90+
@patch("pyproxy_sdk.client.requests.post")
7491
def test_invalid_input(self, mock_post):
7592
mock_response = Mock()
7693
mock_response.ok = False
@@ -81,5 +98,6 @@ def test_invalid_input(self, mock_post):
8198
with self.assertRaises(PyProxyInvalidInput):
8299
self.client.add_filtering("domain", "")
83100

84-
if __name__ == '__main__':
101+
102+
if __name__ == "__main__":
85103
unittest.main()

0 commit comments

Comments
 (0)