def test_create_product_single_subscription_duplicate_error( session, keycloak_mock): # pylint:disable=unused-argument """Assert that an Org can be created.""" user_with_token = TestUserInfo.user_bceid_tester user_with_token['keycloak_guid'] = TestJwtClaims.public_bceid_user['sub'] user = factory_user_model(user_with_token) org = OrgService.create_org(TestOrgInfo.org1, user_id=user.id) assert org dictionary = org.as_dict() assert dictionary['name'] == TestOrgInfo.org1['name'] subscriptions = ProductService.create_product_subscription( dictionary['id'], TestOrgProductsInfo.org_products1, skip_auth=True, token_info=TestJwtClaims.public_bceid_user) assert len(subscriptions) == 1 assert subscriptions[0].product_code == TestOrgProductsInfo.org_products1[ 'subscriptions'][0]['productCode'] with pytest.raises(BusinessException) as exception: ProductService.create_product_subscription( dictionary['id'], TestOrgProductsInfo.org_products1, skip_auth=True, token_info=TestJwtClaims.public_bceid_user) assert exception.value.code == Error.PRODUCT_SUBSCRIPTION_EXISTS.name
def test_update_product_subscription(session, keycloak_mock, monkeypatch): """Assert that updating product subscription works.""" user = factory_user_model(TestUserInfo.user_test) patch_token_info({'sub': user.keycloak_guid}, monkeypatch) org = Org.create_org(TestOrgInfo.org1, user_id=user.id) product_subscription = ProductSubscription( org_id=org._model.id, product_code='PPR', status_code=ProductSubscriptionStatus.ACTIVE.value).flush() class MockContact(object): email = '' class MockPerson(object): def __init__(self, contact: MockContact): self.contact = contact with patch.object(ActivityLogPublisher, 'publish_activity', return_value=None) as mock_alp: with patch.object(ContactLinkModel, 'find_by_user_id', return_value=MockPerson(contact=MockContact())): ProductService.update_product_subscription(product_subscription.id, True, org._model.id) mock_alp.assert_called_with( Activity(action=ActivityAction.ADD_PRODUCT_AND_SERVICE.value, org_id=ANY, value=ANY, id=ANY, name='Personal Property Registry'))
def test_create_product_single_subscription_duplicate_error( session, keycloak_mock, monkeypatch): # pylint:disable=unused-argument """Assert that an Org can be created.""" user_with_token = TestUserInfo.user_bceid_tester user_with_token['keycloak_guid'] = TestJwtClaims.public_bceid_user['sub'] user = factory_user_model(user_with_token) patch_token_info({'sub': user.keycloak_guid}, monkeypatch) org = OrgService.create_org(TestOrgInfo.org1, user_id=user.id) assert org dictionary = org.as_dict() assert dictionary['name'] == TestOrgInfo.org1['name'] patch_token_info(TestJwtClaims.public_bceid_user, monkeypatch) subscriptions = ProductService.create_product_subscription( dictionary['id'], TestOrgProductsInfo.org_products_business, skip_auth=True) assert next(prod for prod in subscriptions if prod.get('code') == TestOrgProductsInfo. org_products_business['subscriptions'][0]['productCode']) with pytest.raises(BusinessException) as exception: ProductService.create_product_subscription( dictionary['id'], TestOrgProductsInfo.org_products_business, skip_auth=True) assert exception.value.code == Error.PRODUCT_SUBSCRIPTION_EXISTS.name
def _update_product_subscription(is_approved: bool, product_subscription_id: int, org_id: int): """Review Product Subscription.""" current_app.logger.debug('<_update_product_subscription ') from auth_api.services import Product as ProductService # pylint:disable=cyclic-import, import-outside-toplevel # Approve/Reject Product subscription ProductService.update_product_subscription(product_subscription_id=product_subscription_id, is_approved=is_approved, org_id=org_id, is_new_transaction=False) current_app.logger.debug('>_update_product_subscription ')
def test_create_product_multiple_subscription(session, keycloak_mock, monkeypatch): # pylint:disable=unused-argument """Assert that an Org can be created.""" user_with_token = TestUserInfo.user_bceid_tester user_with_token['keycloak_guid'] = TestJwtClaims.public_bceid_user['sub'] user = factory_user_model(user_with_token) def token_info(): # pylint: disable=unused-argument; mocks of library methods return { 'sub': str(user_with_token['keycloak_guid']), 'username': '******', 'realm_access': { 'roles': [ 'edit' ] } } monkeypatch.setattr('auth_api.utils.user_context._get_token_info', token_info) org = OrgService.create_org(TestOrgInfo.org1, user_id=user.id) assert org dictionary = org.as_dict() assert dictionary['name'] == TestOrgInfo.org1['name'] subscriptions = ProductService.create_product_subscription(dictionary['id'], TestOrgProductsInfo.org_products2, skip_auth=True, token_info=TestJwtClaims.public_bceid_user) assert next(prod for prod in subscriptions if prod.get('code') == TestOrgProductsInfo.org_products2['subscriptions'][0]['productCode']) assert next(prod for prod in subscriptions if prod.get('code') == TestOrgProductsInfo.org_products2['subscriptions'][1]['productCode'])
def test_get_products(session): # pylint:disable=unused-argument """Assert that the product list can be retrieved.""" response = ProductService.get_products() assert response # assert the structure is correct by checking for name, description properties in each element for item in response: assert item['name'] and item['description']
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 = ProductService.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 get(): """Get a list of all products.""" try: response, status = json.dumps(ProductService.get_products()), http_status.HTTP_200_OK 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 = ProductService.create_product_subscription(dictionary['id'], TestOrgProductsInfo.org_products1, ) assert len(subscriptions) == 1 assert subscriptions[0].product_code == TestOrgProductsInfo.org_products1['subscriptions'][0]['productCode']
def get(org_id): """GET a new product subscription to the org using the request body.""" try: response, status = json.dumps( ProductService.get_all_product_subscription( org_id)), http_status.HTTP_200_OK 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_with_token = TestUserInfo.user_bceid_tester user_with_token['keycloak_guid'] = TestJwtClaims.public_bceid_user['sub'] user = factory_user_model(user_with_token) org = OrgService.create_org(TestOrgInfo.org1, user_id=user.id) assert org dictionary = org.as_dict() assert dictionary['name'] == TestOrgInfo.org1['name'] subscriptions = ProductService.create_product_subscription(dictionary['id'], TestOrgProductsInfo.org_products1, skip_auth=True, token_info=TestJwtClaims.public_bceid_user) assert next(prod for prod in subscriptions if prod.get('code') == TestOrgProductsInfo.org_products1['subscriptions'][0]['productCode'])
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 = ProductService.create_product_subscription( org_id, request_json) response, status = { 'subscriptions': subscriptions }, http_status.HTTP_201_CREATED except BusinessException as exception: response, status = { 'code': exception.code, 'message': exception.message }, exception.status_code return response, status
def get(org_id): """GET a new product subscription to the org using the request body.""" try: include_internal_products = request.args.get( 'includeInternal', 'true').lower() == 'true' products = ProductService.get_all_product_subscription( org_id, include_internal_products=include_internal_products, token_info=g.jwt_oidc_token_info) if products is None: response, status = {'message': 'Not authorized to perform this action'}, \ http_status.HTTP_401_UNAUTHORIZED else: response, status = json.dumps( products), http_status.HTTP_200_OK except BusinessException as exception: response, status = { 'code': exception.code, 'message': exception.message }, exception.status_code return response, status