-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
""" | ||
Copyright (c) 2024 Denis Rozhnovskiy <pytelemonbot@mail.ru> | ||
This file is part of the PyOutline project. | ||
PyOutline is a Python package for interacting with the Outline VPN Server. | ||
Licensed under the MIT License. See the LICENSE file for more details. | ||
""" | ||
|
||
from pyoutlineapi import exceptions as e | ||
|
||
|
||
def test_api_error(): | ||
error = e.APIError("API general error") | ||
assert str(error) == "API general error" | ||
assert isinstance(error, Exception) | ||
|
||
|
||
def test_request_error(): | ||
error = e.RequestError("Connection failed") | ||
assert str(error) == "An error occurred while requesting data: Connection failed" | ||
assert isinstance(error, e.APIError) | ||
assert isinstance(error, Exception) | ||
|
||
|
||
def test_validation_error(): | ||
error = e.ValidationError("Invalid data format") | ||
assert str(error) == "Validation error occurred: Invalid data format" | ||
assert isinstance(error, e.APIError) | ||
assert isinstance(error, Exception) | ||
import unittest | ||
from pyoutlineapi.exceptions import APIError, HTTPError, RequestError, ValidationError | ||
|
||
class TestAPIError(unittest.TestCase): | ||
def test_api_error_initialization(self): | ||
"""Test initialization of APIError.""" | ||
error = APIError("Test API Error") | ||
self.assertEqual(str(error), "Test API Error") | ||
self.assertEqual(error.message, "Test API Error") | ||
|
||
class TestHTTPError(unittest.TestCase): | ||
def test_http_error_initialization(self): | ||
"""Test initialization of HTTPError.""" | ||
error = HTTPError(404, "Not Found") | ||
self.assertEqual(str(error), "HTTP error occurred: 404 - Not Found") | ||
self.assertEqual(error.status_code, 404) | ||
self.assertEqual(error.message, "Not Found") | ||
|
||
class TestRequestError(unittest.TestCase): | ||
def test_request_error_initialization(self): | ||
"""Test initialization of RequestError.""" | ||
error = RequestError("Connection failed") | ||
self.assertEqual(str(error), "An error occurred while requesting data: Connection failed") | ||
|
||
class TestValidationError(unittest.TestCase): | ||
def test_validation_error_initialization(self): | ||
"""Test initialization of ValidationError.""" | ||
error = ValidationError("Invalid data format") | ||
self.assertEqual(str(error), "Validation error occurred: Invalid data format") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |