示例#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
文件: tests.py 项目: wczyz/oioioi
 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
文件: tests.py 项目: wczyz/oioioi
 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
文件: views.py 项目: wczyz/oioioi
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
文件: tests.py 项目: marmistrz/oioioi
 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)