def testMoveEnvelopes(self):
        with open(SignTest1File, 'rb') as sign_file:
            file_contents = sign_file.read()

        # create an envelope to be signed
        envelope_definition = docusign.EnvelopeDefinition()
        envelope_definition.email_subject = 'Please Sign my Python SDK Envelope'
        envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.'

        # add a document to the envelope
        doc = docusign.Document()
        base64_doc = base64.b64encode(file_contents).decode("utf-8")
        doc.document_base64 = base64_doc
        doc.name = 'TestFile.pdf'
        doc.document_id = '1'
        envelope_definition.documents = [doc]

        # Add a recipient to sign the document
        signer = docusign.Signer()
        signer.email = Username
        signer.name = 'Pat Developer'
        signer.recipient_id = '1'

        # Create a SignHere tab somewhere on the document for the signer to sign
        sign_here = docusign.SignHere()
        sign_here.document_id = '1'
        sign_here.page_number = '1'
        sign_here.recipient_id = '1'
        sign_here.x_position = '100'
        sign_here.y_position = '100'
        sign_here.scale_value = '0.5'

        tabs = docusign.Tabs()
        tabs.sign_here_tabs = [sign_here]
        signer.tabs = tabs

        recipients = docusign.Recipients()
        recipients.signers = [signer]
        envelope_definition.recipients = recipients

        envelope_definition.status = 'sent'

        envelopes_api = EnvelopesApi()

        try:
            envelope_summary = envelopes_api.create_envelope(
                self.user_info.accounts[0].account_id,
                envelope_definition=envelope_definition)
            assert envelope_summary is not None
            assert envelope_summary.envelope_id is not None
            assert envelope_summary.status == 'sent'

            folders_api = FoldersApi()
            folders_request = docusign.FoldersRequest(
                envelope_ids=[envelope_summary.envelope_id],
                from_folder_id="sentitems")

            to_folder_id = "draft"

            folders_api.move_envelopes(self.user_info.accounts[0].account_id,
                                       to_folder_id,
                                       folders_request=folders_request)

            # Wait for 1 second to make sure the newly created envelope was moved to the 'sentitems' folder
            # Note: It's discouraged to use sleep statement or to poll DocuSign for envelope status or folder id
            # In production, use DocuSign Connect to get notified when the status of the envelope have changed.
            sleep(1)
            # Test if we moved the envelope to the correct folder
            list_from_drafts_folder = folders_api.list_items(
                self.user_info.accounts[0].account_id, to_folder_id)

            assert list_from_drafts_folder is not None

            for item in list_from_drafts_folder.folder_items:
                if item.envelope_id == envelope_summary.envelope_id:
                    return

            assert False

        except ApiException as e:
            print("\nException when calling DocuSign API: %s" % e)
            assert e is None  # make the test case fail in case of an API exception
    def testMoveEnvelopes(self):
        with open(SignTest1File, 'rb') as sign_file:
            file_contents = sign_file.read()

        # Set properties for envelope and create an envelope to be signed later on
        email_subject = 'Please Sign my Python SDK Envelope'
        email_blurb = 'Hello, Please sign my Python SDK Envelope.'

        # add a document to the envelope
        base64_doc = base64.b64encode(file_contents).decode("utf-8")
        name = 'TestFile.pdf'
        document_id = '1'
        doc = docusign.Document(document_base64=base64_doc,
                                name=name,
                                document_id=document_id)
        documents = [doc]

        # Add a recipient to sign the document
        email = Username
        name = 'Pat Developer'
        recipient_id = '1'
        signer = docusign.Signer(email=email,
                                 name=name,
                                 recipient_id=recipient_id)

        # Create a SignHere tab somewhere on the document for the signer to sign
        document_id = '1'
        page_number = '1'
        recipient_id = '1'
        x_position = '100'
        y_position = '100'
        scale_value = '0.5'
        sign_here = docusign.SignHere(document_id=document_id,
                                      page_number=page_number,
                                      recipient_id=recipient_id,
                                      x_position=x_position,
                                      y_position=y_position,
                                      scale_value=scale_value)

        sign_here_tabs = [sign_here]
        tabs = docusign.Tabs(sign_here_tabs=sign_here_tabs)
        signer.tabs = tabs

        signers = [signer]
        recipients = docusign.Recipients(signers=signers)

        status = 'sent'
        # Now setting all the properties in previous steps create the envelope now
        envelope_definition = docusign.EnvelopeDefinition(
            email_subject=email_subject,
            email_blurb=email_blurb,
            documents=documents,
            recipients=recipients,
            status=status)
        envelopes_api = EnvelopesApi()

        try:
            envelope_summary = envelopes_api.create_envelope(
                self.user_info.accounts[0].account_id,
                envelope_definition=envelope_definition)
            assert envelope_summary is not None
            assert envelope_summary.envelope_id is not None
            assert envelope_summary.status == 'sent'

            folders_api = FoldersApi()
            folders_request = docusign.FoldersRequest(
                envelope_ids=[envelope_summary.envelope_id],
                from_folder_id="sentitems")

            to_folder_id = "draft"

            folders_api.move_envelopes(self.user_info.accounts[0].account_id,
                                       to_folder_id,
                                       folders_request=folders_request)

            # Wait for 3 second to make sure the newly created envelope was moved to the 'sentitems' folder
            # Note: It's discouraged to use sleep statement or to poll DocuSign for envelope status or folder id
            # In production, use DocuSign Connect to get notified when the status of the envelope have changed.
            # 3 Seconds because sometimes when not in public or slow networks, the call takes more time and fails for 1 second.
            sleep(3)
            # Test if we moved the envelope to the correct folder

            search_options = "true"
            list_from_drafts_folder = folders_api.list_items(
                self.user_info.accounts[0].account_id,
                to_folder_id,
                include_items=search_options)

            assert list_from_drafts_folder is not None

            for folder in list_from_drafts_folder.folders:
                for list_item in folder.folder_items:
                    if list_item.envelope_id == envelope_summary.envelope_id:
                        return

            assert False

        except ApiException as e:
            print("\nException when calling DocuSign API: %s" % e)
            assert e is None  # make the test case fail in case of an API exception