Ejemplo n.º 1
0
    def deals_deal(self, **kwargs):
        kwargs.update({
            'size': kwargs.get('size', self.batch_size) / 2,
            'tenant': kwargs.get('tenant', self.tenant),
            'account': kwargs.get('account') if kwargs.get('account') else iterator(self.accounts_account),
            'contact': kwargs.get('contact') if kwargs.get('contact') else iterator(self.contacts_contact),
            'assigned_to': kwargs.get('assigned_to') if kwargs.get('assigned_to') else iterator(self.users_user),
            'contacted_by': kwargs.get('contacted_by') if kwargs.get('contacted_by') else
            iterator(self.deals_deal_contacted_by),
            'found_through': kwargs.get('found_through') if kwargs.get('found_through') else
            iterator(self.deals_deal_found_through),
            'next_step': kwargs.get('next_step') if kwargs.get('next_step') else
            iterator(self.deals_deal_next_step),
            'status': kwargs.get('status') if kwargs.get('status') else iterator(self.deals_deal_status),
            'why_customer': kwargs.get('why_customer') if kwargs.get('why_customer') else
            iterator(self.deals_deal_why_customer),
        })
        contact = kwargs.pop('contact')
        kwargs['contact'] = None
        deals_with_accounts = DealFactory.create_batch(**kwargs)

        kwargs['contact'] = contact
        deals_with_contacts = DealFactory.create_batch(**kwargs)

        self.stdout.write('Done with deals_deal.')

        return deals_with_accounts + deals_with_contacts
Ejemplo n.º 2
0
    def deals_deal(self, **kwargs):
        kwargs.update({
            'size': kwargs.get('size', self.batch_size) / 2,
            'tenant': kwargs.get('tenant', self.tenant),
            'account': kwargs.get('account') if kwargs.get('account') else iterator(self.accounts_account),
            'contact': kwargs.get('contact') if kwargs.get('contact') else iterator(self.contacts_contact),
            'assigned_to': kwargs.get('assigned_to') if kwargs.get('assigned_to') else iterator(self.users_user),
            'contacted_by': kwargs.get('contacted_by') if kwargs.get('contacted_by') else
            iterator(self.deals_deal_contacted_by),
            'found_through': kwargs.get('found_through') if kwargs.get('found_through') else
            iterator(self.deals_deal_found_through),
            'next_step': kwargs.get('next_step') if kwargs.get('next_step') else
            iterator(self.deals_deal_next_step),
            'status': kwargs.get('status') if kwargs.get('status') else iterator(self.deals_deal_status),
            'why_customer': kwargs.get('why_customer') if kwargs.get('why_customer') else
            iterator(self.deals_deal_why_customer),
        })
        contact = kwargs.pop('contact')
        kwargs['contact'] = None
        deals_with_accounts = DealFactory.create_batch(**kwargs)

        kwargs['contact'] = contact
        deals_with_contacts = DealFactory.create_batch(**kwargs)

        self.stdout.write('Done with deals_deal.')

        return deals_with_accounts + deals_with_contacts
Ejemplo n.º 3
0
    def deals_deal(self, **kwargs):
        kwargs.update(
            {
                "size": kwargs.get("size", self.batch_size) / 2,
                "tenant": kwargs.get("tenant", self.tenant),
                "account": kwargs.get("account") if kwargs.get("account") else iterator(self.accounts_account),
                "contact": kwargs.get("contact") if kwargs.get("contact") else iterator(self.contacts_contact),
                "assigned_to": kwargs.get("assigned_to") if kwargs.get("assigned_to") else iterator(self.users_user),
                "contacted_by": kwargs.get("contacted_by")
                if kwargs.get("contacted_by")
                else iterator(self.deals_deal_contacted_by),
                "found_through": kwargs.get("found_through")
                if kwargs.get("found_through")
                else iterator(self.deals_deal_found_through),
                "next_step": kwargs.get("next_step")
                if kwargs.get("next_step")
                else iterator(self.deals_deal_next_step),
                "status": kwargs.get("status") if kwargs.get("status") else iterator(self.deals_deal_status),
                "why_customer": kwargs.get("why_customer")
                if kwargs.get("why_customer")
                else iterator(self.deals_deal_why_customer),
            }
        )
        contact = kwargs.pop("contact")
        kwargs["contact"] = None
        deals_with_accounts = DealFactory.create_batch(**kwargs)

        kwargs["contact"] = contact
        deals_with_contacts = DealFactory.create_batch(**kwargs)

        self.stdout.write("Done with deals_deal.")

        return deals_with_accounts + deals_with_contacts
