Ejemplo n.º 1
0
 def contacts_and_accounts(self, size, tenant):
     # create various contacts
     ContactFactory.create_batch(size, tenant=tenant)
     # create accounts with zero contact
     AccountFactory.create_batch(size, tenant=tenant)
     # create account with multi contacts
     function_factory(tenant).create_batch(size, account=AccountFactory(tenant=tenant))
Ejemplo n.º 2
0
 def notes(self, size, tenant):
     NoteFactory.create_batch(size, tenant=tenant)
     # create multiple notes for single subject and multi author
     NoteFactory.create_batch(size,
                              tenant=tenant,
                              subject=AccountFactory(tenant=tenant))
     # create multiple notes for single subject and single author
     NoteFactory.create_batch(size,
                              tenant=tenant,
                              author=LilyUserFactory(tenant=tenant),
                              subject=AccountFactory(tenant=tenant))
Ejemplo n.º 3
0
 def contacts_and_accounts(self, size, tenant):
     # create various contacts
     ContactFactory.create_batch(size, tenant=tenant)
     # create accounts with zero contact
     AccountFactory.create_batch(size, tenant=tenant)
     # create account with multi contacts
     function_factory(tenant).create_batch(
         size, account=AccountFactory(tenant=tenant))
     # create account with assigned_to
     function_factory(tenant).create_batch(
         size,
         account=AccountFactory(tenant=tenant,
                                assigned_to=LilyUserFactory(tenant=tenant)))
Ejemplo n.º 4
0
    def accounts_account(self, **kwargs):
        kwargs.update({
            'size': kwargs.get('size', self.batch_size) / 2,
            'tenant': kwargs.get('tenant', self.tenant),
            'assigned_to': kwargs.get('assigned_to') if kwargs.get('assigned_to') else iterator(self.users_user),
        })
        accounts_with_users = AccountFactory.create_batch(**kwargs)

        del kwargs['assigned_to']
        accounts_without_users = AccountFactory.create_batch(**kwargs)

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

        return accounts_with_users + accounts_without_users
Ejemplo n.º 5
0
    def accounts_account(self, **kwargs):
        kwargs.update({
            'size': kwargs.get('size', self.batch_size) / 2,
            'tenant': kwargs.get('tenant', self.tenant),
            'assigned_to': kwargs.get('assigned_to') if kwargs.get('assigned_to') else iterator(self.users_user),
        })
        accounts_with_users = AccountFactory.create_batch(**kwargs)

        del kwargs['assigned_to']
        accounts_without_users = AccountFactory.create_batch(**kwargs)

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

        return accounts_with_users + accounts_without_users
Ejemplo n.º 6
0
    def _create_object_stub(self, with_relations=False, size=1, **kwargs):
        """
        Create an object dict with relation dicts using factories.
        """
        object_list = []

        for iteration in range(0, size):
            obj = self.factory_cls.stub(**kwargs).__dict__
            del obj['tenant']

            if with_relations:
                # If relations are needed, override them, because a dict is needed instead of an instance.
                obj['phone_numbers'] = [PhoneNumberFactory.stub().__dict__, ]
                obj['social_media'] = [SocialMediaFactory.stub().__dict__, ]
                obj['addresses'] = [AddressFactory.stub().__dict__, ]
                obj['email_addresses'] = [EmailAddressFactory.stub().__dict__, ]
                obj['accounts'] = [AccountFactory.stub().__dict__, ]
                obj['accounts'][0]['status'] = {'id': AccountStatusFactory.create(tenant=self.user_obj.tenant).id}
                obj['tags'] = [TagFactory.stub().__dict__, ]

                del obj['accounts'][0]['tenant']

            object_list.append(obj)

        if size > 1:
            return object_list
        else:
            # If required size is 1, just give the object instead of a list.
            return object_list[0]
