Exemplo n.º 1
0
def test_delete_bad_id(session):
    """Assert that delete by invalid document ID works as expected."""
    with pytest.raises(BusinessException) as not_found_err:
        Draft.delete('X12345X')

    # check
    assert not_found_err
    assert not_found_err.value.status_code == HTTPStatus.NOT_FOUND
Exemplo n.º 2
0
def test_find_by_document_id_invalid(session):
    """Assert that the find draft statement by invalid document returns the expected result."""
    with pytest.raises(BusinessException) as not_found_err:
        Draft.find_by_document_number('X12345X', False)

    # check
    assert not_found_err
    assert not_found_err.value.status_code == HTTPStatus.NOT_FOUND
Exemplo n.º 3
0
def test_update_invalid(session):
    """Assert that an update draft statement with a non-existent document id returns the expected result."""
    json_data = copy.deepcopy(DRAFT_CHANGE_STATEMENT)

    with pytest.raises(BusinessException) as not_found_err:
        Draft.update(json_data, 'X12345X')

    # check
    assert not_found_err
    assert not_found_err.value.status_code == HTTPStatus.NOT_FOUND
Exemplo n.º 4
0
    def post():
        """Create a new draft statement."""
        try:

            # Quick check: must provide an account ID.
            account_id = get_account_id(request)
            if account_id is None:
                return account_required_response()

            # Verify request JWT and account ID
            if not authorized(account_id, jwt):
                return unauthorized_error_response(account_id)

            request_json = request.get_json(silent=True)
            # Disable schema validation: draft may be partial/incomplele.
            # valid_format, errors = schema_utils.validate(request_json, 'draft', 'ppr')
            # if not valid_format:
            #   return validation_error_response(errors, VAL_ERROR)

            # Save new draft statement: BusinessException raised if failure.
            draft = Draft.create_from_json(request_json, account_id)
            draft.save()

            return draft.json, HTTPStatus.CREATED

        except BusinessException as exception:
            return business_exception_response(exception)
        except Exception as default_exception:  # noqa: B902; return nicer default error
            return default_exception_response(default_exception)
Exemplo n.º 5
0
    def put(document_id):
        """Update a draft statement by document ID with data in the request body."""
        try:
            if document_id is None:
                return path_param_error_response('document ID')

            # Quick check: must provide an account ID.
            account_id = get_account_id(request)
            if account_id is None:
                return account_required_response()

            # Verify request JWT and account ID
            if not authorized(account_id, jwt):
                return unauthorized_error_response(account_id)

            request_json = request.get_json(silent=True)
            # Disable schema validation: draft may be partial/incomplele.
            # valid_format, errors = schema_utils.validate(request_json, 'draft', 'ppr')
            # if not valid_format:
            #   return validation_error_response(errors, VAL_ERROR)

            # Save draft statement update: BusinessException raised if failure.
            draft = Draft.update(request_json, document_id)
            draft.save()

            return draft.json, HTTPStatus.OK

        except BusinessException as exception:
            return business_exception_response(exception)
        except Exception as default_exception:  # noqa: B902; return nicer default error
            return default_exception_response(default_exception)
Exemplo n.º 6
0
def test_find_all_by_account_id(session):
    """Assert that the draft summary list first item contains all expected elements."""
    draft_list = Draft.find_all_by_account_id('PS12345')
    assert draft_list[0]['type']
    assert draft_list[0]['documentId']
    assert draft_list[0]['registrationType']
    assert draft_list[0]['path']
    assert draft_list[0]['createDateTime']
Exemplo n.º 7
0
def test_draft_create_from_json(session):
    """Assert that the draft creates from json data correctly."""
    json_data = copy.deepcopy(DRAFT_CHANGE_STATEMENT)
    draft = Draft.create_from_json(json_data, 'PS12345')

    assert draft.draft
    assert draft.account_id == 'PS12345'
    assert draft.registration_type_cl == 'CHANGE'
    assert draft.registration_type_cd == json_data['changeStatement']['changeType']
    assert draft.registration_number == json_data['changeStatement']['baseRegistrationNumber']

    json_data = copy.deepcopy(DRAFT_AMENDMENT_STATEMENT)
    draft = Draft.create_from_json(json_data, 'PS12345')

    assert draft.draft
    assert draft.account_id == 'PS12345'
    assert draft.registration_type_cl == 'COURTORDER'
    assert draft.registration_type_cd == 'CO'
    assert draft.registration_number == json_data['amendmentStatement']['baseRegistrationNumber']
