forked from klaviyo/python-klaviyo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_api_helper.py
55 lines (43 loc) · 2.3 KB
/
test_api_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pytest
from .fixtures.api_helper import KlaviyoAPIFixture
from klaviyo.exceptions import (
KlaviyoAuthenticationError, KlaviyoConfigurationException,
KlaviyoRateLimitException,
)
class TestKlaviyoAPI(KlaviyoAPIFixture):
def test_filter_params(self, mock_params):
params = self.api._filter_params(mock_params)
assert (
all(params.values()) and
params[self.api.COUNT] == 1
)
def test_build_marker_param(self, mock_marker_param):
params = self.api._build_marker_param(mock_marker_param)
assert params[self.api.MARKER] == 2000
def test_build_query_string(self, mock_params):
query_string = self.api._build_query_string(mock_params, False)
assert (
isinstance(query_string, str) and
'&' in query_string
)
def test_is_valid_request_option_private(self):
with pytest.raises(KlaviyoConfigurationException):
self.api_no_private_token._is_valid_request_option()
def test_v2_request(self, mock_lists_path, mock_get_method, mock_params, mock_request, mock_handle_response):
self.api._v2_request(mock_lists_path, mock_get_method, mock_params)
mock_request.assert_called_once()
def test_v1_request(self, mock_lists_path, mock_get_method, mock_params, mock_request, mock_handle_response):
self.api._v1_request(mock_lists_path, mock_get_method, mock_params)
mock_request.assert_called_once()
def test_public_request(self, mock_lists_path, mock_querystring, mock_request):
self.api._public_request(mock_lists_path, mock_querystring)
mock_request.assert_called_once()
def test_request(self, mock_get_method, mock_url, mock_requests_package, mock_handle_response):
self.api._request(mock_get_method, mock_url)
mock_requests_package.assert_called_once()
def test_handle_response_with_auth_error(self, mock_response_auth_error, mock_request_type_private):
with pytest.raises(KlaviyoAuthenticationError):
self.api._handle_response(mock_response_auth_error)
def test_handle_response_with_rate_limit_error(self, mock_response_rate_limit_error, mock_request_type_private):
with pytest.raises(KlaviyoRateLimitException):
self.api._handle_response(mock_response_rate_limit_error)