Upload google_play_scraper/tests/test_http_utils.py
Browse files
google_play_scraper/tests/test_http_utils.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for http_utils.py module."""
|
| 2 |
+
import pytest
|
| 3 |
+
from google_play_scraper.utils.http_utils import get
|
| 4 |
+
from google_play_scraper.exceptions import RateLimitError
|
| 5 |
+
from unittest.mock import patch, MagicMock
|
| 6 |
+
import requests
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@patch('google_play_scraper.utils.http_utils.session')
|
| 10 |
+
def test_get_success(mock_session):
|
| 11 |
+
mock_response = MagicMock()
|
| 12 |
+
mock_response.json.return_value = {"data": "test"}
|
| 13 |
+
mock_response.raise_for_status = MagicMock()
|
| 14 |
+
mock_session.get.return_value = mock_response
|
| 15 |
+
|
| 16 |
+
result = get("https://example.com")
|
| 17 |
+
assert result == {"data": "test"}
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@patch('google_play_scraper.utils.http_utils.session')
|
| 21 |
+
def test_get_rate_limit(mock_session):
|
| 22 |
+
mock_response = MagicMock()
|
| 23 |
+
mock_response.status_code = 429
|
| 24 |
+
mock_session.get.return_value = mock_response
|
| 25 |
+
mock_session.get.side_effect = requests.exceptions.HTTPError()
|
| 26 |
+
|
| 27 |
+
with pytest.raises(RateLimitError):
|
| 28 |
+
get("https://example.com")
|