|
2 | 2 | Tests for exception classes. |
3 | 3 | """ |
4 | 4 |
|
5 | | -import pytest |
6 | | - |
7 | | -from instaparser.exceptions import ( |
8 | | - InstaparserAPIError, |
9 | | - InstaparserAuthenticationError, |
10 | | - InstaparserError, |
11 | | - InstaparserRateLimitError, |
12 | | - InstaparserValidationError, |
13 | | -) |
14 | | - |
15 | | - |
16 | | -class TestInstaparserError: |
17 | | - """Tests for base InstaparserError exception.""" |
18 | | - |
19 | | - def test_instaparser_error_is_exception(self): |
20 | | - """Test that InstaparserError is an Exception.""" |
21 | | - assert issubclass(InstaparserError, Exception) |
22 | | - |
23 | | - def test_instaparser_error_can_be_raised(self): |
24 | | - """Test that InstaparserError can be raised and caught.""" |
25 | | - with pytest.raises(InstaparserError): |
26 | | - raise InstaparserError("Test error") |
| 5 | +from instaparser.exceptions import InstaparserAPIError |
27 | 6 |
|
28 | 7 |
|
29 | 8 | class TestInstaparserAPIError: |
30 | | - """Tests for InstaparserAPIError exception.""" |
| 9 | + """Tests for InstaparserAPIError attributes.""" |
31 | 10 |
|
32 | | - def test_instaparser_api_error_inherits_from_base(self): |
33 | | - """Test that InstaparserAPIError inherits from InstaparserError.""" |
34 | | - assert issubclass(InstaparserAPIError, InstaparserError) |
35 | | - |
36 | | - def test_instaparser_api_error_with_message(self): |
37 | | - """Test InstaparserAPIError with just a message.""" |
| 11 | + def test_message(self): |
38 | 12 | error = InstaparserAPIError("API error occurred") |
39 | 13 | assert str(error) == "API error occurred" |
40 | 14 | assert error.status_code is None |
41 | 15 | assert error.response is None |
42 | 16 |
|
43 | | - def test_instaparser_api_error_with_status_code(self): |
44 | | - """Test InstaparserAPIError with status code.""" |
| 17 | + def test_status_code(self): |
45 | 18 | error = InstaparserAPIError("API error", status_code=500) |
46 | | - assert str(error) == "API error" |
47 | 19 | assert error.status_code == 500 |
48 | | - assert error.response is None |
49 | | - |
50 | | - def test_instaparser_api_error_with_response(self): |
51 | | - """Test InstaparserAPIError with response object.""" |
52 | | - mock_response = type("MockResponse", (), {"status_code": 500})() |
53 | | - error = InstaparserAPIError("API error", status_code=500, response=mock_response) |
54 | | - assert str(error) == "API error" |
55 | | - assert error.status_code == 500 |
56 | | - assert error.response == mock_response |
57 | | - |
58 | | - |
59 | | -class TestInstaparserAuthenticationError: |
60 | | - """Tests for InstaparserAuthenticationError exception.""" |
61 | | - |
62 | | - def test_authentication_error_inherits_from_api_error(self): |
63 | | - """Test that InstaparserAuthenticationError inherits from InstaparserAPIError.""" |
64 | | - assert issubclass(InstaparserAuthenticationError, InstaparserAPIError) |
65 | | - |
66 | | - def test_authentication_error_can_be_raised(self): |
67 | | - """Test that InstaparserAuthenticationError can be raised.""" |
68 | | - with pytest.raises(InstaparserAuthenticationError): |
69 | | - raise InstaparserAuthenticationError("Invalid API key", status_code=401) |
70 | | - |
71 | | - |
72 | | -class TestInstaparserRateLimitError: |
73 | | - """Tests for InstaparserRateLimitError exception.""" |
74 | | - |
75 | | - def test_rate_limit_error_inherits_from_api_error(self): |
76 | | - """Test that InstaparserRateLimitError inherits from InstaparserAPIError.""" |
77 | | - assert issubclass(InstaparserRateLimitError, InstaparserAPIError) |
78 | | - |
79 | | - def test_rate_limit_error_can_be_raised(self): |
80 | | - """Test that InstaparserRateLimitError can be raised.""" |
81 | | - with pytest.raises(InstaparserRateLimitError): |
82 | | - raise InstaparserRateLimitError("Rate limit exceeded", status_code=429) |
83 | | - |
84 | | - |
85 | | -class TestInstaparserValidationError: |
86 | | - """Tests for InstaparserValidationError exception.""" |
87 | | - |
88 | | - def test_validation_error_inherits_from_api_error(self): |
89 | | - """Test that InstaparserValidationError inherits from InstaparserAPIError.""" |
90 | | - assert issubclass(InstaparserValidationError, InstaparserAPIError) |
91 | 20 |
|
92 | | - def test_validation_error_can_be_raised(self): |
93 | | - """Test that InstaparserValidationError can be raised.""" |
94 | | - with pytest.raises(InstaparserValidationError): |
95 | | - raise InstaparserValidationError("Invalid request", status_code=400) |
| 21 | + def test_response(self): |
| 22 | + response = object() |
| 23 | + error = InstaparserAPIError("API error", status_code=500, response=response) |
| 24 | + assert error.response is response |
0 commit comments