# Path: oslo_middleware/correlation_id.py
# class CorrelationId(base.ConfigurableMiddleware):
#     def process_request(self, req):


from unittest import mock
from oslotest import base as test_base
from oslo_middleware import correlation_id
import fixtures
#    under the License.





class CorrelationIdTest(test_base.BaseTestCase):

    def setUp(self):
        super(CorrelationIdTest, self).setUp()

    def test_process_request(self):
        app = mock.Mock()
        req = mock.Mock()
        req.headers = {}

        mock_uuid4 = mock.Mock()
        mock_uuid4.return_value = "fake_uuid"
        self.useFixture(fixtures.MockPatch('uuid.uuid4', mock_uuid4))

        middleware = correlation_id.CorrelationId(app)
        middleware(req)

        self.assertEqual("fake_uuid", req.headers.get("X_CORRELATION_ID"))

    def test_process_request_should_not_regenerate_correlation_id(self):
        app = mock.Mock()
        req = mock.Mock()
        req.headers = {"X_CORRELATION_ID": "correlation_id"}


# Path: oslo_middleware/correlation_id.py
# class CorrelationId(base.ConfigurableMiddleware):
#     def process_request(self, req):


# Path: oslo_middleware/tests/test_correlation_id.py
from unittest import mock
from oslotest import base as test_base
from oslo_middleware import correlation_id
import fixtures

#    under the License.





class CorrelationIdTest(test_base.BaseTestCase):

    def setUp(self):
        super(CorrelationIdTest, self).setUp()

    def test_process_request(self):
        app = mock.Mock()
        req = mock.Mock()
        req.headers = {}

        mock_uuid4 = mock.Mock()
        mock_uuid4.return_value = "fake_uuid"
        self.useFixture(fixtures.MockPatch('uuid.uuid4', mock_uuid4))

        middleware = correlation_id.CorrelationId(app)
        middleware(req)

        self.assertEqual("fake_uuid", req.headers.get("X_CORRELATION_ID"))

    def test_process_request_should_not_regenerate_correlation_id(self):
        app = mock.Mock()
        req = mock.Mock()
        req.headers = {"X_CORRELATION_ID": "correlation_id"}


        middleware = correlation_id.CorrelationId(app)