Merge "update the huawei's lab"
[pharos.git] / tools / pharos-dashboard / account / tests / test_general.py
1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10
11 from django.contrib.auth.models import User
12 from django.test import Client
13 from django.test import TestCase
14 from django.urls import reverse
15 from django.utils import timezone
16
17 from account.models import UserProfile
18
19
20 class AccountMiddlewareTestCase(TestCase):
21     def setUp(self):
22         self.client = Client()
23         self.user1 = User.objects.create(username='user1')
24         self.user1.set_password('user1')
25         self.user1profile = UserProfile.objects.create(user=self.user1)
26         self.user1.save()
27
28     def test_timezone_middleware(self):
29         """
30         The timezone should be UTC for anonymous users, for authenticated users it should be set
31         to user.userprofile.timezone
32         """
33         #default
34         self.assertEqual(timezone.get_current_timezone_name(), 'UTC')
35
36         url = reverse('account:settings')
37         # anonymous request
38         self.client.get(url)
39         self.assertEqual(timezone.get_current_timezone_name(), 'UTC')
40
41         # authenticated user with UTC timezone (userprofile default)
42         self.client.login(username='user1', password='user1')
43         self.client.get(url)
44         self.assertEqual(timezone.get_current_timezone_name(), 'UTC')
45
46         # authenticated user with custom timezone (userprofile default)
47         self.user1profile.timezone = 'Etc/Greenwich'
48         self.user1profile.save()
49         self.client.get(url)
50         self.assertEqual(timezone.get_current_timezone_name(), 'Etc/Greenwich')