def test_donation_data(self, sfdc_mock, gud_mock): data = self.donate_data.copy() gud_mock.return_value = { 'id': '1234', 'first_name': 'Jeffery', 'last_name': 'Lebowski', } process_donation(data) sfdc_mock.opportunity.create.assert_called_with({ 'RecordTypeId': ANY, 'Name': 'Foundation Donation', 'Donation_Contact__c': '1234', 'StageName': 'Closed Won', # calculated from data['created'] 'CloseDate': '2016-11-21T16:46:49.327000', 'Amount': float(data['donation_amount']), 'Currency__c': 'USD', 'Payment_Source__c': 'paypal', 'PMT_Transaction_ID__c': data['transaction_id'], 'Payment_Type__c': 'Recurring', 'SourceURL__c': data['source_url'], 'Project__c': data['project'], })
def test_donation_data(self, sfdc_mock, gud_mock): data = self.donate_data.copy() gud_mock.return_value = { 'id': '1234', 'first_name': 'Jeffery', 'last_name': 'Lebowski', } process_donation(data) sfdc_mock.opportunity.create.assert_called_with({ 'RecordTypeId': ANY, 'Name': 'Foundation Donation', 'Donation_Contact__c': '1234', 'StageName': 'Closed Won', # calculated from data['created'] 'CloseDate': '2016-11-21T16:46:49.327000', 'Amount': float(data['donation_amount']), 'Currency__c': 'USD', 'Payment_Source__c': 'paypal', 'PMT_Transaction_ID__c': data['transaction_id'], 'Payment_Type__c': 'Recurring', 'SourceURL__c': data['source_url'], 'Project__c': data['project'], 'Donation_Locale__c': data['locale'], 'Processors_Fee__c': data['transaction_fee'], 'Net_Amount__c': data['net_amount'], 'Conversion_Amount__c': data['conversion_amount'], 'Last_4_Digits__c': data['last_4'], })
def test_one_name(self, sfdc_mock, gud_mock): data = self.donate_data.copy() gud_mock.return_value = { 'id': '1234', 'first_name': '', 'last_name': '_', } del data['first_name'] data['last_name'] = 'Donnie' process_donation(data) sfdc_mock.update.assert_called_with(gud_mock(), { '_set_subscriber': False, 'last_name': 'Donnie', })
def test_one_name(self, sfdc_mock, gud_mock): data = self.donate_data.copy() gud_mock.return_value = { 'id': '1234', 'first_name': '', 'last_name': '_', } del data['first_name'] data['last_name'] = 'Donnie' process_donation(data) sfdc_mock.update.assert_called_with(gud_mock(), { '_set_subscriber': False, 'last_name': 'Donnie', })
def test_donation_silent_failure_on_dupe(self, sfdc_mock, gud_mock): data = self.donate_data.copy() gud_mock.return_value = { 'id': '1234', 'first_name': 'Jeffery', 'last_name': 'Lebowski', } error_content = [{ u'errorCode': u'DUPLICATE_VALUE', u'fields': [], u'message': u'duplicate value found: PMT_Transaction_ID__c ' u'duplicates value on record with id: blah-blah', }] exc = sfapi.SalesforceMalformedRequest('url', 400, 'opportunity', error_content) sfdc_mock.opportunity.create.side_effect = exc process_donation(data)
def test_name_splitting(self, sfdc_mock, gud_mock): data = self.donate_data.copy() gud_mock.return_value = None del data['first_name'] data['last_name'] = 'Theodore Donald Kerabatsos' with self.assertRaises(RetryTask): # raises retry b/c the 2nd call to get_user_data returns None process_donation(data) sfdc_mock.add.assert_called_with({ '_set_subscriber': False, 'token': ANY, 'record_type': ANY, 'email': '*****@*****.**', 'first_name': 'Theodore Donald', 'last_name': 'Kerabatsos', })
def test_name_splitting(self, sfdc_mock, gud_mock): data = self.donate_data.copy() gud_mock.return_value = None del data['first_name'] data['last_name'] = 'Theodore Donald Kerabatsos' with self.assertRaises(RetryTask): # raises retry b/c the 2nd call to get_user_data returns None process_donation(data) sfdc_mock.add.assert_called_with({ '_set_subscriber': False, 'token': ANY, 'record_type': ANY, 'email': '*****@*****.**', 'first_name': 'Theodore Donald', 'last_name': 'Kerabatsos', })
def test_donation_normal_failure_not_dupe(self, sfdc_mock, gud_mock): data = self.donate_data.copy() gud_mock.return_value = { 'id': '1234', 'first_name': 'Jeffery', 'last_name': 'Lebowski', } error_content = [{ u'errorCode': u'OTHER_ERROR', u'fields': [], u'message': u'Some other non-dupe problem', }] exc = sfapi.SalesforceMalformedRequest('url', 400, 'opportunity', error_content) sfdc_mock.opportunity.create.side_effect = exc with self.assertRaises(sfapi.SalesforceMalformedRequest): process_donation(data)
def test_donation_normal_failure_not_dupe(self, sfdc_mock, gud_mock): data = self.donate_data.copy() gud_mock.return_value = { 'id': '1234', 'first_name': 'Jeffery', 'last_name': 'Lebowski', } error_content = [{ u'errorCode': u'OTHER_ERROR', u'fields': [], u'message': u'Some other non-dupe problem', }] exc = sfapi.SalesforceMalformedRequest('url', 400, 'opportunity', error_content) sfdc_mock.opportunity.create.side_effect = exc with self.assertRaises(sfapi.SalesforceMalformedRequest): process_donation(data)
def test_name_empty(self, sfdc_mock, gud_mock): """Should be okay if only last_name is provided and is just spaces. https://github.com/mozmeao/basket/issues/45 """ data = self.donate_data.copy() gud_mock.return_value = None del data['first_name'] data['last_name'] = ' ' with self.assertRaises(RetryTask): # raises retry b/c the 2nd call to get_user_data returns None process_donation(data) sfdc_mock.add.assert_called_with({ '_set_subscriber': False, 'token': ANY, 'record_type': ANY, 'email': '*****@*****.**', })
def test_name_empty(self, sfdc_mock, gud_mock): """Should be okay if only last_name is provided and is just spaces. https://github.com/mozmeao/basket/issues/45 """ data = self.donate_data.copy() gud_mock.return_value = None del data['first_name'] data['last_name'] = ' ' with self.assertRaises(RetryTask): # raises retry b/c the 2nd call to get_user_data returns None process_donation(data) sfdc_mock.add.assert_called_with({ '_set_subscriber': False, 'token': ANY, 'record_type': ANY, 'email': '*****@*****.**', })
def test_name_none(self, sfdc_mock, gud_mock): """Should be okay if only last_name is provided and is None. https://sentry.prod.mozaws.net/operations/basket-prod/issues/683973/ """ data = self.donate_data.copy() gud_mock.return_value = None del data['first_name'] data['last_name'] = None with self.assertRaises(RetryTask): # raises retry b/c the 2nd call to get_user_data returns None process_donation(data) sfdc_mock.add.assert_called_with({ '_set_subscriber': False, 'token': ANY, 'record_type': ANY, 'email': '*****@*****.**', })
def test_name_none(self, sfdc_mock, gud_mock): """Should be okay if only last_name is provided and is None. https://sentry.prod.mozaws.net/operations/basket-prod/issues/683973/ """ data = self.donate_data.copy() gud_mock.return_value = None del data['first_name'] data['last_name'] = None with self.assertRaises(RetryTask): # raises retry b/c the 2nd call to get_user_data returns None process_donation(data) sfdc_mock.add.assert_called_with({ '_set_subscriber': False, 'token': ANY, 'record_type': ANY, 'email': '*****@*****.**', })
def test_donation_silent_failure_on_dupe(self, sfdc_mock, gud_mock): data = self.donate_data.copy() gud_mock.return_value = { 'id': '1234', 'first_name': 'Jeffery', 'last_name': 'Lebowski', } error_content = [{ u'errorCode': u'DUPLICATE_VALUE', u'fields': [], u'message': u'duplicate value found: PMT_Transaction_ID__c ' u'duplicates value on record with id: blah-blah', }] exc = sfapi.SalesforceMalformedRequest('url', 400, 'opportunity', error_content) sfdc_mock.opportunity.create.side_effect = exc process_donation(data)
def test_donation_data(self, sfdc_mock, gud_mock): data = deepcopy(self.donate_data) gud_mock.return_value = { 'id': '1234', 'first_name': 'Jeffery', 'last_name': 'Lebowski', } process_donation(data) sfdc_mock.opportunity.create.assert_called_with({ 'RecordTypeId': ANY, 'Name': 'Foundation Donation', 'Donation_Contact__c': '1234', 'StageName': 'Closed Won', 'CloseDate': data['timestamp'], 'Amount': float(data['data']['donation_amount']), 'Currency__c': 'USD', 'Payment_Source__c': 'paypal', 'PMT_Transaction_ID__c': data['data']['transaction_id'], 'Payment_Type__c': 'Recurring', 'SourceURL__c': data['data']['source_url'], 'Project__c': data['data']['project'], })
def test_only_update_contact_if_modified(self, sfdc_mock, gud_mock): data = self.donate_data.copy() gud_mock.return_value = { 'id': '1234', 'first_name': '', 'last_name': '_', } process_donation(data) sfdc_mock.update.assert_called_with(gud_mock(), { '_set_subscriber': False, 'first_name': 'Jeffery', 'last_name': 'Lebowski', }) sfdc_mock.reset_mock() data = self.donate_data.copy() gud_mock.return_value = { 'id': '1234', 'first_name': 'Jeffery', 'last_name': 'Lebowski', } process_donation(data) sfdc_mock.update.assert_not_called()
def test_only_update_contact_if_modified(self, sfdc_mock, gud_mock): data = self.donate_data.copy() gud_mock.return_value = { 'id': '1234', 'first_name': '', 'last_name': '_', } process_donation(data) sfdc_mock.update.assert_called_with( gud_mock(), { '_set_subscriber': False, 'first_name': 'Jeffery', 'last_name': 'Lebowski', }) sfdc_mock.reset_mock() data = self.donate_data.copy() gud_mock.return_value = { 'id': '1234', 'first_name': 'Jeffery', 'last_name': 'Lebowski', } process_donation(data) sfdc_mock.update.assert_not_called()