예제 #1
0
    def _create_object(self, with_relations=False, size=1, **kwargs):
        """
        Create an object with relations in the database 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 = self.factory_cls.create_batch(size=size, **kwargs)

        for iteration in range(0, size):
            obj = object_list[iteration]

            if with_relations:
                obj.phone_numbers.add(*PhoneNumberFactory.create_batch(size=2, tenant=obj.tenant))
                obj.social_media.add(SocialMediaFactory(tenant=obj.tenant))
                obj.addresses.add(AddressFactory(tenant=obj.tenant))
                obj.email_addresses.add(EmailAddressFactory(tenant=obj.tenant))
                obj.functions.add(*FunctionFactory.create_batch(size=2, tenant=obj.tenant, contact=obj))
                obj.tags.add(*TagFactory.create_batch(size=2, tenant=obj.tenant, subject=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]
예제 #2
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]
예제 #3
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]
예제 #4
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]
예제 #5
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
예제 #6
0
    def _create_object(self, with_relations=False, size=1, **kwargs):
        """
        Create an object with relations in the database 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 = self.factory_cls.create_batch(size=size, **kwargs)

        for iteration in range(0, size):
            obj = object_list[iteration]

            if with_relations:
                obj.phone_numbers.add(*PhoneNumberFactory.create_batch(size=2, tenant=obj.tenant))
                obj.social_media.add(SocialMediaFactory(tenant=obj.tenant))
                obj.addresses.add(AddressFactory(tenant=obj.tenant))
                obj.email_addresses.add(EmailAddressFactory(tenant=obj.tenant))
                obj.functions.add(*FunctionFactory.create_batch(size=2, tenant=obj.tenant, contact=obj))
                obj.tags.add(*TagFactory.create_batch(size=2, tenant=obj.tenant, subject=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]
예제 #7
0
    def _create_object_with_relations(self):
        """
        Create an object with relations in the database using factories.
        """
        contact = self.factory_cls(tenant=self.user_obj.tenant)
        contact.phone_numbers.add(PhoneNumberFactory(tenant=contact.tenant))
        contact.social_media.add(SocialMediaFactory(tenant=contact.tenant))
        contact.addresses.add(AddressFactory(tenant=contact.tenant))
        contact.email_addresses.add(EmailAddressFactory(tenant=contact.tenant))
        contact.functions.add(
            FunctionFactory(tenant=contact.tenant, contact=contact))
        contact.tags.add(TagFactory(tenant=contact.tenant, subject=contact))

        return contact