def test_command_with_invalid_data(self, mock_user_fetch_data, mock_pricebook_get, mock_lead_get, mock_lead_save, mock_campaign_get_or_create, mock_campaign_member_create): """ Test management command with invalid user data. """ user_data_without_courses = dict(self.user_data) user_data_without_courses.pop('courses') mock_pricebook_get.return_value = Pricebook2(is_standard=True) mock_user_fetch_data.return_value = [user_data_without_courses] mock_lead_get.return_value = self._get_lead_object() mock_campaign_get_or_create.return_value = Campaign(name='fake-campaign-utm'), True call_command( 'sync_salesforce', '--site-domain', self.site_domain, '--orgs', self.orgs ) call_command( 'sync_salesforce', '--site-domain', self.site_domain, '--orgs', self.orgs )
def test_command_with_opportunity(self, mock_user_fetch_data, mock_pricebook_get, mock_lead_get, mock_convert_lead, mock_opp_get_or_create, mock_lead_save, mock_contact_save): """ Test management command with a lead which is in "In Sync" status. """ course = self.user_data['courses'][0] opportunity = Opportunity( name=course['course_id'], amount=course['unit_price'] * course['quantity'], close_date=course['purchase_date'], stage_name='Paid', ) mock_pricebook_get.return_value = Pricebook2(is_standard=True) mock_lead_get.return_value = self._get_lead_object(is_converted=False) mock_user_fetch_data.return_value = [self.user_data] mock_opp_get_or_create.return_value = opportunity, False call_command( 'sync_salesforce', '--site-domain', self.site_domain, '--orgs', self.orgs ) mock_pricebook_get.assert_called_with(is_standard=True) self.assertTrue(mock_contact_save.called) self.assertFalse(mock_lead_save.called)
def test_command_without_coupon_codes(self, mock_user_fetch_data, mock_pricebook_get, mock_lead_get, mock_convert_lead, mock_opp_get_or_create, mock_product2_get_or_create, mock_price_book_entry_get, mock_opp_contact_role_create, mock_opp_line_item_create, mock_lead_save, mock_contact_save, mock_price_book_save): """ Test management command when coupon codes are empty. """ course = self.user_data['courses'][0] opportunity = Opportunity( name=course['course_id'], amount=course['unit_price'] * course['quantity'], close_date=course['purchase_date'], stage_name='Paid', ) product = Product2(name=course['course_id']) price_book = Pricebook2(is_standard=True) mock_pricebook_get.return_value = price_book mock_lead_get.return_value = self._get_lead_object(is_converted=False) user_data_without_discount_code = dict(self.user_data) user_data_without_discount_code['courses'][0]['coupon_codes'] = None mock_user_fetch_data.return_value = [user_data_without_discount_code] mock_opp_get_or_create.return_value = opportunity, True mock_product2_get_or_create.return_value = product, True mock_price_book_entry_get.return_value = PricebookEntry( pricebook2=price_book, product2=product, is_active=True, unit_price=decimal.Decimal('10.2') ) call_command( 'sync_salesforce', '--site-domain', self.site_domain, '--orgs', self.orgs ) mock_product2_get_or_create.assert_called_with(name=course['course_id']) mock_pricebook_get.assert_called_with(is_standard=True) self.assertTrue(mock_opp_contact_role_create.called) self.assertTrue(mock_opp_line_item_create.called) self.assertTrue(mock_contact_save.called) self.assertFalse(mock_lead_save.called)
def test_command_with_in_sync_lead(self, mock_user_fetch_data, mock_pricebook_get, mock_lead_get, mock_lead_save): """ Test management command with invalid user data. """ mock_pricebook_get.return_value = Pricebook2(is_standard=True) user_data_without_courses = dict(self.user_data) mock_lead_get.return_value = self._get_lead_object(is_converted=False) user_data_without_courses['courses'] = {} mock_user_fetch_data.return_value = [user_data_without_courses] call_command( 'sync_salesforce', '--site-domain', self.site_domain, '--orgs', self.orgs ) mock_pricebook_get.assert_called_with(is_standard=True) self.assertFalse(mock_lead_save.called)
def test_command_with_no_lead_and_empty_campaign(self, mock_user_fetch_data, mock_pricebook_get, mock_lead_get, mock_lead_save, mock_campaign_get_or_create, mock_campaign_member_create): """ Test management command when lead does not exist for given user data and utm_campaign is empty. """ utm_campaign = self.user_data['tracking']['utm_campaign'] mock_pricebook_get.return_value = Pricebook2(is_standard=True) user_data_without_courses = dict(self.user_data) user_data_without_courses['courses'] = {} user_data_without_courses['tracking']['utm_campaign'] = None mock_user_fetch_data.return_value = [user_data_without_courses] mock_campaign_get_or_create.return_value = Campaign(name=utm_campaign), True call_command( 'sync_salesforce', '--site-domain', self.site_domain, '--orgs', self.orgs ) mock_pricebook_get.assert_called_with(is_standard=True) self.assertTrue(mock_lead_save.called)
def test_command_with_converted_lead(self, mock_user_fetch_data, mock_pricebook_get, mock_lead_get, mock_opp_get_or_create, mock_dc_get_or_create, mock_product2_get_or_create, mock_opp_contact_role_create, mock_price_book_entry_get, mock_price_book_entry_create, mock_convert_lead, mock_opp_line_item_create, mock_lead_save, mock_contact_save, mock_price_book_save): """ Test management command when lead is converted contact. """ course = self.user_data['courses'][0] opportunity = Opportunity( name=course['course_id'], amount=course['unit_price'] * course['quantity'], close_date=course['purchase_date'], stage_name='Paid', ) product = Product2(name=course['course_id']) price_book = Pricebook2(is_standard=True) mock_user_fetch_data.return_value = [self.user_data] mock_pricebook_get.return_value = price_book mock_lead_get.return_value = self._get_lead_object(is_converted=True) mock_opp_get_or_create.return_value = opportunity, True mock_dc_get_or_create.return_value = DiscountCode(name=course['coupon_codes'][0]), True mock_product2_get_or_create.return_value = product, True call_command( 'sync_salesforce', '--site-domain', self.site_domain, '--orgs', self.orgs ) mock_lead_get.assert_called_with(username=self.user_data['username']) mock_pricebook_get.assert_called_with(is_standard=True) self.assertTrue(mock_price_book_entry_create.called) self.assertFalse(mock_contact_save.called)
from ddt import ddt, data, unpack from django.test import TestCase from edx_salesforce.models import (Account, Campaign, CampaignMember, Contact, DiscountCode, Lead, Opportunity, OpportunityContactRole, OpportunityLineItem, Pricebook2, PricebookEntry, Product2) ACCOUNT = Account(name='foo') CAMPAIGN = Campaign(name='foo') LEAD = Lead(username='******') CAMPAIGN_MEMBER = CampaignMember(campaign=CAMPAIGN, lead=LEAD) CONTACT = Contact(name='foo') DISCOUNT_CODE = DiscountCode(name='foo') OPPORTUNITY = Opportunity(name='foo') OPPORTUNITY_CONTACT_ROLE = OpportunityContactRole(opportunity=OPPORTUNITY, contact=CONTACT) PRICEBOOK = Pricebook2(name='foo') PRODUCT = Product2(name='foo') PRICEBOOK_ENTRY = PricebookEntry(pricebook2=PRICEBOOK, product2=PRODUCT) OPPORTUNITY_LINE_ITEM = OpportunityLineItem(opportunity=OPPORTUNITY, pricebook_entry=PRICEBOOK_ENTRY) @ddt class TestUnicode(TestCase): """ Test utilities module. """ @data( (ACCOUNT, ACCOUNT.name), (CAMPAIGN, CAMPAIGN.name), (LEAD, LEAD.username),