Пример #1
0
 def test_not_logged_redirect(self):
     set_maintenance_mode(True, 'test message')
     response = self.client.get('/', follow=True)
     self.assertRedirects(response, reverse('maintenance'))
     self.assertEqual(response.context['message'], 'test message')
     self.assertContains(response, 'test message')
     response = self.client.get(reverse('login'))
     self.assertEqual(response.status_code, 200)
Пример #2
0
    def handle(self, *args, **options):
        state_value = options['mode']

        if state_value == 'on':
            message = options['message']
            set_maintenance_mode(True, message)
        elif state_value == 'off':
            set_maintenance_mode(False)
Пример #3
0
 def test_not_logged_redirect(self):
     set_maintenance_mode(True, 'test message')
     response = self.client.get('/', follow=True)
     self.assertRedirects(response, reverse('maintenance'))
     self.assertEqual(response.context['message'], 'test message')
     self.assertContains(response, 'test message')
     response = self.client.get(reverse('login'))
     self.assertEqual(response.status_code, 200)
Пример #4
0
 def test_not_logged_redirect(self):
     set_maintenance_mode(True, "test message")
     response = self.client.get("/", follow=True)
     self.assertRedirects(response, reverse("maintenance"))
     self.assertEquals(response.context["message"], "test message")
     self.assertContains(response, "test message")
     response = self.client.post(reverse("login"))
     self.assertEquals(response.status_code, 200)
Пример #5
0
    def handle(self, *args, **options):
        state_value = options['mode']

        if state_value == 'on':
            message = options['message']
            set_maintenance_mode(True, message)
        elif state_value == 'off':
            set_maintenance_mode(False)
Пример #6
0
 def test_su_no_redirect(self):
     set_maintenance_mode(True, 'test message')
     self.assertTrue(self.client.login(username='******'))
     self.client.post(reverse('su'), {
         'user': '******',
         'backend': 'django.contrib.auth.backends.ModelBackend',
     })
     response = self.client.get('/')
     self.assertEqual(response.status_code, 200)
Пример #7
0
 def test_set_maintenance(self):
     set_maintenance_mode(True, 'test')
     info = get_maintenance_mode()
     self.assertEqual('test', info['message'])
     self.assertEqual(True, info['state'])
     set_maintenance_mode(False)
     info = get_maintenance_mode()
     self.assertEqual('', info['message'])
     self.assertEqual(False, info['state'])
Пример #8
0
 def test_set_maintenance(self):
     set_maintenance_mode(True, 'test')
     info = get_maintenance_mode()
     self.assertEqual('test', info['message'])
     self.assertEqual(True, info['state'])
     set_maintenance_mode(False)
     info = get_maintenance_mode()
     self.assertEqual('', info['message'])
     self.assertEqual(False, info['state'])
Пример #9
0
 def test_set_maintenance(self):
     set_maintenance_mode(True, "test")
     info = get_maintenance_mode()
     self.assertEquals("test", info["message"])
     self.assertEquals(True, info["state"])
     set_maintenance_mode(False)
     info = get_maintenance_mode()
     self.assertEquals("", info["message"])
     self.assertEquals(False, info["state"])
Пример #10
0
 def test_logged_user_redirect(self):
     set_maintenance_mode(True, "test message")
     self.client.login(username="******")
     response = self.client.get("/", follow=True)
     self.assertRedirects(response, reverse("maintenance"))
     self.assertContains(response, "test message")
     response = self.client.post(
         reverse("logout"), {"user": "******", "backend": "django.contrib.auth.backends.ModelBackend"}
     )
     self.assertIn("been logged out", response.content)
Пример #11
0
 def test_admin_change_message(self):
     set_maintenance_mode(False)
     self.client.login(username="******")
     self.client.post(reverse("set_maintenance_mode"), {"message": "new test message", "set_button": 1})
     info = get_maintenance_mode()
     self.assertEquals("new test message", info["message"])
     self.assertEquals(True, info["state"])
     self.client.post(reverse("set_maintenance_mode"), {"turn_off_button": 1})
     info = get_maintenance_mode()
     self.assertEquals(False, info["state"])