Exemplo n.º 8
0
def test_find_by_document_id_amendment(session):
    """Assert that the find draft amendment statement by document id contains all expected elements."""
    draft = Draft.find_by_document_number('D-T-AM01', True)
    assert draft
    json_data = draft.json
    assert json_data['amendmentStatement']
    assert json_data['type'] == 'AMENDMENT_STATEMENT'
    assert json_data['amendmentStatement']['registeringParty']
    assert json_data['amendmentStatement']['baseRegistrationNumber']
    assert json_data['amendmentStatement']['changeType']
Exemplo n.º 9
0
def test_find_by_document_id_financing(session):
    """Assert that the find draft financing statement by document id contains all expected elements."""
    draft = Draft.find_by_document_number('D-T-FS01', True)
    assert draft
    json_data = draft.json
    assert json_data['financingStatement']
    assert json_data['type'] == 'FINANCING_STATEMENT'
    assert json_data['financingStatement']['securedParties'][0]
    assert json_data['financingStatement']['debtors'][0]
    assert json_data['financingStatement']['vehicleCollateral'][0]
    assert json_data['financingStatement']['lifeYears']
Exemplo n.º 10
0
def test_save_then_delete(session):
    """Assert that a save then delete draft statement returns the expected result."""
    json_data = copy.deepcopy(DRAFT_CHANGE_STATEMENT)

    new_draft = Draft.create_from_json(json_data, 'PS12345')
    new_draft.save()
    draft = new_draft.json
    assert draft
    assert draft['changeStatement']
    assert draft['type'] == 'CHANGE_STATEMENT'
    assert draft['createDateTime']
    assert draft['changeStatement']['registeringParty']
    assert draft['changeStatement']['baseRegistrationNumber']
    assert draft['changeStatement']['changeType']
    assert draft['changeStatement']['documentId']

    # Now test delete draft
    document_id = draft['changeStatement']['documentId']
    delete_draft = Draft.delete(document_id)
    assert delete_draft
Exemplo n.º 11
0
def test_update(session):
    """Assert that a valid update draft statement returns the expected result."""
    json_data = copy.deepcopy(DRAFT_CHANGE_STATEMENT)
    updated = Draft.update(json_data, 'D-T-CH01')
    updated.save()
    draft = updated.json
    assert draft
    assert draft['changeStatement']
    assert draft['type'] == 'CHANGE_STATEMENT'
    assert draft['createDateTime']
    assert draft['lastUpdateDateTime']
    assert draft['changeStatement']['registeringParty']
    assert draft['changeStatement']['baseRegistrationNumber']
    assert draft['changeStatement']['changeType']
    assert draft['changeStatement']['documentId']
Exemplo n.º 12
0
    def delete(document_id):
        """Delete a draft statement by document ID."""
        try:
            if document_id is None:
                return path_param_error_response('document ID')

            # Quick check: must be staff or provide an account ID.
            account_id = get_account_id(request)
            if not is_staff(jwt) and account_id is None:
                return account_required_response()

            # Verify request JWT and account ID
            if not authorized(account_id, jwt):
                return unauthorized_error_response(account_id)

            # Try to fetch draft statement by document ID
            Draft.delete(document_id)

            return '', HTTPStatus.NO_CONTENT

        except BusinessException as exception:
            return business_exception_response(exception)
        except Exception as default_exception:  # noqa: B902; return nicer default error
            return default_exception_response(default_exception)