Ejemplo n.º 7
0
    def _create_object_stub(self, with_relations=False, size=1, **kwargs):
        """
        Create an object dict with relation dicts using factories.
        """
        object_list = []

        for iteration in range(0, size):
            obj = self.factory_cls.stub(**kwargs).__dict__
            del obj['tenant']

            if with_relations:
                # If relations are needed, override them, because a dict is needed instead of an instance.
                obj['phone_numbers'] = [PhoneNumberFactory.stub().__dict__, ]
                obj['social_media'] = [SocialMediaFactory.stub().__dict__, ]
                obj['addresses'] = [AddressFactory.stub().__dict__, ]
                obj['email_addresses'] = [EmailAddressFactory.stub().__dict__, ]
                obj['accounts'] = [AccountFactory.stub().__dict__, ]
                obj['accounts'][0]['status'] = {'id': AccountStatusFactory.create(tenant=self.user_obj.tenant).id}
                obj['tags'] = [TagFactory.stub().__dict__, ]

                del obj['accounts'][0]['tenant']

            object_list.append(obj)

        if size > 1:
            return object_list
        else:
            # If required size is 1, just give the object instead of a list.
            return object_list[0]
Ejemplo n.º 8
0
    def _create_object_stub(self, with_relations=False, size=1, **kwargs):
        """
        Create an object dict with relation dicts using factories.
        """
        # Set a default tenant of the user.
        kwargs['tenant'] = self.user_obj.tenant if not kwargs.get('tenant') else kwargs['tenant']

        object_list = []
        account = AccountFactory(**kwargs)
        assigned_to = LilyUserFactory(**kwargs)
        next_step = DealNextStepFactory(**kwargs)
        why_customer = DealWhyCustomerFactory(**kwargs)
        found_through = DealFoundThroughFactory(**kwargs)
        contacted_by = DealContactedByFactory(**kwargs)
        status = DealStatusFactory(**kwargs)
        why_lost = DealWhyLostFactory(**kwargs)

        for iteration in range(0, size):
            obj = self.factory_cls.stub(**kwargs).__dict__
            del obj['tenant']
            del obj['contact']

            # The minimum viable deal instance needs these relations, so always make them.
            obj['account'] = {
                'id': account.pk,
            }
            obj['assigned_to'] = {
                'id': assigned_to.pk,
            }
            obj['next_step'] = {
                'id': next_step.pk,
            }
            obj['why_customer'] = {
                'id': why_customer.pk,
            }
            obj['found_through'] = {
                'id': found_through.pk,
            }
            obj['contacted_by'] = {
                'id': contacted_by.pk,
            }
            obj['status'] = {
                'id': status.pk,
            }
            obj['why_lost'] = {
                'id': why_lost.pk,
            }

            if with_relations:
                # If relations are needed, override them, because a dict is needed instead of an instance.
                obj['tags'] = [TagFactory.stub().__dict__, ]
                obj['notes'] = [NoteFactory.stub().__dict__, ]

            object_list.append(obj)

        if size > 1:
            return object_list
        else:
            # If required size is 1, just give the object instead of a list.
            return object_list[0]
Ejemplo n.º 9
0
    def accounts_account(self, **kwargs):
        kwargs.update(
            {
                "size": kwargs.get("size", self.batch_size) / 2,
                "tenant": kwargs.get("tenant", self.tenant),
                "assigned_to": kwargs.get("assigned_to") if kwargs.get("assigned_to") else iterator(self.users_user),
            }
        )
        accounts_with_users = AccountFactory.create_batch(**kwargs)

        del kwargs["assigned_to"]
        accounts_without_users = AccountFactory.create_batch(**kwargs)

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

        return accounts_with_users + accounts_without_users
Ejemplo n.º 10
0
    def _create_object_stub_with_relations(self):
        """
        Create an object dict with relation dicts using factories.
        """
        contact = self.factory_cls.stub().__dict__
        contact['phone_numbers'] = [
            PhoneNumberFactory.stub().__dict__,
        ]
        contact['social_media'] = [
            SocialMediaFactory.stub().__dict__,
        ]
        contact['addresses'] = [
            AddressFactory.stub().__dict__,
        ]
        contact['email_addresses'] = [
            EmailAddressFactory.stub().__dict__,
        ]
        contact['accounts'] = [
            AccountFactory.stub().__dict__,
        ]
        contact['tags'] = [
            TagFactory.stub().__dict__,
        ]

        del contact['tenant']
        del contact['accounts'][0]['tenant']

        return contact
Ejemplo n.º 11
0
 def contacts_and_accounts(self, size, tenant):
     # create various contacts
     ContactFactory.create_batch(size, tenant=tenant)
     # create accounts with zero contact
     AccountFactory.create_batch(size, tenant=tenant)
     # create account with multi contacts
     FunctionFactory.create_batch(
         size,
         tenant=tenant,
         account=AccountFactory(tenant=tenant),
     )
     # create account with assigned_to
     FunctionFactory.create_batch(
         size,
         tenant=tenant,
         account=AccountFactory(
             tenant=tenant,
             assigned_to=LilyUserFactory(tenant=tenant)
         ),
     )
