def test__check_lead_duplication_fail_if_your_and_over_leads_found_and_audited_by_others(
         self):
     you = User(id=1)
     your_project = Project(user=you)
     your_pixel = Pixel(project=your_project)
     someone = User(id=2)
     someone_project = Project(user=someone)
     someone_pixel = Pixel(project=someone_project)
     sometwo = User(id=3)
     sometwo_audit2 = Audit(processed=strptime('2018-02-27'), user=sometwo)
     your_lead1 = Lead(pixel=your_pixel, created=strptime('2018-02-24'))
     someone_lead2 = Lead(pixel=someone_pixel,
                          created=strptime('2018-02-25'))
     your_lead3 = Lead(pixel=your_pixel, created=strptime('2018-02-26'))
     with mock.patch(
             'collector.models.analytics.Lead.audits') as mock_manager:
         mock_manager.all.return_value = [sometwo_audit2]
         leads = [
             your_lead1,
             someone_lead2,
             your_lead3,
         ]
         res = lead_duplication._check_lead_duplication(you, leads)
         self.assertEquals(
             {
                 'success': False,
                 'resolution': 'Lead was sold 2 times',
                 'created': strptime('2018-02-26'),
                 'your_audits': [],
                 'duplicates': [strptime('2018-02-24')],
                 'sales': [strptime('2018-02-27'),
                           strptime('2018-02-25')]
             }, res)
 def test__check_lead_duplication_fail_if_no_leads_found(self):
     you = User(id=1)
     leads = []
     res = lead_duplication._check_lead_duplication(you, leads)
     self.assertEquals(
         {
             'success': False,
             'resolution': 'Lead was sold to you outside the system',
             'created': None,
             'your_audits': [],
             'duplicates': [],
             'sales': []
         }, res)
 def test__check_lead_duplication_success_if_one_your_lead_found(self):
     you = User(id=1)
     your_project = Project(user=you)
     your_pixel = Pixel(project=your_project)
     leads = [Lead(pixel=your_pixel, created=strptime('2018-02-26'))]
     res = lead_duplication._check_lead_duplication(you, leads)
     self.assertEquals(
         {
             'success': True,
             'resolution': 'New lead',
             'created': strptime('2018-02-26'),
             'your_audits': [],
             'duplicates': [],
             'sales': []
         }, res)
 def test__check_lead_duplication_success_if_one_your_lead_found_and_audited_by_you(
         self):
     you = User(id=1)
     your_project = Project(user=you)
     your_pixel = Pixel(project=your_project)
     your_audit = Audit(processed=strptime('2018-02-27'), user=you)
     your_lead = Lead(pixel=your_pixel, created=strptime('2018-02-26'))
     with mock.patch(
             'collector.models.analytics.Lead.audits') as mock_manager:
         mock_manager.all.return_value = [your_audit]
         leads = [your_lead]
         res = lead_duplication._check_lead_duplication(you, leads)
         self.assertEquals(
             {
                 'success': True,
                 'resolution': 'You already audited this lead 1 times',
                 'created': strptime('2018-02-26'),
                 'your_audits': [strptime('2018-02-27')],
                 'duplicates': [],
                 'sales': []
             }, res)
 def test__check_lead_duplication_fail_if_only_your_leads_found(self):
     you = User(id=1)
     your_project = Project(user=you)
     your_pixel = Pixel(project=your_project)
     your_lead1 = Lead(pixel=your_pixel, created=strptime('2018-02-24'))
     your_lead2 = Lead(pixel=your_pixel, created=strptime('2018-02-25'))
     your_lead3 = Lead(pixel=your_pixel, created=strptime('2018-02-26'))
     leads = [
         your_lead1,
         your_lead2,
         your_lead3,
     ]
     res = lead_duplication._check_lead_duplication(you, leads)
     self.assertEquals(
         {
             'success': False,
             'resolution': 'Lead has 2 duplicates',
             'created': strptime('2018-02-26'),
             'your_audits': [],
             'duplicates': [strptime('2018-02-25'),
                            strptime('2018-02-24')],
             'sales': []
         }, res)
 def test__check_lead_duplication_fail_if_only_others_leads_found(self):
     you = User(id=1)
     someone = User(id=2)
     someone_project = Project(user=someone)
     someone_pixel = Pixel(project=someone_project)
     someone1_lead = Lead(pixel=someone_pixel,
                          created=strptime('2018-02-25'))
     someone2_lead = Lead(pixel=someone_pixel,
                          created=strptime('2018-02-26'))
     leads = [
         someone2_lead,
         someone1_lead,
     ]
     res = lead_duplication._check_lead_duplication(you, leads)
     self.assertEquals(
         {
             'success': False,
             'resolution': 'Lead was sold to you outside the system',
             'created': None,
             'your_audits': [],
             'duplicates': [],
             'sales': [strptime('2018-02-26')]
         }, res)