<commit_before>import logging

import django.test
import django.test.client
import django.utils.timezone

from .. import models
from .. import middleware


logging.disable(logging.CRITICAL)


class TimezoneMiddlewareTestCase(django.test.TestCase):
    fixtures = ('test_companies.json', )

    def setUp(self):
        self.factory = django.test.client.RequestFactory()
        self.company = models.Company.objects.get(pk=1)
        self.user = models.User.objects.create_user(
            email='<EMAIL>', password='<PASSWORD>', first_name='test', last_name='user', company=self.company)

    def test_process_request(self):
        request = self.factory.get('/admin')
        request.user = self.user
        self.assertEqual(django.utils.timezone.get_current_timezone(), django.utils.timezone.get_default_timezone())
        tz_middleware = middleware.TimezoneMiddleware()
        tz_middleware.process_request(request)
        self.assertEqual(django.utils.timezone.get_current_timezone(), self.user.timezone)<commit_msg>fix broken unit test for timezone middleware<commit_after>import logging

import django.test
import django.test.client
import django.utils.timezone

import pytz

from .. import models
from .. import middleware


logging.disable(logging.CRITICAL)


class TimezoneMiddlewareTestCase(django.test.TestCase):
    fixtures = ('test_companies.json', )

    def setUp(self):
        self.factory = django.test.client.RequestFactory()
        self.company = models.Company.objects.get(pk=1)
        self.user = models.User.objects.create_user(
            email='<EMAIL>', password='<PASSWORD>', first_name='test', last_name='user', company=self.company)

    def test_process_request(self):
        request = self.factory.get('/admin/')
        request.user = self.user
        tz_middleware = middleware.TimezoneMiddleware()
        tz_middleware.process_request(request)
        self.assertEqual(django.utils.timezone.get_current_timezone(), self.user.timezone)

        # test changing user timezone
        self.user.timezone = pytz.timezone('Asia/Singapore')
        self.user.save()

        tz_middleware.process_request(request)
        self.assertEqual(django.utils.timezone.get_current_timezone(), self.user.timezone)
{'fraction_non_alphanumeric': 0.11442564559216385, 'fraction_numerical': 0.0008904719501335708, 'mean_word_length': 3.770700636942675, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5879050', 'n_tokens_mistral': 661, 'n_tokens_neox': 649, 'n_words': 105}