def test_get_light_request_not_found(self): self.cache_mock.get_and_remove.return_value = None token, encoded = self.get_token() view = ProxyServiceRequestView() view.request = self.factory.post(self.url, {'test_token': encoded}) view.light_token = token view.storage = IgniteStorage('test.example.net', 1234, 'test-proxy-service-request-cache', '') with self.assertRaisesMessage(SecurityError, 'Request not found in light storage'): view.get_light_request()
def test_get_light_request_success(self): orig_light_request = LightRequest(**LIGHT_REQUEST_DICT) self.cache_mock.get_and_remove.return_value = dump_xml(orig_light_request.export_xml()).decode('utf-8') token, encoded = self.get_token() view = ProxyServiceRequestView() view.request = self.factory.post(self.url, {'test_token': encoded}) view.light_token = token view.storage = IgniteStorage('test.example.net', 1234, 'test-proxy-service-request-cache', '') light_request = view.get_light_request() self.assertEqual(light_request, orig_light_request) self.maxDiff = None self.assertEqual(self.client_mock.mock_calls, [call.connect('test.example.net', 1234), call.get_cache('test-proxy-service-request-cache'), call.get_cache().get_and_remove('request-token-id')])