def add_user(self): if self.request.method == 'GET': name = self.request.GET['name'] password = self.request.GET['password'] age = self.request.GET['age'] else: name = self.request.POST['name'] password = self.request.POST['password'] age = self.request.POST['age'] user = User(name=name, password=password, age=age) id = user.save() return user.id
def get_users(self): return User.objects()
def get_user_by_name(self, name): return User.objects(name=name).first()
def get_user_name(self, id): user = User.objects(id=id).first() return user.name
def get_user_by_id(self, id): return User.objects(id=id).first()
def update_user(self, id): if self.request.method == 'GET': name = self.request.GET['name'] else: name = self.request.POST['name'] return User.objects(id=id).update_one(set__name=name)
def tearDown(self): User.drop_collection()