Ejemplo n.º 4
0
    def test_contact_closed_case(self):
        """
        Test having a contact with no open deals or cases. There is only a case closed less than a week ago.
        """
        cases = CaseFactory.create_batch(size=5, tenant=self.user_obj.tenant)
        Case.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc),
                                  status=self.case_status_closed)

        DealFactory.create_batch(size=5, tenant=self.user_obj.tenant)
        Deal.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc),
                                  status=self.deal_status_lost)

        case = cases[0]
        case.contact = self.contact
        case.is_deleted = False
        case.status = self.case_status_closed
        case.modified = self.four_days_ago
        case.update_modified = False
        case.save()

        assigned_to_user = case.assigned_to

        # Make api call.
        response = self.user.get(
            reverse(self.search_url,
                    kwargs={'number': self.phone_number.number}))

        # Verify response.
        self._verify_response(response, assigned_to_user)
Ejemplo n.º 5
0
    def test_contact_closed_case(self):
        """
        Test having a contact with no open deals or cases. There is only a case closed less than a week ago.
        """
        cases = CaseFactory.create_batch(size=5, tenant=self.user_obj.tenant)
        Case.objects.all().update(
            modified=datetime(2018, 1, 1, tzinfo=utc),
            status=self.case_status_closed
        )

        DealFactory.create_batch(size=5, tenant=self.user_obj.tenant)
        Deal.objects.all().update(
            modified=datetime(2018, 1, 1, tzinfo=utc),
            status=self.deal_status_lost
        )

        case = cases[0]
        case.contact = self.contact
        case.is_deleted = False
        case.status = self.case_status_closed
        case.modified = self.four_days_ago
        case.update_modified = False
        case.save()

        assigned_to_user = case.assigned_to

        # Make api call.
        response = self.user.get(reverse(self.search_url, kwargs={'number': self.phone_number.number}))

        # Verify response.
        self._verify_response(response, assigned_to_user)
Ejemplo n.º 6
0
    def test_contact_open_deal_open_case_no_notes(self):
        """
        Test having a contact with open deals and cases. Both without notes.
        """
        # There are open cases and open deals, both have no attached notes. The case is the most recent edited.
        cases = CaseFactory.create_batch(size=5, tenant=self.user_obj.tenant)
        Case.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc))

        case = cases[0]
        case.contact = self.contact
        case.is_deleted = False
        case.status = self.case_status_new
        case.modified = datetime(2018, 1, 3, tzinfo=utc)
        case.update_modified = False
        case.save()

        assigned_to_user = case.assigned_to

        deals = DealFactory.create_batch(size=5, tenant=self.user_obj.tenant)
        Deal.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc))

        deal = deals[0]
        deal.is_deleted = False
        deal.status = self.deal_status_open
        deal.contact = self.contact
        deal.modified = datetime(2018, 1, 2, tzinfo=utc)
        deal.update_modified = False
        deal.save()

        # Make api call.
        response = self.user.get(
            reverse(self.search_url,
                    kwargs={'number': self.phone_number.number}))

        # Verify response.
        self._verify_response(response, assigned_to_user)

        # There are open cases and open deals, both have no attached notes. The deal is the most recent edited.
        Case.objects.filter(pk=case.pk).update(
            modified=datetime(2018, 3, 2, tzinfo=utc))
        Deal.objects.filter(pk=deal.pk).update(
            modified=datetime(2018, 3, 3, tzinfo=utc))

        assigned_to_user = deal.assigned_to

        # Make api call.
        response = self.user.get(
            reverse(self.search_url,
                    kwargs={'number': self.phone_number.number}))

        # Verify response.
        self._verify_response(response, assigned_to_user)
