Example #1
0
 def test_process_response(self, get_cid):
     get_cid.return_value = self.cid
     request = Mock()
     response = {}
     middleware = CidMiddleware()
     response = middleware.process_response(request, response)
     self.assertEqual(response['X_CORRELATION_ID'], self.cid)
Example #2
0
 def test_process_response_with_no_cid(self, get_cid):
     get_cid.return_value = None
     request = Mock()
     response = {}
     middleware = CidMiddleware()
     middleware.process_response(request, response)
     self.assertNotIn('X_CORRELATION_ID', response.keys())
Example #3
0
 def test_process_response(self, get_cid):
     get_cid.return_value = self.cid
     request = Mock()
     response = {}
     middleware = CidMiddleware()
     middleware.process_response(request, response)
     self.assertEqual(response['X_CORRELATION_ID'], self.cid)
Example #4
0
 def test_process_response_custom_header_name(self, get_cid):
     get_cid.return_value = self.cid
     request = Mock()
     response = {}
     middleware = CidMiddleware()
     response = middleware.process_response(request, response)
     self.assertEqual(response['X-Custom-Name'], self.cid)
Example #5
0
 def test_process_response_with_no_cid(self, get_cid):
     get_cid.return_value = None
     request = Mock()
     response = {}
     middleware = CidMiddleware()
     response = middleware.process_response(request, response)
     self.assertNotIn('X_CORRELATION_ID', response.keys())
Example #6
0
 def test_with_cid_from_upstream(self):
     request = make_request('cid-from-upstream')
     middleware = CidMiddleware(get_response=get_response)
     response = middleware(request)
     self.assertEqual(request.correlation_id, 'cid-from-upstream')
     self.assertEqual(cid.locals.get_cid(), 'cid-from-upstream')
     self.assertEqual(response['X_CORRELATION_ID'], 'cid-from-upstream')
Example #7
0
 def test_no_response_header(self):
     request = make_request('cid-from-upstream')
     middleware = CidMiddleware(get_response=get_response)
     response = middleware(request)
     self.assertEqual(request.correlation_id, 'cid-from-upstream')
     self.assertEqual(cid.locals.get_cid(), 'cid-from-upstream')
     self.assertEqual(response.headers, {})
Example #8
0
 def test_custom_response_header(self):
     request = make_request('cid-from-upstream')
     middleware = CidMiddleware(get_response=get_response)
     response = middleware(request)
     self.assertEqual(request.correlation_id, 'cid-from-upstream')
     self.assertEqual(cid.locals.get_cid(), 'cid-from-upstream')
     self.assertEqual(response['X_CUSTOM_HEADER'], 'cid-from-upstream')
Example #9
0
 def test_no_cid_from_upstream(self):
     request = make_request(cid=None)
     middleware = CidMiddleware(get_response=get_response)
     response = middleware(request)
     self.assertIsNone(request.correlation_id, None)
     self.assertIsNone(cid.locals.get_cid(), None)
     self.assertEqual(response.headers, {})
Example #10
0
 def test_generate_cid(self, uuid4):
     uuid4.return_value = 'generated-cid'
     request = make_request(cid=None)
     middleware = CidMiddleware(get_response=get_response)
     response = middleware(request)
     self.assertEqual(request.correlation_id, 'generated-cid')
     self.assertEqual(cid.locals.get_cid(), 'generated-cid')
     self.assertEqual(response['X_CORRELATION_ID'], 'generated-cid')
Example #11
0
 def test_concatenate_ids(self, uuid4):
     uuid4.return_value = 'local-cid'
     request = make_request(cid_='upstream-cid')
     middleware = CidMiddleware(get_response=get_response)
     response = middleware(request)
     self.assertEqual(request.correlation_id, 'upstream-cid, local-cid')
     self.assertEqual(cid.locals.get_cid(), 'upstream-cid, local-cid')
     self.assertEqual(response['X_CORRELATION_ID'], 'upstream-cid, local-cid')
Example #12
0
 def test_process_request_with_custom_header(self, set_cid):
     request = Mock()
     request.META = {'A_TEST_HEADER': 'different-cid'}
     middleware = CidMiddleware()
     middleware.process_request(request)
     set_cid.assert_called_with('different-cid')
Example #13
0
 def test_process_request_with_no_header(self, set_cid):
     request = self.get_mock_request()
     middleware = CidMiddleware()
     middleware.process_request(request)
     set_cid.assert_called_with(None)
Example #14
0
 def test_process_request(self, set_cid):
     request = self.get_mock_request(self.cid)
     middleware = CidMiddleware()
     middleware.process_request(request)
     set_cid.assert_called_with(self.cid)
Example #15
0
 def test_process_request_with_custom_header(self, set_cid):
     request = Mock()
     request.META = {'A_TEST_HEADER': 'different-cid'}
     middleware = CidMiddleware()
     middleware.process_request(request)
     set_cid.assert_called_with('different-cid')
Example #16
0
 def test_process_request_generates_uuid(self, set_cid, uuid4):
     uuid4.return_value = '6fa459ea-ee8a-3ca4-894e-db77e160355e'
     request = self.get_mock_request()
     middleware = CidMiddleware()
     middleware.process_request(request)
     set_cid.assert_called_with('6fa459ea-ee8a-3ca4-894e-db77e160355e')
Example #17
0
 def test_process_request_with_no_header(self, set_cid):
     request = self.get_mock_request()
     middleware = CidMiddleware()
     middleware.process_request(request)
     set_cid.assert_called_with(None)
Example #18
0
 def test_process_request(self, set_cid):
     request = self.get_mock_request(self.cid)
     middleware = CidMiddleware()
     middleware.process_request(request)
     set_cid.assert_called_with(self.cid)
Example #19
0
 def test_process_request_generates_uuid(self, set_cid, uuid4):
     uuid4.return_value = '6fa459ea-ee8a-3ca4-894e-db77e160355e'
     request = self.get_mock_request()
     middleware = CidMiddleware()
     middleware.process_request(request)
     set_cid.assert_called_with('6fa459ea-ee8a-3ca4-894e-db77e160355e')