Ejemplo n.º 1
0
def test_update_entity_existing_failures(session):  # pylint:disable=unused-argument
    """Assert that an Entity can be updated from a dictionary."""
    entity = EntityService.save_entity({
        'businessIdentifier': TestEntityInfo.bc_entity_passcode3['businessIdentifier'],
        'businessNumber': TestEntityInfo.bc_entity_passcode3['businessNumber'],
        'passCode': TestEntityInfo.bc_entity_passcode3['passCode'],
        'name': TestEntityInfo.bc_entity_passcode3['name'],
        'corpTypeCode': TestEntityInfo.bc_entity_passcode3['corpTypeCode']
    })

    assert entity
    assert entity.as_dict()['corp_type']['code'] == 'BC'

    updated_entity_info = {
        'businessIdentifier': TestEntityInfo.bc_entity_passcode4['businessIdentifier'],
        'businessNumber': TestEntityInfo.bc_entity_passcode4['businessNumber'],
        'name': TestEntityInfo.bc_entity_passcode4['name'],
        'corpTypeCode': TestEntityInfo.bc_entity_passcode4['corpTypeCode']
    }
    user_with_token = TestUserInfo.user_test
    user_with_token['keycloak_guid'] = TestJwtClaims.public_user_role['sub']

    with pytest.raises(BusinessException) as exception:
        EntityService.update_entity('invalidbusinessnumber', updated_entity_info,
                                    {'loginSource': '', 'realm_access': {'roles': ['system']},
                                     'corp_type': 'INVALID_CP'})

    assert exception.value.code == Error.DATA_NOT_FOUND.name
Ejemplo n.º 2
0
def test_update_entity_existing_success(session):  # pylint:disable=unused-argument
    """Assert that an Entity can be updated from a dictionary."""
    entity = EntityService.save_entity({
        'businessIdentifier': TestEntityInfo.bc_entity_passcode3['businessIdentifier'],
        'businessNumber': TestEntityInfo.bc_entity_passcode3['businessNumber'],
        'passCode': TestEntityInfo.bc_entity_passcode3['passCode'],
        'name': TestEntityInfo.bc_entity_passcode3['name'],
        'corpTypeCode': TestEntityInfo.bc_entity_passcode3['corpTypeCode']
    })

    assert entity
    assert entity.as_dict()['corp_type']['code'] == 'BC'

    updated_entity_info = {
        'businessIdentifier': TestEntityInfo.bc_entity_passcode4['businessIdentifier'],
        'businessNumber': TestEntityInfo.bc_entity_passcode4['businessNumber'],
        'name': TestEntityInfo.bc_entity_passcode4['name'],
        'corpTypeCode': TestEntityInfo.bc_entity_passcode4['corpTypeCode']
    }
    user_with_token = TestUserInfo.user_test
    user_with_token['keycloak_guid'] = TestJwtClaims.public_user_role['sub']

    updated_entity = EntityService.update_entity(entity.as_dict().get('business_identifier'), updated_entity_info,
                                                 {'loginSource': '', 'realm_access': {'roles': ['system']},
                                                  'corp_type': 'BC'})

    assert updated_entity
    assert updated_entity.as_dict()['name'] == updated_entity_info['name']
    assert updated_entity.as_dict()['business_number'] == updated_entity_info['businessNumber']
Ejemplo n.º 3
0
    def patch(business_identifier):
        """Update an existing business by it's business number."""
        request_json = request.get_json()

        valid_format, errors = schema_utils.validate(request_json, 'entity')
        if not valid_format:
            return {
                'message': schema_utils.serialize(errors)
            }, http_status.HTTP_400_BAD_REQUEST

        try:
            entity = EntityService.update_entity(
                business_identifier,
                request_json,
                token_info=g.jwt_oidc_token_info)
            if entity is not None:
                response, status = entity.as_dict(), http_status.HTTP_200_OK
            else:
                response, status = {'message': 'A business for {} was not found.'.format(business_identifier)}, \
                                   http_status.HTTP_404_NOT_FOUND
        except BusinessException as exception:
            response, status = {
                'code': exception.code,
                'message': exception.message
            }, exception.status_code
        return response, status
Ejemplo n.º 4
0
    def patch(business_identifier):
        """Update an existing business by it's business number."""
        request_json = request.get_json()

        valid_format, errors = schema_utils.validate(request_json, 'entity')
        if not valid_format:
            return {'message': schema_utils.serialize(errors)}, http_status.HTTP_400_BAD_REQUEST

        passcode_reset = request_json.get('resetPasscode', False)

        try:
            if passcode_reset:
                entity = EntityService.reset_passcode(business_identifier,
                                                      email_addresses=request_json.get('passcodeResetEmail', None))
            else:
                entity = EntityService.update_entity(business_identifier, request_json)

            if entity is not None:
                response, status = entity.as_dict(), http_status.HTTP_200_OK
            else:
                response, status = {'message': 'A business for {} was not found.'.format(business_identifier)}, \
                                   http_status.HTTP_404_NOT_FOUND
        except BusinessException as exception:
            response, status = {'code': exception.code, 'message': exception.message}, exception.status_code
        return response, status