Exemplo n.º 13
0
def test_draft_json(session):
    """Assert that the draft renders to a json format correctly."""
    json_data = copy.deepcopy(DRAFT_CHANGE_STATEMENT)
    draft = Draft(
        document_number='TEST1234',
        account_id='PS12345',
        create_ts=now_ts(),
        registration_type=json_data['changeStatement']['changeType'],
        registration_type_cl='CHANGE',
        draft=json_data,  # json.dumps(json_data),
        registration_number=json_data['changeStatement']
        ['baseRegistrationNumber'])

    draft_json = draft.json
    assert draft_json
    assert draft_json['type'] == 'CHANGE_STATEMENT'
Exemplo n.º 14
0
def test_save(session, reg_type, account_id, create_draft):
    """Assert that saveing a valid financing statement works as expected."""
    json_data = copy.deepcopy(FINANCING_STATEMENT)
    json_data['type'] = reg_type
    del json_data['createDateTime']
    del json_data['baseRegistrationNumber']
    del json_data['payment']
    del json_data['lifeInfinite']
    del json_data['expiryDate']
    del json_data['documentId']
    if reg_type != model_utils.REG_TYPE_REPAIRER_LIEN:
        del json_data['lienAmount']
        del json_data['surrenderDate']
    if reg_type != model_utils.REG_TYPE_SECURITY_AGREEMENT:
        del json_data['trustIndenture']
        del json_data['generalCollateral']
    if reg_type == model_utils.REG_TYPE_OTHER:
        json_data['otherTypeDescription'] = 'TEST OTHER DESC'

    if create_draft:
        draft_json = copy.deepcopy(DRAFT_FINANCING_STATEMENT)
        draft = Draft.create_from_json(draft_json, account_id)
        draft.save()
        assert draft.document_number
        json_data['documentId'] = draft.document_number

    statement = FinancingStatement.create_from_json(json_data, account_id,
                                                    'UNIT_TEST')
    statement.save()
    assert statement.id
    assert statement.registration[0].account_id == account_id
    assert statement.registration[0].user_id == 'UNIT_TEST'
    result = statement.json
    assert result
    assert result['baseRegistrationNumber']
    assert result['registrationDescription']
    assert result['registrationAct']
    assert result['createDateTime']
    assert result['registeringParty']
    assert result['debtors'][0]
    assert result['securedParties'][0]
    assert result['vehicleCollateral'][0]
    if reg_type == model_utils.REG_TYPE_SECURITY_AGREEMENT:
        assert result['generalCollateral'][0]
    assert 'documentId' not in result
    if reg_type == model_utils.REG_TYPE_OTHER:
        assert result['otherTypeDescription'] == 'TEST OTHER DESC'
Exemplo n.º 15
0
def test_find_all_by_account_id(session):
    """Assert that the draft summary list items contains all expected elements."""
    draft_list = Draft.find_all_by_account_id('PS12345')
    # print(draft_list)
    assert draft_list
    for draft in draft_list:
        assert draft['type']
        assert draft['documentId']
        assert draft['registrationType']
        assert draft['registrationDescription']
        assert draft['createDateTime']
        assert draft['lastUpdateDateTime']
        # assert draft['clientReferenceId']
        assert draft['path']
        assert draft['registeringName']
        if draft['type'] != 'FINANCING_STATEMENT':
            assert draft['baseRegistrationNumber']
        assert draft['documentId'] != 'D-T-0001'
