def test_payment_card_find_success(self): """Verifies find returns the correct payment card.""" payment_card = FundingSources.get_user_payment_card() found = self.client.funding_sources.payment_card.find( payment_card.token) expected = FundingSources.get_funding_source_verify(payment_card) verify_payment_card_response_model(self, found, expected)
def test_make_default_ach_user(self): """Makes a user ach account the default.""" user = self.client.users.create({}) FundingSources.get_user_ach_funding_source(user) source = FundingSources.get_user_ach_funding_source(user) default = self.client.funding_sources(source.token).make_default() verify_payment_card_response_model(self, default, {'is_default_account': True})
def test_payment_card_save_business(self): """Updates a payment card for a business.""" payment_card = FundingSources.get_business_payment_card() updated = self.client.funding_sources.payment_card.save( payment_card.token, self.token_update_request) verify = FundingSources.get_funding_source_verify(payment_card) verify["exp_date"] = self.token_update_request["exp_date"] verify_payment_card_response_model(self, updated, verify)
def test_make_default_ach_business(self): """Makes a business ach account the default.""" business = self.client.businesses.create({}) FundingSources.get_business_ach_funding_source(business) source = FundingSources.get_business_ach_funding_source(business) default = self.client.funding_sources(source.token).make_default() verify_payment_card_response_model(self, default, {'is_default_account': True})
def test_make_default_payment_card_user(self): """Makes a user payment card the default.""" user = self.client.users.create({}) FundingSources.get_user_payment_card(user) payment_card_two = FundingSources.get_user_payment_card(user) updated = self.client.funding_sources( payment_card_two.token).make_default() verify_payment_card_response_model(self, updated, {'is_default_account': True})
def test_program_gateway_find_success(self): """Finds the program gateway it is searching for.""" funding_request = FundingSources.get_program_gateway_funding_request() source = self.client.funding_sources.program_gateway.create( funding_request) found = self.client.funding_sources.program_gateway.find(source.token) verify = FundingSources.get_funding_source_verify(source) verify_gateway_program_funding_source_response(self, found, verify)
def test_funding_sources_list_for_user_one(self): """Tests when one funding source is returned.""" ach = FundingSources.get_user_ach_funding_source(self.user) results = self.client.funding_sources.list_for_user(self.user.token) self.assertEqual(len(results), 1, 'Unexpected number of funding sources returned') verify = FundingSources.get_funding_source_verify(ach) verify_funding_account_response_model(self, results[0], verify)
def test_make_default_payment_card_business(self): """Makes a business payment card the default.""" business = self.client.businesses.create({}) FundingSources.get_business_payment_card(business) payment_card_two = FundingSources.get_business_payment_card(business) updated = self.client.funding_sources( payment_card_two.token).make_default() verify_payment_card_response_model(self, updated, {'is_default_account': True})
def test_program_find(self): """Tests searching for a program.""" program_funding_source_request = FundingSources.get_program_source_funding_request( ) program = self.client.funding_sources.program.create( program_funding_source_request) found = self.client.funding_sources.program.find(program.token) verify = FundingSources.get_funding_source_verify(program) verify_program_funding_source_response(self, found, verify)
def test_program_save_empty(self): """Updates a program with an empty record.""" program_funding_source_request = FundingSources.get_program_source_funding_request( ) program_funding_source_request["active"] = True program = self.client.funding_sources.program.create( program_funding_source_request) updated = self.client.funding_sources.program.save(program.token, {}) verify = FundingSources.get_funding_source_verify(program) verify_program_funding_source_response(self, updated, verify)
def test_payment_card_create_business(self): """Creates a payment card for a user.""" business = self.client.businesses.create({}) payment_card_request = FundingSources.get_payment_card_request() payment_card_request["business_token"] = business.token payment_card = self.client.funding_sources.payment_card.create( payment_card_request) expected = FundingSources.get_payment_card_verify_values( payment_card_request) verify_payment_card_response_model(self, payment_card, expected)
def test_funding_sources_list_for_business_one(self): """Tests when one funding source is returned.""" business = self.client.businesses.create({}) ach_source = FundingSources.get_business_ach_funding_source(business) results = self.client.funding_sources.list_for_business(business.token) self.assertEqual(len(results), 1, 'Unexpected number of funding sources returned') verify = FundingSources.get_funding_source_verify(ach_source) verify_funding_account_response_model(self, results[0], verify)
def test_addresses_list_for_business_one(self): """Tests when one funding source address should be returned.""" business = self.client.businesses.create({}) address = FundingSources.get_business_card_holder_address(business) FundingSources.get_business_payment_card(business) addresses = self.client.funding_sources.addresses.list_for_business( business.token) self.assertEqual(len(addresses), 1, 'Incorrect number of addresses returned') verify_card_holder_address_response( self, addresses[0], address.__dict__)
def test_payment_card_save_error_request(self): """Tests error handling when a bad update request is passed.""" payment_card = FundingSources.get_user_payment_card() with self.assertRaises(MarqetaError): self.client.funding_sources.payment_card.save( payment_card.token, {})
def test_ach_find_success_business(self): """Tests successful find of a business ach funding source.""" funding_source = FundingSources.get_business_ach_funding_source() found = self.client.funding_sources.ach.find(funding_source.token) verify_ach_response_model(self, found, funding_source.__dict__)
def test_funding_sources_addresses_find_business(self): """Finds a business address.""" address = FundingSources.get_business_card_holder_address() found = self.client.funding_sources.addresses.find(address.token) verify_card_holder_address_response( self, found, self.get_address_expected(address))
def test_program_create(self): """Creates a program funding source.""" program_funding_source_request = FundingSources.get_program_source_funding_request() program = self.client.funding_sources.program.create( program_funding_source_request) verify_program_funding_source_response( self, program, program_funding_source_request)
def test_addresses_save_business(self): """Updates the funding source address for a business.""" address = FundingSources.get_business_card_holder_address() updated = self.client.funding_sources.addresses.save( address.token, self.get_address_update()) verify_card_holder_address_response(self, updated, self.get_address_update())
def test_program_gateway_create_success(self): """Creates a program gateway funding source.""" funding_request = FundingSources.get_program_gateway_funding_request() source = self.client.funding_sources.program_gateway.create( funding_request) verify_gateway_program_funding_source_response(self, source, funding_request)
def test_program_gateway_save_empty_request(self): """Checks behavior when the update request is empty.""" request = FundingSources.get_program_gateway_funding_request() source = self.client.funding_sources.program_gateway.create(request) updated = self.client.funding_sources.program_gateway.save( source.token, {}) verify_gateway_program_funding_source_response(self, updated, request)
def test_funding_sources_list_for_user_two(self): """Tests when two funding sources are returned.""" ach_one = FundingSources.get_user_ach_funding_source(self.user) ach_two = FundingSources.get_user_ach_funding_source(self.user) results = self.client.funding_sources.list_for_user(self.user.token) self.assertEqual(len(results), 2, 'Unexpected number of funding sources returned') verify_one = FundingSources.get_funding_source_verify(ach_one) verify_two = FundingSources.get_funding_source_verify(ach_two) if results[0].token == ach_one.token: verify_funding_account_response_model(self, results[0], verify_one) verify_funding_account_response_model(self, results[1], verify_two) else: verify_funding_account_response_model(self, results[1], verify_one) verify_funding_account_response_model(self, results[0], verify_two)
def test_funding_sources_list_for_business_filter_type(self): """Filters list by type.""" business = self.client.businesses.create({}) FundingSources.get_business_ach_funding_source(business) card = FundingSources.get_business_payment_card(business) results = self.client.funding_sources.list_for_business( business.token, params={"type": "paymentcard"}) self.assertEqual(len(results), 1, 'Unexpected number of funding sources returned') self.assertEqual( results[0].type, 'paymentcard', 'Filter did not return funding source with the correct type') verify = FundingSources.get_funding_source_verify(card) verify_funding_account_response_model(self, results[0], verify)
def test_program_gateway_save_success(self): """Successfully updates a program gateway.""" request = FundingSources.get_program_gateway_funding_request() source = self.client.funding_sources.program_gateway.create(request) request['url'] = 'https://qe_updated.marqeta.com' updated = self.client.funding_sources.program_gateway.save( source.token, request) verify_gateway_program_funding_source_response(self, updated, request)
def test_ach_verification_amounts_user(self): """Retrieves the verification amounts for a user funding source.""" funding_source = FundingSources.get_user_ach_funding_source() amounts = self.client.funding_sources.ach( funding_source.token).verification_amounts() with self.subTest( 'First verification amount not within expected range'): self.assertTrue(0 < amounts.verify_amount1 < 1) with self.subTest( 'Second verification amount not within expected range'): self.assertTrue(0 < amounts.verify_amount2 < 1)
def test_program_save_active(self): """Deactivates a program.""" program_funding_source_request = FundingSources.get_program_source_funding_request( ) program = self.client.funding_sources.program.create( program_funding_source_request) change_request = {"active": False} updated = self.client.funding_sources.program.save( program.token, change_request) verify_program_funding_source_response(self, updated, change_request)
def test_ach_save_fail(self): """Tries to verify the ach account with incorrect verification amounts.""" funding_source = FundingSources.get_user_ach_funding_source() amounts = self.client.funding_sources.ach( funding_source.token).verification_amounts() ach_verification = { "verify_amount1": amounts.verify_amount1 + 0.01, "verify_amount2": amounts.verify_amount2 + 0.01 } with self.assertRaises(MarqetaError): self.client.funding_sources.ach.save(funding_source.token, ach_verification)
def test_program_save_name(self): """Changes the name of a program.""" program_funding_source_request = FundingSources.get_program_source_funding_request( ) program = self.client.funding_sources.program.create( program_funding_source_request) change_request = { "name": 'changed_' + program_funding_source_request['name'] } updated = self.client.funding_sources.program.save( program.token, change_request) verify_program_funding_source_response(self, updated, change_request)
def test_program_save_both(self): """Changes the name of a program and deactivates it.""" program_funding_source_request = FundingSources.get_program_source_funding_request( ) program = self.client.funding_sources.program.create( program_funding_source_request) change_request = { "name": 'deactivated_' + program_funding_source_request['name'], "active": False } updated = self.client.funding_sources.program.save( program.token, change_request) verify_program_funding_source_response(self, updated, change_request)
def test_addresses_list_for_business_two(self): """Tests when two funding source addresses should be returned.""" business = self.client.businesses.create({}) address_one = FundingSources.get_card_holder_address_model() address_one["business_token"] = business.token address_two = { "business_token": business.token, "first_name": "O", "last_name": "PD", "address_1": "455 7th St.", "city": "Oakland", "state": "CA", "zip": "94612", "country": "USA" } self.client.funding_sources.addresses.create(address_one) self.client.funding_sources.addresses.create(address_two) addresses = self.client.funding_sources.addresses.list_for_business( business.token) self.assertEqual(len(addresses), 2, 'Incorrect number of addresses returned') if addresses[0].first_name == address_one['first_name']: verify_card_holder_address_response( self, addresses[0], address_one) verify_card_holder_address_response( self, addresses[1], address_two) else: verify_card_holder_address_response( self, addresses[1], address_one) verify_card_holder_address_response( self, addresses[0], address_two)
def test_ach_save_success(self): """Verifies the ach account with the correct verification amounts.""" funding_source = FundingSources.get_user_ach_funding_source() amounts = self.client.funding_sources.ach( funding_source.token).verification_amounts() ach_verification = { "verify_amount1": amounts.verify_amount1, "verify_amount2": amounts.verify_amount2 } result = self.client.funding_sources.ach.save(funding_source.token, ach_verification) verify = self.get_funding_source_verify(funding_source) verify['verification_status'] = 'ACH_VERIFIED' verify['active'] = True verify_ach_response_model(self, result, verify)