Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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'])
Ejemplo n.º 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'])
Ejemplo n.º 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"])
Ejemplo n.º 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)
Ejemplo n.º 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"])
Ejemplo n.º 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)
Ejemplo n.º 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'],
                  })
Ejemplo n.º 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"))
Ejemplo n.º 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'],
                  })
Ejemplo n.º 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'])
Ejemplo n.º 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'])
Ejemplo n.º 18
0
 def test_maintenance_off(self):
     set_maintenance_mode(False)
     response = self.client.get(reverse('maintenance'))
     self.assertRedirects(response, '/')
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 22
0
 def test_maintenance_off(self):
     set_maintenance_mode(False)
     response = self.client.get(reverse("maintenance"))
     self.assertRedirects(response, "/")
Ejemplo n.º 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)