@@ -126,3 +126,49 @@ def test_authenticate_failure_empty_values(self, mock_requests):
126126 self .assertDictEqual (response , expected_response )
127127 self .assertEqual (response .get ("code" ), 400 )
128128 self .assertEqual (response .get ("message" ), "Validation error" )
129+
130+ @patch ("loading_api_wrapper.api.requests" )
131+ def test_get_profile_success (self , mock_requests ):
132+ status_code = 200
133+ expected_response = {
134+ "id" : "000000000000000000000000" ,
135+ "name" : "test_username" ,
136+ "email" : "test@email.com" ,
137+ "role" : "user" ,
138+ "createdAt" : "2022-01-01T00:00:00.000Z" ,
139+ }
140+
141+ mock_response = MagicMock ()
142+ mock_response .status_code = status_code
143+ mock_response .json .return_value = expected_response
144+ mock_requests .get .return_value = mock_response
145+
146+ with patch (
147+ "loading_api_wrapper.api.LoadingApiWrapper._authenticate"
148+ ) as mock_auth :
149+ mock_auth .return_value = {"code" : 200 , "cookies" : self .cookie_jar }
150+ api = LoadingApiWrapper ("test@email.com" , "password" )
151+ response = api .get_profile ()
152+
153+ self .assertIsNotNone (api .cookies )
154+ self .assertEqual (api .cookies , self .cookie_jar )
155+ self .assertEqual (response .get ("code" ), 200 )
156+ self .assertDictEqual (response .get ("profile" ), expected_response )
157+
158+ @patch ("loading_api_wrapper.api.requests" )
159+ def test_get_profile_failure (self , mock_requests ):
160+ status_code = 401
161+ expected_response = {"code" : status_code , "message" : "No auth token" }
162+
163+ mock_response = MagicMock ()
164+ mock_response .status_code = status_code
165+ mock_response .json .return_value = expected_response
166+
167+ mock_requests .get .return_value = mock_response
168+
169+ api = LoadingApiWrapper ()
170+ response = api .get_profile ()
171+
172+ self .assertIsNone (api .cookies )
173+ self .assertEqual (response .get ("code" ), 401 )
174+ self .assertEqual (response .get ("message" ), "No auth token" )
0 commit comments