Пример #1
0
 def test_logged_user_allowed(self):
     with self.settings(
             MIDDLEWARE_CLASSES=TestMiddleware.MIDDLEWARE_CLASSES,
             INSTALLED_APPS=TestMiddleware.INSTALLED_APPS):
         api.stop()  # just to be sure
         assert api.is_online()
         self.client.login(**{'username': '******', 'password': '******'})
         response = self.client.get('/admin/')
         self.assertEqual(response.status_code, 200)
         self._activate()
         response = self.client.get('/admin/')
         self.assertEqual(response.status_code, 200)
Пример #2
0
 def test_logged_user_allowed(self):
     with self.settings(
         MIDDLEWARE_CLASSES=TestMiddleware.MIDDLEWARE_CLASSES, INSTALLED_APPS=TestMiddleware.INSTALLED_APPS
     ):
         api.stop()  # just to be sure
         assert api.is_online()
         self.client.login(**{"username": "******", "password": "******"})
         response = self.client.get("/admin/")
         self.assertEqual(response.status_code, 200)
         self._activate()
         response = self.client.get("/admin/")
         self.assertEqual(response.status_code, 200)
Пример #3
0
 def test_logged_user_forced(self):
     # not sure this is required
     # web server should itercept request first
     # in any case double check
     with self.settings(
             MIDDLEWARE_CLASSES=TestMiddleware.MIDDLEWARE_CLASSES,
             INSTALLED_APPS=TestMiddleware.INSTALLED_APPS):
         api.stop()  # just to be sure
         assert api.is_online()
         self.client.login(**{'username': '******', 'password': '******'})
         response = self.client.get('/admin/')
         self.assertEqual(response.status_code, 200)
         self._activate(ignore_session=True)
         response = self.client.get('/admin/')
         self.assertEqual(response.status_code, 302)
Пример #4
0
 def test_logged_user_forced(self):
     # not sure this is required
     # web server should itercept request first
     # in any case double check
     with self.settings(
         MIDDLEWARE_CLASSES=TestMiddleware.MIDDLEWARE_CLASSES, INSTALLED_APPS=TestMiddleware.INSTALLED_APPS
     ):
         api.stop()  # just to be sure
         assert api.is_online()
         self.client.login(**{"username": "******", "password": "******"})
         response = self.client.get("/admin/")
         self.assertEqual(response.status_code, 200)
         self._activate(ignore_session=True)
         response = self.client.get("/admin/")
         self.assertEqual(response.status_code, 302)
Пример #5
0
    def handle_label(self, cmd, **options):
        verbosity = options.get("verbosity")
        timeout = options.get("timeout")
        ignore_session = options.get("ignore_session")
        ret, msg = 0, "Unknow error"
        if cmd not in Command.args:
            raise CommandError("Allowed options are: %s" % self.args)

        if cmd in ("check", "status"):
            ret, msg = api.check()
            print msg
        elif cmd in ("on", "activate"):
            ret, msg = api.start(ignore_session, timeout, verbosity)
            if verbosity >= 1:
                print msg
        elif cmd in ("off", "deactivate"):
            ret, msg = api.stop()
            if verbosity >= 1:
                print msg
        elif cmd in ("list",):
            now = datetime.datetime.now()
            for s in Session.objects.filter(expire_date__gte=now):
                offset = time.mktime(s.expire_date.timetuple()) - time.mktime(now.timetuple())
                print s.pk, s.expire_date, offset
        if ret:
            raise CommandError(msg)
Пример #6
0
    def handle_label(self, cmd, **options):
        verbosity = options.get('verbosity')
        timeout = options.get('timeout')
        ignore_session = options.get('ignore_session')
        ret, msg = 0,'Unknow error'
        if cmd not in Command.args:
            raise CommandError('Allowed options are: %s' % self.args)

        if cmd in ('check', 'status'):
            ret, msg = api.check()
            print msg
        elif cmd in ('on', 'activate'):
            ret, msg = api.start(ignore_session, timeout, verbosity)
            if verbosity >= 1:
                print msg
        elif cmd in ('off', 'deactivate'):
            ret, msg = api.stop()
            if verbosity >= 1:
                print msg
        elif cmd in ('list',):
            now = datetime.datetime.now()
            for s in Session.objects.filter(expire_date__gte=now):
                offset =  (time.mktime(s.expire_date.timetuple())-time.mktime(now.timetuple()))
                print s.pk, s.expire_date, offset
        if ret:
            raise CommandError(msg)
Пример #7
0
 def test_is_online(self):
     ret, msg = api.start()
     self.assertEqual(ret, SUCCESS)
     self.assertFalse(api.is_online())
     api.stop()
     self.assertTrue(api.is_online())
Пример #8
0
 def test_stop(self):
     api.stop()
     self.assertFalse(os.path.exists(api.MAINTENANCE_FILE))
     self.assertFalse(os.path.exists(api.PENDING_MAINTENANCE_FILE))
Пример #9
0
 def tearDown(self):
     api.stop()
Пример #10
0
 def test_is_online(self):
     ret, msg = api.start()
     self.assertEqual(ret, SUCCESS)
     self.assertFalse(api.is_online())
     api.stop()
     self.assertTrue(api.is_online())
Пример #11
0
 def test_stop(self):
     api.stop()
     self.assertFalse(os.path.exists(api.MAINTENANCE_FILE))
     self.assertFalse(os.path.exists(api.PENDING_MAINTENANCE_FILE))
Пример #12
0
 def tearDown(self):
     api.stop()