Пример #12
0
 def test_logged_user_redirect(self):
     set_maintenance_mode(True, 'test message')
     self.assertTrue(self.client.login(username='******'))
     response = self.client.get('/', follow=True)
     self.assertRedirects(response, reverse('maintenance'))
     self.assertContains(response, 'test message')
     response = self.client.post(reverse('logout'), {
         'user': '******',
         'backend': 'django.contrib.auth.backends.ModelBackend',
     })
     self.assertEqual(response.status_code, 302)
Пример #13
0
def set_maintenance_mode_view(request):
    if request.method == 'POST':
        if 'set_button' in request.POST:
            message = request.POST['message']
            set_maintenance_mode(True, message)
        elif 'turn_off_button' in request.POST:
            set_maintenance_mode(False)

    maintenance_info = get_maintenance_mode()
    return render(request, 'set_maintenance.html',
                  {
                      'message': maintenance_info['message'],
                      'state': maintenance_info['state'],
                  })
Пример #14
0
    def handle(self, *args, **options):
        if len(args) == 0 or len(args) > 2:
            raise CommandError(_("Expected one or two arguments"))

        state_value = args[0].lower()
        if state_value in ['on', 'yes', 'true', '1']:
            message = ''
            if len(args) > 1:
                message = args[1]
            set_maintenance_mode(True, message)
        elif state_value in ['off', 'no', 'false', '0']:
            set_maintenance_mode(False)
        else:
            raise CommandError(_("Unrecognized first argument"))
Пример #15
0
def set_maintenance_mode_view(request):
    if request.method == 'POST':
        if 'set_button' in request.POST:
            message = request.POST['message']
            set_maintenance_mode(True, message)
        elif 'turn_off_button' in request.POST:
            set_maintenance_mode(False)

    maintenance_info = get_maintenance_mode()
    return render(request, 'set_maintenance.html',
                  {
                      'message': maintenance_info['message'],
                      'state': maintenance_info['state'],
                  })
Пример #16
0
 def test_admin_change_message(self):
     set_maintenance_mode(False)
     self.assertTrue(self.client.login(username='******'))
     self.client.post(reverse('set_maintenance_mode'), {
         'message': 'new test message',
         'set_button': 1,
     })
     info = get_maintenance_mode()
     self.assertEqual('new test message', info['message'])
     self.assertEqual(True, info['state'])
     self.client.post(reverse('set_maintenance_mode'), {
         'turn_off_button': 1,
     })
     info = get_maintenance_mode()
     self.assertEqual(False, info['state'])
Пример #17
0
 def test_admin_change_message(self):
     set_maintenance_mode(False)
     self.client.login(username='******')
     self.client.post(reverse('set_maintenance_mode'), {
         'message': 'new test message',
         'set_button': 1,
     })
     info = get_maintenance_mode()
     self.assertEquals('new test message', info['message'])
     self.assertEquals(True, info['state'])
     self.client.post(reverse('set_maintenance_mode'), {
         'turn_off_button': 1,
     })
     info = get_maintenance_mode()
     self.assertEquals(False, info['state'])
Пример #18
0
 def test_maintenance_off(self):
     set_maintenance_mode(False)
     response = self.client.get(reverse('maintenance'))
     self.assertRedirects(response, '/')
Пример #19
0
 def test_logged_admin_no_redirect(self):
     set_maintenance_mode(True, 'test message')
     self.assertTrue(self.client.login(username='******'))
     response = self.client.get('/')
     self.assertEqual(response.status_code, 200)
Пример #20
0
 def test_logged_admin_no_redirect(self):
     set_maintenance_mode(True, 'test message')
     self.assertTrue(self.client.login(username='******'))
     response = self.client.get('/')
     self.assertEqual(response.status_code, 200)
Пример #21
0
 def test_su_no_redirect(self):
     set_maintenance_mode(True, "test message")
     self.client.login(username="******")
     self.client.post(reverse("su"), {"user": "******", "backend": "django.contrib.auth.backends.ModelBackend"})
     response = self.client.get("/")
     self.assertEquals(response.status_code, 200)
Пример #22
0
 def test_maintenance_off(self):
     set_maintenance_mode(False)
     response = self.client.get(reverse("maintenance"))
     self.assertRedirects(response, "/")
Пример #23
0
 def test_logged_admin_no_redirect(self):
     set_maintenance_mode(True, "test message")
     self.client.login(username="******")
     response = self.client.get("/")
     self.assertEquals(response.status_code, 200)