Ejemplo n.º 7
0
    def test_contact_open_deal_open_case_no_notes(self):
        """
        Test having a contact with open deals and cases. Both without notes.
        """
        # There are open cases and open deals, both have no attached notes. The case is the most recent edited.
        cases = CaseFactory.create_batch(size=5, tenant=self.user_obj.tenant)
        Case.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc))

        case = cases[0]
        case.contact = self.contact
        case.is_deleted = False
        case.status = self.case_status_new
        case.modified = datetime(2018, 1, 3, tzinfo=utc)
        case.update_modified = False
        case.save()

        assigned_to_user = case.assigned_to

        deals = DealFactory.create_batch(size=5, tenant=self.user_obj.tenant)
        Deal.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc))

        deal = deals[0]
        deal.is_deleted = False
        deal.status = self.deal_status_open
        deal.contact = self.contact
        deal.modified = datetime(2018, 1, 2, tzinfo=utc)
        deal.update_modified = False
        deal.save()

        # Make api call.
        response = self.user.get(reverse(self.search_url, kwargs={'number': self.phone_number.number}))

        # Verify response.
        self._verify_response(response, assigned_to_user)

        # There are open cases and open deals, both have no attached notes. The deal is the most recent edited.
        Case.objects.filter(pk=case.pk).update(modified=datetime(2018, 3, 2, tzinfo=utc))
        Deal.objects.filter(pk=deal.pk).update(modified=datetime(2018, 3, 3, tzinfo=utc))

        assigned_to_user = deal.assigned_to

        # Make api call.
        response = self.user.get(reverse(self.search_url, kwargs={'number': self.phone_number.number}))

        # Verify response.
        self._verify_response(response, assigned_to_user)
Ejemplo n.º 8
0
    def test_contact_open_deal(self):
        """
        Test having a contact with only open deals.
        """
        deals = DealFactory.create_batch(size=5, tenant=self.user_obj.tenant)
        Deal.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc))

        deal = deals[0]
        deal.is_deleted = False
        deal.status = self.deal_status_open
        deal.contact = self.contact
        deal.modified = datetime(2018, 1, 2, tzinfo=utc)
        deal.update_modified = False
        deal.save()

        assigned_to_user = deal.assigned_to

        # Make api call.
        response = self.user.get(reverse(self.search_url, kwargs={'number': self.phone_number.number}))

        # Verify response.
        self._verify_response(response, assigned_to_user)
Ejemplo n.º 9
0
    def test_contact_open_deal(self):
        """
        Test having a contact with only open deals.
        """
        deals = DealFactory.create_batch(size=5, tenant=self.user_obj.tenant)
        Deal.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc))

        deal = deals[0]
        deal.is_deleted = False
        deal.status = self.deal_status_open
        deal.contact = self.contact
        deal.modified = datetime(2018, 1, 2, tzinfo=utc)
        deal.update_modified = False
        deal.save()

        assigned_to_user = deal.assigned_to

        # Make api call.
        response = self.user.get(
            reverse(self.search_url,
                    kwargs={'number': self.phone_number.number}))

        # Verify response.
        self._verify_response(response, assigned_to_user)
Ejemplo n.º 10
0
 def deals(self, size, tenant):
     DealFactory.create_batch(size, tenant=tenant)
