def post(org_id): """Post a new product subscription to the org using the request body.""" request_json = request.get_json() valid_format, errors = schema_utils.validate( request_json, 'org_product_subscription') if not valid_format: return { 'message': schema_utils.serialize(errors) }, http_status.HTTP_400_BAD_REQUEST try: subscriptions = OrgService.create_product_subscription( org_id, request_json) if subscriptions is None: response, status = {'message': 'Not authorized to perform this action'}, \ http_status.HTTP_401_UNAUTHORIZED else: response, status = {'subscriptions': ProductSubscriptionSchema().dump(subscriptions, many=True)}, \ http_status.HTTP_201_CREATED except BusinessException as exception: response, status = { 'code': exception.code, 'message': exception.message }, exception.status_code return response, status
def test_create_product_single_subscription(session, keycloak_mock): # pylint:disable=unused-argument """Assert that an Org can be created.""" user = factory_user_model() org = OrgService.create_org(TestOrgInfo.org1, user_id=user.id) assert org dictionary = org.as_dict() assert dictionary['name'] == TestOrgInfo.org1['name'] subscriptions = OrgService.create_product_subscription( dictionary['id'], TestOrgProductsInfo.org_products1, ) assert len(subscriptions) == 1 assert subscriptions[0].product_code == TestOrgProductsInfo.org_products1[ 'subscriptions'][0]['productCode']