예제 #1
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]
예제 #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_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
예제 #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 = []
        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]
예제 #5
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]