Exemplo n.º 1
0
 def stop_task(cls, name):
     task = Backend('task').find(name)
     if not task.is_running():
         task.status = Task.STOP
         Backend('task').save(task)
         return True
     return False
Exemplo n.º 2
0
 def test_save(self):
     task = Backend('task').find('job_test')
     task.fresh()
     task.attempts += 1
     task.status = Task.COMPLETED
     Backend('task').save(task)
     task = Backend('task').find('job_test')
     assert task.name == self.task.name
     assert task.event == self.task.event
     assert task.run_times == 1
     assert task.attempts == self.task.attempts + 1
     assert task.status == Task.COMPLETED
     assert task.last_five_logs[0]['status'] == Task.SCHEDULED
Exemplo n.º 3
0
    def test_save(self):
        # on dup
        user = Backend('user').find(self.uid)
        user.status = 'banned'
        Backend('user').save(user)
        user = Backend('user').find(self.uid)
        assert user.status == 'banned'

        # new case
        user = User('username', 'email2', 'real_name', 'password', 'active')
        Backend('user').save(user)
        user = Backend('user').find_by_email(self.user.email)
        assert user is not None
Exemplo n.º 4
0
 def test_save(self):
     task = Backend('task').find('job_test')
     task.fresh()
     task.attempts += 1
     task.status = Task.COMPLETED
     Backend('task').save(task)
     task = Backend('task').find('job_test')
     assert task.name == self.task.name
     assert task.event == self.task.event
     assert task.run_times == 1
     assert task.attempts == self.task.attempts + 1
     assert task.status == Task.COMPLETED
     assert task.last_five_logs[0]['status'] == Task.SCHEDULED
Exemplo n.º 5
0
    def test_save(self):
        # on dup
        user = Backend('user').find(self.uid)
        user.status = 'banned'
        Backend('user').save(user)
        user = Backend('user').find(self.uid)
        assert user.status == 'banned'

        # new case
        user = User('username', 'email2', 'real_name', 'password', 'active')
        Backend('user').save(user)
        user = Backend('user').find_by_email(self.user.email)
        assert user is not None
Exemplo n.º 6
0
    def edit_task(self,  name, action, data, event, status):
        try:
            action, data, status = self.process_task_args(action, data, status)
        except TypeError as e:
            return {'msg': str(e), 'status': 'error'}

        task = Backend('task').find(name)
        if not task:
            raise cherrypy.HTTPError(404, 'nof found')

        if not task.is_running():
            task.action = action
            task.status = status
            try:
                task.event = event
            except:
                return {'msg': 'event invalid', 'status': 'error'}
            Backend('task').save(task)
            return {'status': 'info', 'msg': 'saved', }
        else:
            return {'status': 'error', 'msg': 'The task is runnig'}
Exemplo n.º 7
0
    def edit_user(self, uid, email, real_name, password, newpass1, newpass2, status, role='user'):
        real_name, newpass1, newpass2 = real_name.strip(), newpass1.strip(), newpass2.strip()

        uid = int(uid)
        user = Backend('user').find(uid)
        if not user:
            raise cherrypy.HTTPError(404, 'user not found')

        me = cherrypy.request.user
        if me.uid == user.uid:
            if re.match(r'[A-Za-z0-9@#$%^&+=]{4,16}', newpass1):
                if password and newpass1 and newpass1 == newpass2:
                    user.password = newpass1
            elif newpass1:
                return {'status' : 'error', 'msg' : 'password: %s must be the [A-Za-z0-9_]{4,16} pattern' %(newpass1)}

            if len(email) > 7 and re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", email):
                user_ = Backend('user').find_by_email(email)
                if user_ and user_.uid != user.uid:
                    return {'status' : 'error', 'msg' : 'email:%s is used' %(email)}
                else:
                    user.email = email


        if me.uid == 1 and user.uid != 1:
            if role in (ADMIN, USER):
                user.role = role
            if user.status != status and status in USER_STATUSES:
                user.status = status

        if re.match(r'^[A-Za-z0-9_ ]{4,16}$', real_name):
            if user.real_name != real_name:
                user.real_name = real_name

        Backend('user').save(user)
        return  {'status' : 'info', 'msg' : 'updated'}