def test_create_with_valid_contact_info_returning_object(self): shopper = Shopper() shopper_id = shopper.create( contact_info=self.contact_info) shopper_obj = shopper.find_by_shopper_id(shopper_id) self.assertIsInstance(shopper_obj, dict) shopper_info = shopper_obj['shopper-info'] shopper_contact_info = shopper_info['shopper-contact-info'] self.assertEqual(shopper_contact_info['first-name'], self.contact_info.first_name) self.assertEqual(shopper_contact_info['last-name'], self.contact_info.last_name) self.assertEqual(shopper_info['store-id'], shopper.client.default_store_id) self.assertIsNone(shopper_info['payment-info']['credit-cards-info'])
def test_create_with_valid_contact_info_and_encrypted_credit_card(self): shopper = Shopper() shopper_id = shopper.create( contact_info=self.contact_info, credit_card=self.encrypted_credit_card) shopper_obj = shopper.find_by_shopper_id(shopper_id) self.assertIsInstance(shopper_obj, dict) shopper_info = shopper_obj['shopper-info'] shopper_contact_info = shopper_info['shopper-contact-info'] self.assertEqual(shopper_contact_info['first-name'], self.contact_info.first_name) self.assertEqual(shopper_contact_info['last-name'], self.contact_info.last_name) self.assertEqual(shopper_info['store-id'], shopper.client.default_store_id)
def test_find_by_shopper_id(self): shopper = Shopper() shopper_id = shopper.create( contact_info=self.contact_info) self.assertIsNotNone(shopper_id) # find_by_shopper_id shopper_obj = shopper.find_by_shopper_id(shopper_id) self.assertIsInstance(shopper_obj, dict) shopper_contact_info = shopper_obj['shopper-info']['shopper-contact-info'] self.assertEqual(shopper_contact_info['first-name'], self.contact_info.first_name) self.assertEqual(shopper_contact_info['last-name'], self.contact_info.last_name) self.assertEqual(shopper_obj['shopper-info']['store-id'], shopper.client.default_store_id)
def test_find_by_seller_shopper_id(self): seller_id = 'seller_id' seller_shopper_id = 'seller_shopper_id' # Set up shopper = Shopper() shopper.client.seller_id = seller_id shopper.find_by_shopper_id = MagicMock() # find_by_seller_shopper_id shopper.find_by_seller_shopper_id(seller_shopper_id) shopper.find_by_shopper_id.assert_called_once_with( '{seller_shopper_id},{seller_id}'.format( seller_shopper_id=seller_shopper_id, seller_id=seller_id))
def test_create_with_valid_contact_info_returning_object(self): shopper = Shopper() shopper_id = shopper.create(contact_info=self.contact_info) shopper_obj = shopper.find_by_shopper_id(shopper_id) self.assertIsInstance(shopper_obj, dict) shopper_info = shopper_obj['shopper-info'] shopper_contact_info = shopper_info['shopper-contact-info'] self.assertEqual(shopper_contact_info['first-name'], self.contact_info.first_name) self.assertEqual(shopper_contact_info['last-name'], self.contact_info.last_name) self.assertEqual(shopper_info['store-id'], shopper.client.default_store_id) self.assertIsNone(shopper_info['payment-info']['credit-cards-info'])
def test_create_with_valid_contact_info_and_encrypted_credit_card(self): shopper = Shopper() shopper_id = shopper.create(contact_info=self.contact_info, credit_card=self.encrypted_credit_card) shopper_obj = shopper.find_by_shopper_id(shopper_id) self.assertIsInstance(shopper_obj, dict) shopper_info = shopper_obj['shopper-info'] shopper_contact_info = shopper_info['shopper-contact-info'] self.assertEqual(shopper_contact_info['first-name'], self.contact_info.first_name) self.assertEqual(shopper_contact_info['last-name'], self.contact_info.last_name) self.assertEqual(shopper_info['store-id'], shopper.client.default_store_id)
def test_find_by_shopper_id(self): shopper = Shopper() shopper_id = shopper.create(contact_info=self.contact_info) self.assertIsNotNone(shopper_id) # find_by_shopper_id shopper_obj = shopper.find_by_shopper_id(shopper_id) self.assertIsInstance(shopper_obj, dict) shopper_contact_info = shopper_obj['shopper-info'][ 'shopper-contact-info'] self.assertEqual(shopper_contact_info['first-name'], self.contact_info.first_name) self.assertEqual(shopper_contact_info['last-name'], self.contact_info.last_name) self.assertEqual(shopper_obj['shopper-info']['store-id'], shopper.client.default_store_id)
def test_add_invalid_encrypted_credit_card(self): # Create a shopper, ensuring no credit card info was added shopper = Shopper() shopper_id = shopper.create( contact_info=self.contact_info) shopper_obj = shopper.find_by_shopper_id(shopper_id) self.assertIsNone(shopper_obj['shopper-info']['payment-info']['credit-cards-info']) # Add expired card with self.assertRaises(exceptions.CardError) as e: shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=EncryptedCreditCard( card_type=helper.DUMMY_CARD_VISA__EXPIRED['card_type'], expiration_month=helper.DUMMY_CARD_VISA__EXPIRED['expiration_month'], expiration_year=helper.DUMMY_CARD_VISA__EXPIRED['expiration_year'], encrypted_card_number='encrypted_%s' % helper.DUMMY_CARD_VISA__EXPIRED['card_number'], encrypted_security_code=helper.DUMMY_CARD_VISA__EXPIRED['encrypted_security_code'])) self.assertEqual(e.exception.code, '430306-14002') self.assertEqual(e.exception.description, 'The expiration date entered is invalid. Enter valid expiration date or try another card') self.assertEqual(e.exception.verbose_description, 'Order creation could not be completed because of payment processing failure: 430306 ' '- The expiration date entered is invalid. Enter valid expiration date or try another card') # Add card with insufficient funds with self.assertRaises(exceptions.CardError) as e: shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=EncryptedCreditCard( card_type=helper.DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['card_type'], expiration_month=helper.DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['expiration_month'], expiration_year=helper.DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['expiration_year'], encrypted_card_number='encrypted_%s' % helper.DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['card_number'], encrypted_security_code=helper.DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['encrypted_security_code'])) self.assertEqual(e.exception.code, '430360-14002') self.assertEqual(e.exception.description, 'Insufficient funds. Please use another card or contact your bank for assistance') self.assertEqual(e.exception.verbose_description, 'Order creation could not be completed because of payment processing failure: 430360 ' '- Insufficient funds. Please use another card or contact your bank for assistance') # Add card with invalid number with self.assertRaises(exceptions.CardError) as e: shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=EncryptedCreditCard( card_type=helper.DUMMY_CARD_VISA__INVALID_CARD_NUMBER['card_type'], expiration_month=helper.DUMMY_CARD_VISA__INVALID_CARD_NUMBER['expiration_month'], expiration_year=helper.DUMMY_CARD_VISA__INVALID_CARD_NUMBER['expiration_year'], encrypted_card_number='encrypted_%s' % helper.DUMMY_CARD_VISA__INVALID_CARD_NUMBER['card_number'], encrypted_security_code=helper.DUMMY_CARD_VISA__INVALID_CARD_NUMBER['encrypted_security_code'])) self.assertEqual(e.exception.code, '430330-14002') self.assertEqual(e.exception.description, 'Invalid card number. Please check the number and try again, or use a different card') self.assertEqual(e.exception.verbose_description, 'Order creation could not be completed because of payment processing failure: 430330 ' '- Invalid card number. Please check the number and try again, or use a different card') # Add card with invalid number with self.assertRaises(exceptions.CardError) as e: shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=EncryptedCreditCard( card_type=helper.DUMMY_CARD_AMEX__AUTH_FAIL['card_type'], expiration_month=helper.DUMMY_CARD_AMEX__AUTH_FAIL['expiration_month'], expiration_year=helper.DUMMY_CARD_AMEX__AUTH_FAIL['expiration_year'], encrypted_card_number='encrypted_%s' % helper.DUMMY_CARD_AMEX__AUTH_FAIL['card_number'], encrypted_security_code=helper.DUMMY_CARD_AMEX__AUTH_FAIL['encrypted_security_code'])) self.assertEqual(e.exception.code, '430285-14002') self.assertEqual(e.exception.description, 'Authorization has failed for this transaction. ' 'Please try again or contact your bank for assistance')
def test_add_encrypted_credit_card(self): # Create a shopper, ensuring no credit card info was added shopper = Shopper() shopper_id = shopper.create( contact_info=self.contact_info) shopper_obj = shopper.find_by_shopper_id(shopper_id) self.assertIsNone(shopper_obj['shopper-info']['payment-info']['credit-cards-info']) # Add first credit card update_successful = shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=self.encrypted_credit_card) self.assertTrue(update_successful) shopper_obj = shopper.find_by_shopper_id(shopper_id) credit_card_info = shopper_obj['shopper-info']['payment-info']['credit-cards-info']['credit-card-info'] self.assertIsInstance(credit_card_info['credit-card'], dict) # Since credit_card and encrypted_credit_card are the same I can get the last 4 digits from the non encrypted self.assertEqual(credit_card_info['credit-card']['card-last-four-digits'], self.credit_card.card_number[-4:]) self.assertEqual(credit_card_info['credit-card']['card-type'], self.encrypted_credit_card.card_type) # Add second credit card update_successful = shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=self.encrypted_second_credit_card) self.assertTrue(update_successful) shopper_obj = shopper.find_by_shopper_id(shopper_id) credit_cards_info = shopper_obj['shopper-info']['payment-info']['credit-cards-info']['credit-card-info'] self.assertIsInstance(credit_cards_info, list) self.assertEqual(len(credit_cards_info), 2) # The order of the credit cards is not known, so we sort the items before comparing. cards = map(lambda c: dict(c['credit-card']), credit_cards_info) self.assertItemsEqual( cards, [{'card-last-four-digits': self.credit_card.card_number[-4:], 'card-type': self.encrypted_credit_card.card_type}, {'card-last-four-digits': self.second_credit_card.card_number[-4:], 'card-type': self.encrypted_second_credit_card.card_type}]) # Add third credit card update_successful = shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=self.encrypted_third_credit_card) self.assertTrue(update_successful) shopper_obj = shopper.find_by_shopper_id(shopper_id) credit_cards_info = shopper_obj['shopper-info']['payment-info']['credit-cards-info']['credit-card-info'] self.assertIsInstance(credit_cards_info, list) self.assertEqual(len(credit_cards_info), 3) # Last added credit card displays first cards = map(lambda c: dict(c['credit-card']), credit_cards_info) self.assertItemsEqual( cards, [{'card-last-four-digits': self.credit_card.card_number[-4:], 'card-type': self.encrypted_credit_card.card_type}, {'card-last-four-digits': self.second_credit_card.card_number[-4:], 'card-type': self.encrypted_second_credit_card.card_type}, {'card-last-four-digits': self.third_credit_card.card_number[-4:], 'card-type': self.encrypted_third_credit_card.card_type}])
def test_add_invalid_encrypted_credit_card(self): # Create a shopper, ensuring no credit card info was added shopper = Shopper() shopper_id = shopper.create(contact_info=self.contact_info) shopper_obj = shopper.find_by_shopper_id(shopper_id) self.assertIsNone( shopper_obj['shopper-info']['payment-info']['credit-cards-info']) # Add expired card with self.assertRaises(exceptions.CardError) as e: shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=EncryptedCreditCard( card_type=helper.DUMMY_CARD_VISA__EXPIRED['card_type'], expiration_month=helper. DUMMY_CARD_VISA__EXPIRED['expiration_month'], expiration_year=helper. DUMMY_CARD_VISA__EXPIRED['expiration_year'], encrypted_card_number='encrypted_%s' % helper.DUMMY_CARD_VISA__EXPIRED['card_number'], encrypted_security_code=helper. DUMMY_CARD_VISA__EXPIRED['encrypted_security_code'])) self.assertEqual(e.exception.code, '430306-14002') self.assertEqual( e.exception.description, 'The expiration date entered is invalid. Enter valid expiration date or try another card' ) self.assertEqual( e.exception.verbose_description, 'Order creation could not be completed because of payment processing failure: 430306 ' '- The expiration date entered is invalid. Enter valid expiration date or try another card' ) # Add card with insufficient funds with self.assertRaises(exceptions.CardError) as e: shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=EncryptedCreditCard( card_type=helper. DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['card_type'], expiration_month=helper. DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['expiration_month'], expiration_year=helper. DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['expiration_year'], encrypted_card_number='encrypted_%s' % helper.DUMMY_CARD_VISA__INSUFFICIENT_FUNDS['card_number'], encrypted_security_code=helper. DUMMY_CARD_VISA__INSUFFICIENT_FUNDS[ 'encrypted_security_code'])) self.assertEqual(e.exception.code, '430360-14002') self.assertEqual( e.exception.description, 'Insufficient funds. Please use another card or contact your bank for assistance' ) self.assertEqual( e.exception.verbose_description, 'Order creation could not be completed because of payment processing failure: 430360 ' '- Insufficient funds. Please use another card or contact your bank for assistance' ) # Add card with invalid number with self.assertRaises(exceptions.CardError) as e: shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=EncryptedCreditCard( card_type=helper. DUMMY_CARD_VISA__INVALID_CARD_NUMBER['card_type'], expiration_month=helper. DUMMY_CARD_VISA__INVALID_CARD_NUMBER['expiration_month'], expiration_year=helper. DUMMY_CARD_VISA__INVALID_CARD_NUMBER['expiration_year'], encrypted_card_number='encrypted_%s' % helper.DUMMY_CARD_VISA__INVALID_CARD_NUMBER['card_number'], encrypted_security_code=helper. DUMMY_CARD_VISA__INVALID_CARD_NUMBER[ 'encrypted_security_code'])) self.assertEqual(e.exception.code, '430330-14002') self.assertEqual( e.exception.description, 'Invalid card number. Please check the number and try again, or use a different card' ) self.assertEqual( e.exception.verbose_description, 'Order creation could not be completed because of payment processing failure: 430330 ' '- Invalid card number. Please check the number and try again, or use a different card' ) # Add card with invalid number with self.assertRaises(exceptions.CardError) as e: shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=EncryptedCreditCard( card_type=helper.DUMMY_CARD_AMEX__AUTH_FAIL['card_type'], expiration_month=helper. DUMMY_CARD_AMEX__AUTH_FAIL['expiration_month'], expiration_year=helper. DUMMY_CARD_AMEX__AUTH_FAIL['expiration_year'], encrypted_card_number='encrypted_%s' % helper.DUMMY_CARD_AMEX__AUTH_FAIL['card_number'], encrypted_security_code=helper. DUMMY_CARD_AMEX__AUTH_FAIL['encrypted_security_code'])) self.assertEqual(e.exception.code, '430285-14002') self.assertEqual( e.exception.description, 'Authorization has failed for this transaction. ' 'Please try again or contact your bank for assistance')
def test_add_encrypted_credit_card(self): # Create a shopper, ensuring no credit card info was added shopper = Shopper() shopper_id = shopper.create(contact_info=self.contact_info) shopper_obj = shopper.find_by_shopper_id(shopper_id) self.assertIsNone( shopper_obj['shopper-info']['payment-info']['credit-cards-info']) # Add first credit card update_successful = shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=self.encrypted_credit_card) self.assertTrue(update_successful) shopper_obj = shopper.find_by_shopper_id(shopper_id) credit_card_info = shopper_obj['shopper-info']['payment-info'][ 'credit-cards-info']['credit-card-info'] self.assertIsInstance(credit_card_info['credit-card'], dict) # Since credit_card and encrypted_credit_card are the same I can get the last 4 digits from the non encrypted self.assertEqual( credit_card_info['credit-card']['card-last-four-digits'], self.credit_card.card_number[-4:]) self.assertEqual(credit_card_info['credit-card']['card-type'], self.encrypted_credit_card.card_type) # Add second credit card update_successful = shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=self.encrypted_second_credit_card) self.assertTrue(update_successful) shopper_obj = shopper.find_by_shopper_id(shopper_id) credit_cards_info = shopper_obj['shopper-info']['payment-info'][ 'credit-cards-info']['credit-card-info'] self.assertIsInstance(credit_cards_info, list) self.assertEqual(len(credit_cards_info), 2) # The order of the credit cards is not known, so we sort the items before comparing. cards = map(lambda c: dict(c['credit-card']), credit_cards_info) self.assertItemsEqual( cards, [{ 'card-last-four-digits': self.credit_card.card_number[-4:], 'card-type': self.encrypted_credit_card.card_type }, { 'card-last-four-digits': self.second_credit_card.card_number[-4:], 'card-type': self.encrypted_second_credit_card.card_type }]) # Add third credit card update_successful = shopper.update( shopper_id=shopper_id, contact_info=self.contact_info, credit_card=self.encrypted_third_credit_card) self.assertTrue(update_successful) shopper_obj = shopper.find_by_shopper_id(shopper_id) credit_cards_info = shopper_obj['shopper-info']['payment-info'][ 'credit-cards-info']['credit-card-info'] self.assertIsInstance(credit_cards_info, list) self.assertEqual(len(credit_cards_info), 3) # Last added credit card displays first cards = map(lambda c: dict(c['credit-card']), credit_cards_info) self.assertItemsEqual( cards, [{ 'card-last-four-digits': self.credit_card.card_number[-4:], 'card-type': self.encrypted_credit_card.card_type }, { 'card-last-four-digits': self.second_credit_card.card_number[-4:], 'card-type': self.encrypted_second_credit_card.card_type }, { 'card-last-four-digits': self.third_credit_card.card_number[-4:], 'card-type': self.encrypted_third_credit_card.card_type }])