1717from requests import exceptions as request_exception
1818
1919from optimizely .helpers .enums import OdpRestApiConfig
20+ from optimizely .odp .odp_event import OdpEvent , OdpEventEncoder
2021from optimizely .odp .zaius_rest_api_manager import ZaiusRestApiManager
2122from . import base
2223
@@ -26,10 +27,9 @@ class ZaiusRestApiManagerTest(base.BaseTest):
2627 user_value = "test-user-value"
2728 api_key = "test-api-key"
2829 api_host = "test-host"
29-
3030 events = [
31- { "type" : "t1" , "action" : "a1" , "identifiers" : {"id-key-1" : "id-value-1" }, "data" : {"key-1" : "value1" }} ,
32- { "type" : "t2" , "action" : "a2" , "identifiers" : {"id-key-2" : "id-value-2" }, "data" : {"key-2" : "value2" }},
31+ OdpEvent ( 't1' , 'a1' , {"id-key-1" : "id-value-1" }, {"key-1" : "value1" }) ,
32+ OdpEvent ( 't2' , 'a2' , {"id-key-2" : "id-value-2" }, {"key-2" : "value2" })
3333 ]
3434
3535 def test_send_odp_events__valid_request (self ):
@@ -42,7 +42,7 @@ def test_send_odp_events__valid_request(self):
4242 request_headers = {'content-type' : 'application/json' , 'x-api-key' : self .api_key }
4343 mock_request_post .assert_called_once_with (url = self .api_host + "/v3/events" ,
4444 headers = request_headers ,
45- data = json .dumps (self .events ),
45+ data = json .dumps (self .events , cls = OdpEventEncoder ),
4646 timeout = OdpRestApiConfig .REQUEST_TIMEOUT )
4747
4848 def test_send_odp_ovents_success (self ):
@@ -58,7 +58,8 @@ def test_send_odp_ovents_success(self):
5858 self .assertFalse (should_retry )
5959
6060 def test_send_odp_events_invalid_json_no_retry (self ):
61- events = {1 , 2 , 3 } # using a set to trigger JSON-not-serializable error
61+ """Using a set to trigger JSON-not-serializable error."""
62+ events = {1 , 2 , 3 }
6263
6364 with mock .patch ('requests.post' ) as mock_request_post , \
6465 mock .patch ('optimizely.logger' ) as mock_logger :
0 commit comments