Exemplo n.º 16
0
def test_save_amendment_from_draft(session):
    """Assert that creating an amendment statement from a draft on a non-RL financing statement.

    Verify it contains all expected elements.
    """
    json_data = copy.deepcopy(AMENDMENT_STATEMENT)
    del json_data['createDateTime']
    del json_data['amendmentRegistrationNumber']
    del json_data['payment']

    financing_statement = FinancingStatement.find_by_financing_id(200000000)
    assert financing_statement
    for party in financing_statement.parties:
        if party.registration_id != 200000000 and not party.registration_id_end:
            if party.party_type_cd == 'DB' or party.party_type_cd == 'DI':
                json_data['deleteDebtors'][0]['partyId'] = party.party_id
            elif party.party_type_cd == 'SP':
                json_data['deleteSecuredParties'][0][
                    'partyId'] = party.party_id

    for gc in financing_statement.general_collateral:
        if gc.registration_id != 200000000 and not gc.registration_id_end:
            json_data['deleteGeneralCollateral'][0][
                'collateralId'] = gc.collateral_id

    for vc in financing_statement.vehicle_collateral:
        if vc.registration_id != 200000000 and not vc.registration_id_end:
            json_data['deleteVehicleCollateral'][0][
                'vehicleId'] = vc.vehicle_id

    # Now create a draft amendment
    draft_json = copy.deepcopy(DRAFT_AMENDMENT_STATEMENT)
    draft = Draft.create_from_json(draft_json, 'PS12345')
    draft.save()
    assert draft.document_number
    json_data['documentId'] = draft.document_number
    registration = Registration.create_from_json(json_data, 'AMENDMENT',
                                                 financing_statement,
                                                 'TEST0001', 'PS12345')
    registration.save()
    assert registration.draft
    result = registration.json
    assert result
Exemplo n.º 17
0
def test_save(session, reg_type, account_id, create_draft):
    """Assert that saveing a valid financing statement works as expected."""
    json_data = copy.deepcopy(FINANCING_STATEMENT)
    json_data['type'] = reg_type
    del json_data['createDateTime']
    del json_data['baseRegistrationNumber']
    del json_data['payment']
    del json_data['lifeInfinite']
    del json_data['expiryDate']
    del json_data['documentId']
    if reg_type != 'RL':
        del json_data['lienAmount']
        del json_data['surrenderDate']
    if reg_type != 'SA':
        del json_data['trustIndenture']
        del json_data['generalCollateral']

    if create_draft:
        draft_json = copy.deepcopy(DRAFT_FINANCING_STATEMENT)
        draft = Draft.create_from_json(draft_json, account_id)
        draft.save()
        assert draft.document_number
        json_data['documentId'] = draft.document_number

    statement = FinancingStatement.create_from_json(json_data, account_id)
    statement.save()
    assert statement.financing_id

    result = statement.json
    assert result
    assert result['baseRegistrationNumber']
    assert result['registrationDescription']
    assert result['registrationAct']
    assert result['createDateTime']
    assert result['registeringParty']
    assert result['debtors'][0]
    assert result['securedParties'][0]
    assert result['vehicleCollateral'][0]
    if reg_type == 'SA':
        assert result['generalCollateral'][0]
    assert 'documentId' not in result
Exemplo n.º 18
0
    def get():
        """Get the list of draft statements belonging to the header account ID."""
        try:

            # Quick check: must provide an account ID.
            account_id = get_account_id(request)
            if account_id is None:
                return account_required_response()

            # Verify request JWT and account ID
            if not authorized(account_id, jwt):
                return unauthorized_error_response(account_id)

            # Try to fetch draft list for account ID
            draft_list = Draft.find_all_by_account_id(account_id)

            return jsonify(draft_list), HTTPStatus.OK

        except BusinessException as exception:
            return business_exception_response(exception)
        except Exception as default_exception:  # noqa: B902; return nicer default error
            return default_exception_response(default_exception)
Exemplo n.º 19
0
    def get(document_id):
        """Get a draft statement by document ID."""
        try:
            if document_id is None:
                return path_param_error_response('document ID')

            # Quick check: must be staff or provide an account ID.
            account_id = get_account_id(request)
            if not is_staff(jwt) and account_id is None:
                return account_required_response()

            # Verify request JWT and account ID
            if not authorized(account_id, jwt):
                return unauthorized_error_response(account_id)

            # Try to fetch draft statement by document ID
            draft = Draft.find_by_document_number(document_id, False)

            return draft.json, HTTPStatus.OK

        except BusinessException as exception:
            return business_exception_response(exception)
        except Exception as default_exception:  # noqa: B902; return nicer default error
            return default_exception_response(default_exception)
Exemplo n.º 20
0
def test_find_by_account_id_no_result(session):
    """Assert that the find draft statement by invalid account ID returns the expected result."""
    drafts = Draft.find_all_by_account_id('X12345X')

    # check
    assert len(drafts) == 0