def post(self): username, password = ( self.get_argument("username"), self.get_argument("password") ) if username and password and UserMeta.check_password(username=username, password=password): self.set_secure_cookie("username", username) query_data = UserMeta.query.filter_by(username=username).first() session.close() self.write({ "id": query_data.id, "username": username, "type": query_data.user_type }) else: self.write({ "msg": "Wrong username or password" })
def test_check_password_if_not_has_user(self, session): with mock.patch.object(UserMeta, "query", session.query_property()) as _query: self.assertFalse(UserMeta.check_password("Bob", "chkpasswd"))
def test_check_password_if_has_user(self, session): _insert_data = UserMeta(username="******", user_type=2, password="******", public_key="/path/key2.pub") session.add(_insert_data) with mock.patch.object(UserMeta, "query", session.query_property()) as _query: self.assertTrue(UserMeta.check_password("Bob", "chkpasswd"))