def create_billing_plan(): with app.app_context(): billing_plan = models.BillingPlan(name='test', max_request_count=10, max_object_count=100, end_point_id=models.EndPoint.get_default().id) models.db.session.add(billing_plan) models.db.session.commit() return billing_plan.id
def post(self): parser = reqparse.RequestParser() parser.add_argument('name', type=unicode, required=True, case_sensitive=False, help='name is required', location=('json', 'values')) parser.add_argument('max_request_count', type=int, required=False, help='max request count for this billing plan', location=('json', 'values')) parser.add_argument('max_object_count', type=int, required=False, help='max object count for this billing plan', location=('json', 'values')) parser.add_argument('default', type=bool, required=False, default=True, help='if this plan is the default one', location=('json', 'values')) parser.add_argument('end_point_id', type=int, required=False, help='id of the end_point', location=('json', 'values')) args = parser.parse_args() if args['end_point_id']: end_point = models.EndPoint.query.get(args['end_point_id']) else: end_point = models.EndPoint.get_default() if not end_point: return ({'error': 'end_point doesn\'t exist'}, 400) try: billing_plan = models.BillingPlan(name=args['name'], max_request_count=args['max_request_count'], max_object_count=args['max_object_count'], default=args['default']) billing_plan.end_point = end_point db.session.add(billing_plan) db.session.commit() return marshal(billing_plan, billing_plan_fields_full) except Exception: logging.exception("fail") raise
def create_multiple_users(request, geojson_polygon): with app.app_context(): end_point = models.EndPoint() end_point.name = 'myEndPoint' billing_plan = models.BillingPlan() billing_plan.name = 'free' billing_plan.end_point = end_point user1 = models.User('foo', '*****@*****.**') user1.end_point = end_point user1.billing_plan = billing_plan user1.shape = json.dumps(geojson_polygon) user2 = models.User('foodefault', '*****@*****.**') user2.end_point = models.EndPoint.get_default() user2.billing_plan = models.BillingPlan.get_default(user2.end_point) models.db.session.add(end_point) models.db.session.add(billing_plan) models.db.session.add(user1) models.db.session.add(user2) models.db.session.commit() # we end the context but need to keep some id for later (object won't survive this lost!) d = { 'user1': user1.id, 'user2': user2.id, 'end_point': end_point.id, 'billing_plan': billing_plan.id } # we can't truncate end_point and billing_plan, so we have to delete them explicitly def teardown(): with app.app_context(): end_point = models.EndPoint.query.get(d['end_point']) billing_plan = models.BillingPlan.query.get(d['billing_plan']) models.db.session.delete(end_point) models.db.session.delete(billing_plan) models.db.session.commit() request.addfinalizer(teardown) return d