Ejemplo n.º 12
0
    def test_contact_closed_deals_cases_account(self):
        """
        Test having a contact attached to a contact with no cases or deals.
        """
        assigned_to_user = LilyUserFactory.create(tenant=self.user_obj.tenant, is_active=True)
        account = AccountFactory.create(tenant=self.user_obj.tenant, assigned_to=assigned_to_user)
        Function.objects.create(account=account, contact=self.contact)

        # 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.º 13
0
    def test_update_modified(self):
        """
        Test that the modified date of a case gets set properly.
        """
        tenant = TenantFactory.create()
        account = AccountFactory.create(tenant=tenant)
        modified = account.modified

        time.sleep(1)

        account.save(update_modified=False)
        self.assertEqual(modified, account.modified)

        account.save(update_modified=True)
        self.assertNotEqual(modified, account.modified)
Ejemplo n.º 14
0
    def test_contact_closed_deals_cases_account(self):
        """
        Test having a contact attached to a contact with no cases or deals.
        """
        assigned_to_user = LilyUserFactory.create(tenant=self.user_obj.tenant,
                                                  is_active=True)
        account = AccountFactory.create(tenant=self.user_obj.tenant,
                                        assigned_to=assigned_to_user)
        Function.objects.create(account=account, contact=self.contact)

        # 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.º 15
0
    def _create_object_stub(self, with_relations=False, size=1, **kwargs):
        """
        Create an object dict with relation dicts using factories.
        """
        # Set a default tenant of the user.
        kwargs['tenant'] = self.user_obj.tenant if not kwargs.get('tenant') else kwargs['tenant']

        object_list = []
        casetype = CaseTypeFactory(**kwargs)
        casestatus = CaseStatusFactory(**kwargs)

        for iteration in range(0, size):
            obj = self.factory_cls.stub(**kwargs).__dict__
            del obj['tenant']

            # The minimum viable case instance needs these relations, so always make them.
            obj['type'] = {
                'id': casetype.pk
            }
            obj['status'] = {
                'id': casestatus.pk
            }

            if with_relations:
                # If relations are needed, override them, because a dict is needed instead of an instance.
                obj['account'] = AccountFactory.stub().__dict__
                obj['contact'] = ContactFactory.stub().__dict__
                obj['assigned_to'] = LilyUserFactory.stub().__dict__

                del obj['account']['tenant']
                del obj['contact']['tenant']
                del obj['assigned_to']['tenant']
                del obj['created_by']
            else:
                # Delete the related objects, since they can't be serialized.
                del obj['account']
                del obj['assigned_to']
                del obj['created_by']

            object_list.append(obj)

        if size > 1:
            return object_list
        else:
            # If required size is 1, just give the object instead of a list.
            return object_list[0]
Ejemplo n.º 16
0
    def _create_object_stub(self, with_relations=False, size=1, **kwargs):
        """
        Create an object dict with relation dicts using factories.
        """
        # Set a default tenant of the user.
        kwargs['tenant'] = self.user_obj.tenant if not kwargs.get('tenant') else kwargs['tenant']

        object_list = []
        account = AccountFactory(**kwargs)
        casetype = CaseTypeFactory(**kwargs)
        casestatus = CaseStatusFactory(**kwargs)

        for iteration in range(0, size):
            obj = self.factory_cls.stub(**kwargs).__dict__
            del obj['tenant']

            # The minimum viable case instance needs these relations, so always make them.
            obj['account'] = {
                'id': account.pk,
            }
            obj['type'] = {
                'id': casetype.pk
            }
            obj['status'] = {
                'id': casestatus.pk
            }

            if with_relations:
                # If relations are needed, override them, because a dict is needed instead of an instance.
                obj['assigned_to'] = LilyUserFactory.stub().__dict__

                del obj['assigned_to']['tenant']
                del obj['created_by']
            else:
                # Delete the related objects, since they can't be serialized.
                del obj['assigned_to']
                del obj['created_by']

            object_list.append(obj)

        if size > 1:
            return object_list
        else:
            # If required size is 1, just give the object instead of a list.
            return object_list[0]