<commit_before>from django.test import TestCase
from mock import Mock, patch

from django_sql_log.middleware import RequestLoggingMiddleware
from django_sql_log.middleware import ResponseLoggingMiddleware
RequestLoggingMiddleware = Mock(RequestLoggingMiddleware)
ResponseLoggingMiddleware = Mock(ResponseLoggingMiddleware)


class TestSettings(TestCase):
    "Test if the demo settings are correctly done"

    def test_request(self):
        with patch('django_sql_log.middleware.RequestLoggingMiddleware.process_request') as mocked_request:
            self.client.get('/')
            self.assertTrue(mocked_request.called)

    def test_response(self):
        with patch('django_sql_log.middleware.ResponseLoggingMiddleware.process_response') as mocked_response:
            self.client.get('/')
            self.assertTrue(mocked_response.called)<commit_msg>checking for call order (ugly)<commit_after>from django.test import TestCase
from mock import Mock, patch, MagicMock

from django_sql_log.middleware import RequestLoggingMiddleware
from django_sql_log.middleware import ResponseLoggingMiddleware
RequestLoggingMiddleware = Mock(RequestLoggingMiddleware)
ResponseLoggingMiddleware = Mock(ResponseLoggingMiddleware)

REQUEST_MODULE = 'django_sql_log.middleware.RequestLoggingMiddleware' \
                 '.process_request'

RESPONSE_MODULE = 'django_sql_log.middleware.ResponseLoggingMiddleware' \
                  '.process_response'


class TestSettings(TestCase):
    "Test if the demo settings are correctly done"

    def test_request(self):
        with patch(REQUEST_MODULE) as mocked_request:
            self.client.get('/')
            self.assertTrue(mocked_request.called)

    def test_response(self):
        with patch(RESPONSE_MODULE) as mocked_response:
            self.client.get('/')
            self.assertTrue(mocked_response.called)

    def test_order(self):
        manager = MagicMock()
        with patch(REQUEST_MODULE) as Request:
            with patch(RESPONSE_MODULE) as Response:
                manager.attach_mock(Request, 'Request')
                manager.attach_mock(Response, 'Response')
                self.client.get('/')
                # Ugly method, but couldn't find a better one
                first = manager.mock_calls[0].__str__()
                last = manager.mock_calls[-1].__str__()
                self.assertTrue(first.startswith('call.Request'))
                self.assertTrue(last.startswith('call.Response'))
{'fraction_non_alphanumeric': 0.08135320177204994, 'fraction_numerical': 0.0008054772452678212, 'mean_word_length': 3.4120781527531086, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7200042', 'n_tokens_mistral': 659, 'n_tokens_neox': 662, 'n_words': 135}