Skip to content

Commit

Permalink
test: added new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
orenlab committed Aug 30, 2024
1 parent 6620ec9 commit 047fe5e
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
"""
Copyright (c) 2024 Denis Rozhnovskiy <pytelemonbot@mail.ru>
This file is part of the PyOutlineAPI project.
PyOutlineAPI is a Python package for interacting with the Outline VPN Server.
Licensed under the MIT License. See the LICENSE file for more details.
"""

import unittest
from unittest.mock import patch, Mock

Expand All @@ -20,6 +9,7 @@
from pyoutlineapi.models import (
Server,
AccessKey,
AccessKeyList,
ServerPort,
DataLimit,
Metrics
Expand Down Expand Up @@ -182,15 +172,21 @@ def test_get_metrics_invalid_data(self, mock_request):
self.wrapper.get_metrics()

@patch('pyoutlineapi.client.requests.Session.request')
def test_rate_limiting(self, mock_request):
def test_get_access_keys_empty(self, mock_request):
mock_response = Mock()
mock_response.status_code = 429
mock_response.raise_for_status.side_effect = requests.HTTPError("429 Client Error: Too Many Requests")
mock_response.status_code = 200
mock_response.json.return_value = {"accessKeys": []}
mock_request.return_value = mock_response

access_keys = self.wrapper.get_access_keys()
self.assertIsInstance(access_keys, AccessKeyList)
self.assertEqual(len(access_keys.accessKeys), 0)

@patch('pyoutlineapi.client.requests.Session.request')
def test_handle_api_error(self, mock_request):
mock_request.side_effect = requests.exceptions.HTTPError("500 Internal Server Error")
with self.assertRaises(APIError):
for _ in range(5):
self.wrapper.get_server_info() # Simulate rapid consecutive calls
self.wrapper.get_server_info()


if __name__ == '__main__':
Expand Down

0 comments on commit 047fe5e

Please sign in to comment.