示例#1
0
def factory_product_model(org_id: str,
                          product_code: str = 'PPR'):
    """Produce a templated product model."""
    subscription = ProductSubscriptionModel(org_id=org_id, product_code=product_code)
    subscription.save()

    return subscription
示例#2
0
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 factory_product_model(org_id: str,
                          product_code: str = 'PPR',
                          product_role_codes: list = ['search']
                          ):
    """Produce a templated product model."""
    subscription = ProductSubscriptionModel(org_id=org_id, product_code=product_code)
    subscription.save()

    # Save product roles
    for role_code in product_role_codes:
        product_role_code = ProductRoleCodeModel.find_by_code_and_product_code(role_code, product_code)
        product_role = ProductSubscriptionRoleModel(product_subscription_id=subscription.id,
                                                    product_role_id=product_role_code.id)
        product_role.save()

    return subscription