Skip to content

Commit

Permalink
Try to fix Import Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
orenlab committed Aug 28, 2024
1 parent d3935ec commit cd8d504
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/python_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ jobs:
- name: Install flake8
run: |
poetry run pip install flake8
- name: Set PYTHONPATH
run: echo "PYTHONPATH=$(pwd)" >> $GITHUB_ENV
- name: Lint with flake8
run: |
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
Expand Down
22 changes: 11 additions & 11 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
self.cert_sha256 = "dummy_cert_sha256"
self.api = pyoutline_client.PyOutlineWrapper(self.api_url, self.cert_sha256)

@patch('client.requests.Session.request')
@patch('pyoutlineapi.client.requests.Session.request')
def test_get_server_info(self, mock_request):
"""Test the get_server_info method."""
mock_response = Mock()
Expand All @@ -47,7 +47,7 @@ def test_get_server_info(self, mock_request):
self.assertEqual(server_info.portForNewAccessKeys, 8080)
mock_request.assert_called_once_with("GET", f"{self.api_url}/server", json=None, verify=True)

@patch('client.requests.Session.request')
@patch('pyoutlineapi.client.requests.Session.request')
def test_create_access_key(self, mock_request):
"""Test the create_access_key method."""
mock_response = Mock()
Expand All @@ -72,7 +72,7 @@ def test_create_access_key(self, mock_request):
self.assertEqual(access_key.accessUrl.get_secret_value(), "https://example.com")
mock_request.assert_called_once_with("POST", f"{self.api_url}/access-keys", json=None, verify=True)

@patch('client.requests.Session.request')
@patch('pyoutlineapi.client.requests.Session.request')
def test_get_access_keys(self, mock_request):
"""Test the get_access_keys method."""
mock_response = Mock()
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_get_access_keys(self, mock_request):
self.assertEqual(access_key_list.accessKeys[1].id, "key_id2")
mock_request.assert_called_once_with("GET", f"{self.api_url}/access-keys", json=None, verify=True)

@patch('client.requests.Session.request')
@patch('pyoutlineapi.client.requests.Session.request')
def test_delete_access_key(self, mock_request):
"""Test the delete_access_key method."""
mock_response = Mock()
Expand All @@ -116,7 +116,7 @@ def test_delete_access_key(self, mock_request):
self.api.delete_access_key("key_id")
mock_request.assert_called_once_with("DELETE", f"{self.api_url}/access-keys/key_id", json=None, verify=True)

@patch('client.requests.Session.request')
@patch('pyoutlineapi.client.requests.Session.request')
def test_update_server_port(self, mock_request):
"""Test the update_server_port method."""
mock_response = Mock()
Expand All @@ -130,7 +130,7 @@ def test_update_server_port(self, mock_request):
mock_request.assert_called_once_with("PUT", f"{self.api_url}/server/port-for-new-access-keys",
json={"port": 1234}, verify=True)

@patch('client.requests.Session.request')
@patch('pyoutlineapi.client.requests.Session.request')
def test_set_access_key_data_limit(self, mock_request):
"""Test the set_access_key_data_limit method."""
mock_response = Mock()
Expand All @@ -144,7 +144,7 @@ def test_set_access_key_data_limit(self, mock_request):
mock_request.assert_called_once_with("PUT", f"{self.api_url}/access-keys/key_id/data-limit",
json={"bytes": 1000000}, verify=True)

@patch('client.requests.Session.request')
@patch('pyoutlineapi.client.requests.Session.request')
def test_set_metrics_enabled(self, mock_request):
"""Test the set_metrics_enabled method."""
mock_response = Mock()
Expand All @@ -158,7 +158,7 @@ def test_set_metrics_enabled(self, mock_request):
mock_request.assert_called_once_with("PUT", f"{self.api_url}/server/metrics/enabled", json={"enabled": True},
verify=True)

@patch('client.requests.Session.request')
@patch('pyoutlineapi.client.requests.Session.request')
def test_get_metrics(self, mock_request):
"""Test the get_metrics method."""
mock_response = Mock()
Expand All @@ -176,15 +176,15 @@ def test_get_metrics(self, mock_request):
self.assertEqual(metrics.bytesTransferredByUserId, {"0": 3353820783, "1": 12827443528})
mock_request.assert_called_once_with("GET", f"{self.api_url}/metrics/transfer", json=None, verify=True)

@patch('client.requests.Session.request')
@patch('pyoutlineapi.client.requests.Session.request')
def test_request_error_handling(self, mock_request):
"""Test the error handling in _request method."""
mock_request.side_effect = requests.RequestException("Test exception")

with self.assertRaises(exceptions.APIError):
self.api._request("GET", "server")

@patch('client.requests.Session.request')
@patch('pyoutlineapi.client.requests.Session.request')
def test_get_server_info_invalid_data(self, mock_request):
"""Test handling of invalid data from get_server_info."""
mock_response = Mock()
Expand All @@ -197,7 +197,7 @@ def test_get_server_info_invalid_data(self, mock_request):
with self.assertRaises(ValueError):
self.api.get_server_info()

@patch('client.requests.Session.request')
@patch('pyoutlineapi.client.requests.Session.request')
def test_create_access_key_invalid_data(self, mock_request):
"""Test handling of invalid data from create_access_key."""
mock_response = Mock()
Expand Down

0 comments on commit cd8d504

Please sign in to comment.