@@ -103,23 +103,72 @@ def test_get_library_events_exception_when_connection_timeout(
103103 with pytest .raises (CloudLibraryClientError ):
104104 test_instance .get_library_events ()
105105
106- def test_request_success (self , test_instance , mocker ):
106+ def test_get_request_success (self , test_instance , requests_mock ):
107107 start = "2024-11-10T10:00:00"
108108 end = "2024-11-11T10:00:00"
109- expected_headers = {'3mcl-Datetime' : 'Mon, 11 Nov 2024 10:00:00 GMT' ,
110- '3mcl-Authorization' : '3MCLAUTH account_id:KipNmbVsmsT2xPjP4oHAaR3n00JgcszfF6mQRffBoRk=' , # noqa
111- '3mcl-APIVersion' : '3.0.2' ,
112- 'Accept' : 'application/xml' }
113- mock_get = mocker .patch ("requests.sessions.Session.get" )
114- test_instance .request (
109+ url = f"{ _API_URL } { test_instance .library_id } /data/cloudevents?startdate={ start } &enddate={ end } " # noqa
110+ expected_headers = {"3mcl-Datetime" : "Mon, 11 Nov 2024 10:00:00 GMT" ,
111+ "3mcl-Authorization" : "3MCLAUTH account_id:KipNmbVsmsT2xPjP4oHAaR3n00JgcszfF6mQRffBoRk=" , # noqa
112+ "3mcl-APIVersion" : "3.0.2" ,
113+ "Accept" : "application/xml" }
114+ requests_mock .get (
115+ url = url , text = _TEST_LIBRARY_EVENTS_RESPONSE )
116+
117+ response = test_instance .request (
115118 path = f"data/cloudevents?startdate={ start } &enddate={ end } " ,
116119 method_type = "GET" )
117120
118- mock_get .assert_called_once_with (
119- url = f"{ _API_URL } library_id/data/cloudevents?startdate={ start } &enddate={ end } " , # noqa
120- data = None ,
121- headers = expected_headers ,
122- timeout = 60 )
121+ assert response .text == _TEST_LIBRARY_EVENTS_RESPONSE
122+ assert requests_mock .request_history [0 ].method == "GET"
123+ assert requests_mock .request_history [0 ].url == url
124+ assert expected_headers .items () <= dict (
125+ requests_mock .request_history [0 ].headers ).items ()
126+
127+ def test_put_request_success (self , test_instance , requests_mock ):
128+ start = "2024-11-10T10:00:00"
129+ end = "2024-11-11T10:00:00"
130+ url = f"{ _API_URL } { test_instance .library_id } /data/cloudevents?startdate={ start } &enddate={ end } " # noqa
131+ expected_headers = {"3mcl-Datetime" : "Mon, 11 Nov 2024 10:00:00 GMT" ,
132+ "3mcl-Authorization" : "3MCLAUTH account_id:3M773C6ZVWmB/ISoSjQy9iBp48T4tUWhoNOwXaseMtE=" , # noqa
133+ "3mcl-APIVersion" : "3.0.2" ,
134+ "Content-Type" : "application/xml" }
135+ requests_mock .put (
136+ url = url , text = _TEST_LIBRARY_EVENTS_RESPONSE )
137+
138+ response = test_instance .request (
139+ path = f"data/cloudevents?startdate={ start } &enddate={ end } " ,
140+ method_type = "PUT" ,
141+ body = {"test" : "test" })
142+
143+ assert response .text == _TEST_LIBRARY_EVENTS_RESPONSE
144+ assert requests_mock .request_history [0 ].method == "PUT"
145+ assert requests_mock .request_history [0 ].url == url
146+ assert requests_mock .request_history [0 ].body == "test=test"
147+ assert expected_headers .items () <= dict (
148+ requests_mock .request_history [0 ].headers ).items ()
149+
150+ def test_post_request_success (self , test_instance , requests_mock ):
151+ start = "2024-11-10T10:00:00"
152+ end = "2024-11-11T10:00:00"
153+ url = f"{ _API_URL } { test_instance .library_id } /data/cloudevents?startdate={ start } &enddate={ end } " # noqa
154+ expected_headers = {"3mcl-Datetime" : "Mon, 11 Nov 2024 10:00:00 GMT" ,
155+ "3mcl-Authorization" : "3MCLAUTH account_id:vF0zI6ee1w1PbTLQ9EVvtxRly2vpCRxdBdAHb8DZQ4E=" , # noqa
156+ "3mcl-APIVersion" : "3.0.2" ,
157+ "Content-Type" : "application/xml" }
158+ requests_mock .post (
159+ url = url , text = _TEST_LIBRARY_EVENTS_RESPONSE )
160+
161+ response = test_instance .request (
162+ path = f"data/cloudevents?startdate={ start } &enddate={ end } " ,
163+ method_type = "POST" ,
164+ body = {"test" : "test" })
165+
166+ assert response .text == _TEST_LIBRARY_EVENTS_RESPONSE
167+ assert requests_mock .request_history [0 ].method == "POST"
168+ assert requests_mock .request_history [0 ].url == url
169+ assert requests_mock .request_history [0 ].body == "test=test"
170+ assert expected_headers .items () <= dict (
171+ requests_mock .request_history [0 ].headers ).items ()
123172
124173 def test_request_failure (self , test_instance , requests_mock ):
125174 start = "2024-11-10T10:00:00"
0 commit comments