Ejemplo n.º 11
0
class InternalNumberSearchAPITestCase(UserBasedTest, APITestCase):
    search_url = 'search_internal_number_view'

    @classmethod
    def setUpTestData(cls):
        super(InternalNumberSearchAPITestCase, cls).setUpTestData()

        cls.four_days_ago = datetime.now(tz=utc) - timedelta(days=4)
        cls.five_days_ago = datetime.now(tz=utc) - timedelta(days=5)
        cls.nine_days_ago = datetime.now(tz=utc) - timedelta(days=9)

        cls.case_status_new = CaseStatusFactory.create(
            tenant=cls.user_obj.tenant, name='New')
        cls.case_status_closed = CaseStatusFactory.create(
            tenant=cls.user_obj.tenant, name='Closed')
        cls.deal_status_open = DealStatusFactory.create(
            tenant=cls.user_obj.tenant, name='Open')
        cls.deal_status_lost = DealStatusFactory.create(
            tenant=cls.user_obj.tenant, name='Lost')

        cls.phone_number = PhoneNumberFactory(tenant=cls.user_obj.tenant,
                                              number='+31611223344')
        cls.contact = ContactFactory.create(tenant=cls.user_obj.tenant)
        cls.contact.phone_numbers.add(cls.phone_number)

    def test_contact_open_deal_open_case_notes(self):
        """
        Test having a contact with open deals and cases. Both with notes.
        """
        # There are open cases and open deals, both have attached notes. The most recent note is for a case.
        cases = CaseFactory.create_batch(size=5, tenant=self.user_obj.tenant)
        Case.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc))

        case = cases[0]
        case.contact = self.contact
        case.is_deleted = False
        case.status = self.case_status_new
        case.modified = datetime(2018, 1, 3, tzinfo=utc)
        case.update_modified = False
        case.save()

        case_notes = NoteFactory.create_batch(
            size=5,
            tenant=self.user_obj.tenant,
            gfk_content_type=case.content_type,
            gfk_object_id=case.id)

        for note in case_notes:
            case.notes.add(note)

        case_note = case_notes[0]

        deals = DealFactory.create_batch(size=5, tenant=self.user_obj.tenant)
        Deal.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc))

        deal = deals[0]
        deal.is_deleted = False
        deal.status = self.deal_status_open
        deal.contact = self.contact
        deal.modified = datetime(2018, 1, 2, tzinfo=utc)
        deal.update_modified = False
        deal.save()

        deal_notes = NoteFactory.create_batch(
            size=5,
            tenant=self.user_obj.tenant,
            gfk_content_type=deal.content_type,
            gfk_object_id=deal.id)

        for note in deal_notes:
            deal.notes.add(note)

        deal_note = deal_notes[0]

        Note.objects.all().update(modified=datetime(2018, 1, 1, tzinfo=utc))
        Note.objects.filter(pk=case_note.pk).update(
            modified=datetime(2018, 2, 3, tzinfo=utc))
        Note.objects.filter(pk=deal_note.pk).update(
            modified=datetime(2018, 2, 2, tzinfo=utc))

        assigned_to_user = case.assigned_to

        # Make api call.
        response = self.user.get(
            reverse(self.search_url,
                    kwargs={'number': self.phone_number.number}))

        # Verify response.
        self._verify_response(response, assigned_to_user)

        # There are open cases and open deals, both have attached notes. The most recent note is for a deal.
        Note.objects.filter(pk=case_note.pk).update(
            modified=datetime(2018, 2, 2, tzinfo=utc))
        Note.objects.filter(pk=deal_note.pk).update(
            modified=datetime(2018, 2, 3, tzinfo=utc))

        assigned_to_user = deal.assigned_to

        # Make api call.
        response = self.user.get(
            reverse(self.search_url,
                    kwargs={'number': self.phone_number.number}))

        # Verify response.
        self._verify_response(response, assigned_to_user)
Ejemplo n.º 12
0
 def deals(self, size, tenant):
     DealFactory.create_batch(size, tenant=tenant)