def test_create_from_json(session): """Assert that the party json renders to a party model correctly.""" party_bus_json = { 'businessName': 'business', 'emailAddress': '*****@*****.**', 'address': { 'street': 'street', 'streetAdditional': 'additional', 'city': 'city', 'region': 'BC', 'country': 'CA', 'postalCode': 'V8S2J4' } } party_ind_json = { 'personName': { 'first': 'first', 'last': 'last', 'middle': 'middle' }, 'emailAddress': '*****@*****.**', 'birthDate': '1990-06-15', 'address': { 'street': 'street', 'streetAdditional': 'additional', 'city': 'city', 'region': 'BC', 'country': 'CA', 'postalCode': 'V8S2J4' } } party_bus = Party.create_from_json(party_bus_json, 'SP', 1234) assert party_bus.registration_id assert party_bus.party_type_cd == 'SP' assert party_bus.business_name assert party_bus.address assert party_bus.address.street assert party_bus.address.street_additional assert party_bus.address.city assert party_bus.address.region assert party_bus.address.country assert party_bus.address.postal_code assert not party_bus.last_name party_ind = Party.create_from_json(party_ind_json, 'DB', 1234) assert party_ind.registration_id assert party_ind.party_type_cd == 'DI' assert party_ind.last_name assert party_ind.first_name assert party_ind.middle_name assert party_ind.address assert party_ind.address.street assert party_ind.address.street_additional assert party_ind.address.city assert party_ind.address.region assert party_ind.address.country assert party_ind.address.postal_code assert not party_ind.business_name
def validate_party_codes(json_data): """Verify party codes exist in the database for all parties in json_data.""" error_msg = '' code = None if 'registeringParty' in json_data and 'code' in json_data['registeringParty']: code = json_data['registeringParty']['code'] if not Party.verify_party_code(code): error_msg += REGISTERING_CODE_MSG.format(code) if 'securedParties' in json_data: for party in json_data['securedParties']: if 'code' in party: code = party['code'] if not Party.verify_party_code(code): error_msg += SECURED_CODE_MSG.format(code) if 'addSecuredParties' in json_data: for party in json_data['addSecuredParties']: if 'code' in party: code = party['code'] if not Party.verify_party_code(code): error_msg += SECURED_CODE_MSG.format(code) return error_msg
def test_find_by_registration_id(session): """Assert that find party by registration id contains all expected elements.""" parties = Party.find_by_registration_id(200000000) assert parties assert len(parties) == 5 assert parties[0].party_type_cd == 'RG' assert parties[1].party_type_cd == 'DI' assert parties[2].party_type_cd == 'DB' assert parties[3].party_type_cd == 'SP' assert parties[4].party_type_cd == 'SP'
def test_create_from_financing_json(session): """Assert that the financing statement json renders to a list of party models correctly.""" json_data = copy.deepcopy(FINANCING_STATEMENT) del json_data['securedParties'] secured = [{'code': '200000000'}] json_data['securedParties'] = secured parties = Party.create_from_financing_json(json_data, None) assert parties assert len(parties) == 3 for party in parties: assert party.party_type_cd if not party.branch_id: assert party.address
def test_find_by_id(session): """Assert that find party by party ID contains all expected elements.""" party = Party.find_by_id(200000000) assert party assert party.party_id == 200000000 assert party.address_id assert party.party_type_cd == 'RG' assert party.first_name assert party.middle_name assert party.last_name assert party.registration_id assert not party.branch_id assert not party.business_name assert not party.birth_date assert not party.registration_id_end
def test_find_by_id_client(session): """Assert that find party by party ID for a client party contains all expected elements.""" party = Party.find_by_id(200000004) assert party assert party.party_type_cd == 'SP' assert party.party_id == 200000004 assert party.registration_id assert not party.first_name assert not party.middle_name assert not party.last_name assert not party.birth_date assert not party.registration_id_end json_data = party.json assert json_data['code'] == '200000000' assert json_data['businessName'] assert json_data['address']
def test_party_json(session): """Assert that the party model renders to a json format correctly.""" party = Party(party_id=1000, first_name='FIRST', middle_name='MIDDLE', last_name='LAST', business_name='BUSINESS', registration_id=1000, address_id=1000) party_json = { 'partyId': party.party_id, 'businessName': party.business_name, 'personName': { 'first': party.first_name, 'last': party.last_name, 'middle': party.middle_name } } assert party.json == party_json
def test_find_by_reg_id_invalid(session): """Assert that find party by non-existent registration id eturns the expected result.""" parties = Party.find_by_registration_id(300000000) assert not parties
def test_find_by_financing_id_invalid(session): """Assert that find party by non-existent financing statement ID returns the expected result.""" party = Party.find_by_financing_id(300000000) assert not party
def test_verify_party_code_false(session): """Assert that Party.verify_party_code works correctly with an invalid code.""" result = Party.verify_party_code('300000000') assert not result
def test_verify_party_code_true(session): """Assert that Party.verify_party_code works correctly with a valid code.""" result = Party.verify_party_code('200000000') assert result