def delete_role(role_name): try: role = Role.get_one(db.session.query, role_name) if role: db.session.delete(role) db.session.commit() except Exception as e: abort(500) return jsonify(result=dict(message="OK", request="delete role", payload=str(request.json)))
def update_role(old_role_name): if not is_json_request(request) or not is_valid_keys(request.json, ["role"]): abort(400) new_role_name = request.json["role"] try: role = Role.get_one(db.session.query, old_role_name) role.role_name = new_role_name db.session.commit() except Exception as e: abort(500) return jsonify(result=[dict(message="OK", request="update role", payload=str(request.json))])
def test_get_one_miss(self): expected = None self.create_test_role_data() role = Role.get_one(db.session.query, 'we') actual = role self.assertEqual(expected, actual)
def test_get_one(self): expected = 'web' self.create_test_role_data() role = Role.get_one(db.session.query, 'web') actual = role.role_name self.assertEqual(expected, actual)