コード例 #1
0
ファイル: sharing.py プロジェクト: travisjgood/indivo_server
    def admin_setup(bob_account_id):

        admin_client = IndivoClient(data.machine_app_email,
                                    data.machine_app_secret)
        admin_client.set_app_id(data.app_email)

        # Create a record for Alice and set her at the owner
        record_id = admin_client.create_record(
            data=data.demographics).response[PRD]['Record'][0]
        admin_client.set_record_owner(data=data.account['account_id'])

        # Create a basic set of carenets
        carenet_names = ['Family2', 'Friends2', 'School/Office']
        for cname in carenet_names:
            admin_client.create_carenet(data='name=' + cname)

        # Check to make sure the admin can list the carenets and the accounts within each one
        carenets = xpath(
            parse_xml(admin_client.get_record_carenets(record_id=record_id)),
            '/Carenets/Carenet/@id')

        for carenet_id in carenets:
            assert len(
                xpath(
                    parse_xml(
                        admin_client.get_carenet_accounts(
                            carenet_id=carenet_id)), '/CarenetAccounts')) > 0

        return record_id
コード例 #2
0
def test_special_document_handling(IndivoClient):
  CONTACT = 'contact'
  DEMOGRAPHICS = 'demographics'

  try:
    admin_client = IndivoClient(data.machine_app_email, data.machine_app_secret)
    record_id = admin_client.create_record(data=data.contact).response[PRD]['Record'][0]
    admin_client.set_app_id(data.app_email)
    admin_client.set_record_owner(data=data.account['account_id'])
  
    chrome_client = IndivoClient('chrome', 'chrome')
    chrome_client.create_session(data.account)
    chrome_client.read_record(record_id=record_id)
    chrome_client.put_special_document(special_document=DEMOGRAPHICS, data=data.demographics)
    chrome_client.read_special_document(special_document=DEMOGRAPHICS)
    chrome_client.put_special_document(special_document=CONTACT, data=data.contact)
    chrome_client.read_special_document(special_document=CONTACT)

    # replace the contact document
    chrome_client.put_special_document(special_document=CONTACT, data=data.contact02)
    record_doc = parse_xml(chrome_client.read_record())

    # make sure the label of the record was updated
    record_label = xpath(record_doc,'/Record/@label')[0]
    contact_fullname = xpath(parse_xml(data.contact02), '/ns:Contact/ns:name/ns:fullName/text()', namespaces={'ns':'http://indivo.org/vocab/xml/documents#'})[0]
    assert record_label == contact_fullname, "record label is %s while contact_fullname is %s" % (record_label, contact_fullname)

  except Exception, e:
    return False, e
コード例 #3
0
def test_special_document_handling(IndivoClient):
    DEMOGRAPHICS = 'demographics'

    try:
        admin_client = IndivoClient(data.machine_app_email,
                                    data.machine_app_secret)
        record_id = admin_client.create_record(
            data=data.demographics).response[PRD]['Record'][0]
        admin_client.set_app_id(data.app_email)
        admin_client.set_record_owner(data=data.account['account_id'])

        chrome_client = IndivoClient('chrome', 'chrome')
        chrome_client.create_session(data.account)
        chrome_client.read_record(record_id=record_id)
        chrome_client.put_special_document(
            special_document=DEMOGRAPHICS, data=data.demographics
        )  #TODO: change client away from "special document" for demograhics
        chrome_client.read_special_document(special_document=DEMOGRAPHICS)

        # replace the demographics document
        chrome_client.put_special_document(special_document=DEMOGRAPHICS,
                                           data=data.demographics2)
        record_doc = parse_xml(chrome_client.read_record())

        # make sure the label of the record was updated
        record_label = xpath(record_doc, '/Record/@label')[0]
        #TODO: update below to work with new smart demographics


#    contact_fullname = xpath(parse_xml(data.contact02), '/ns:Contact/ns:name/ns:fullName/text()', namespaces={'ns':'http://indivo.org/vocab/xml/documents#'})[0]
#    assert record_label == contact_fullname, "record label is %s while contact_fullname is %s" % (record_label, contact_fullname)

    except Exception, e:
        return False, e
コード例 #4
0
def test_special_document_handling(IndivoClient):
    DEMOGRAPHICS = "demographics"

    try:
        admin_client = IndivoClient(data.machine_app_email, data.machine_app_secret)
        record_id = admin_client.create_record(data=data.demographics).response[PRD]["Record"][0]
        admin_client.set_app_id(data.app_email)
        admin_client.set_record_owner(data=data.account["account_id"])

        chrome_client = IndivoClient("chrome", "chrome")
        chrome_client.create_session(data.account)
        chrome_client.read_record(record_id=record_id)
        chrome_client.put_special_document(
            special_document=DEMOGRAPHICS, data=data.demographics
        )  # TODO: change client away from "special document" for demograhics
        chrome_client.read_special_document(special_document=DEMOGRAPHICS)

        # replace the demographics document
        chrome_client.put_special_document(special_document=DEMOGRAPHICS, data=data.demographics2)
        record_doc = parse_xml(chrome_client.read_record())

        # make sure the label of the record was updated
        record_label = xpath(record_doc, "/Record/@label")[0]
        # TODO: update below to work with new smart demographics
    #    contact_fullname = xpath(parse_xml(data.contact02), '/ns:Contact/ns:name/ns:fullName/text()', namespaces={'ns':'http://indivo.org/vocab/xml/documents#'})[0]
    #    assert record_label == contact_fullname, "record label is %s while contact_fullname is %s" % (record_label, contact_fullname)

    except Exception, e:
        return False, e
コード例 #5
0
ファイル: sharing.py プロジェクト: Dhanayan123/indivo_server
  def admin_setup(bob_account_id):

    admin_client = IndivoClient(data.machine_app_email, data.machine_app_secret)
    admin_client.set_app_id(data.app_email)

    # Create a record for Alice and set her at the owner
    record_id = admin_client.create_record(data=data.demographics).response[PRD]['Record'][0]
    admin_client.set_record_owner(data=data.account['account_id'])

    # Create a basic set of carenets
    carenet_names = ['Family2', 'Friends2', 'School/Office']
    for cname in carenet_names:
      admin_client.create_carenet(data='name=' + cname)

    # Check to make sure the admin can list the carenets and the accounts within each one
    carenets = xpath(parse_xml(admin_client.get_record_carenets(record_id = record_id)),'/Carenets/Carenet/@id')

    for carenet_id in carenets:
      assert len(xpath(parse_xml(admin_client.get_carenet_accounts(carenet_id = carenet_id)), '/CarenetAccounts')) > 0

    return record_id
コード例 #6
0
ファイル: core.py プロジェクト: kimcharli/jaide
    def op_cmd(self, command, req_format='text', xpath_expr=""):
        """ Execute an operational mode command.

        Purpose: Used to send an operational mode command to the connected
               | device. This requires and uses a paramiko.SSHClient() as
               | the handler so that we can easily pass and allow all pipe
               | commands to be used.
               |
               | We indiscriminately attach ' | no-more' on the end of
               | every command so the device doesn't hold output. The
               | req_format parameter can be set to 'xml' to force raw
               | xml output in the reply.

        @param command: The single command that to retrieve output from the
                      | device. Any pipes will be taken into account.
        @type command: str
        @param req_format: The desired format of the response, defaults to
                         | 'text', but also accepts 'xml'. **NOTE**: 'xml'
                         | will still return a string, not a libxml ElementTree
        @type req_format: str

        @returns: The reply from the device.
        @rtype: str
        """
        if not command:
            raise InvalidCommandError("Parameter 'command' cannot be empty")
        if req_format.lower() == 'xml' or xpath_expr:
            command = command.strip() + ' | display xml'
        command = command.strip() + ' | no-more\n'
        out = ''
        # when logging in as root, we use _shell to get the response.
        if self.username == 'root':
            self._shell.send(command)
            time.sleep(3)
            while self._shell.recv_ready():
                out += self._shell.recv(999999)
                time.sleep(.75)
            # take off the command being sent and the prompt at the end.
            out = '\n'.join(out.split('\n')[1:-2])
        # not logging in as root, and can grab the output as normal.
        else:
            stdin, stdout, stderr = self._session.exec_command(command=command,
                                           timeout=float(self.session_timeout))
            stdin.close()
            # read normal output
            while not stdout.channel.exit_status_ready():
                out += stdout.read()
            stdout.close()
            # read errors
            while not stderr.channel.exit_status_ready():
                out += stderr.read()
            stderr.close()
        return out if not xpath_expr else xpath(out, xpath_expr)
コード例 #7
0
ファイル: core.py プロジェクト: NetworkAutomation/jaide
    def op_cmd(self, command, req_format='text', xpath_expr=""):
        """ Execute an operational mode command.

        Purpose: Used to send an operational mode command to the connected
               | device. This requires and uses a paramiko.SSHClient() as
               | the handler so that we can easily pass and allow all pipe
               | commands to be used.
               |
               | We indiscriminately attach ' | no-more' on the end of
               | every command so the device doesn't hold output. The
               | req_format parameter can be set to 'xml' to force raw
               | xml output in the reply.

        @param command: The single command that to retrieve output from the
                      | device. Any pipes will be taken into account.
        @type command: str
        @param req_format: The desired format of the response, defaults to
                         | 'text', but also accepts 'xml'. **NOTE**: 'xml'
                         | will still return a string, not a libxml ElementTree
        @type req_format: str

        @returns: The reply from the device.
        @rtype: str
        """
        if not command:
            raise InvalidCommandError("Parameter 'command' cannot be empty")
        if req_format.lower() == 'xml' or xpath_expr:
            command = command.strip() + ' | display xml'
        command = command.strip() + ' | no-more\n'
        out = ''
        # when logging in as root, we use _shell to get the response.
        if self.username == 'root':
            self._shell.send(command)
            time.sleep(3)
            while self._shell.recv_ready():
                out += self._shell.recv(999999)
                time.sleep(.75)
            # take off the command being sent and the prompt at the end.
            out = '\n'.join(out.split('\n')[1:-2])
        # not logging in as root, and can grab the output as normal.
        else:
            stdin, stdout, stderr = self._session.exec_command(command=command,
                                           timeout=float(self.session_timeout))
            stdin.close()
            # read normal output
            while not stdout.channel.exit_status_ready():
                out += stdout.read()
            stdout.close()
            # read errors
            while not stderr.channel.exit_status_ready():
                out += stderr.read()
            stderr.close()
        return out if not xpath_expr else xpath(out, xpath_expr)
コード例 #8
0
    def bob_setup(bob_account_id, record_id, carenet_id, allowed_docs, disallowed_docs):
        bob_chrome_client = IndivoClient("chrome", "chrome")
        bob_chrome_client.create_session(data.account02)

        # SZ: Bob should NOT be able to read the docs directly in the record
        for doc_id in allowed_docs + disallowed_docs:
            assert_403(bob_chrome_client.read_document(record_id=record_id, document_id=doc_id))

        assert_403(bob_chrome_client.get_record_carenets(record_id=record_id))

        # Bob should be able to read the allowed docs
        for doc_id in allowed_docs:
            assert_200(bob_chrome_client.get_carenet_document(carenet_id=carenet_id, document_id=doc_id))

        # Bob should not be able to read the disallowed docs
        for doc_id in disallowed_docs:
            assert_404(bob_chrome_client.get_carenet_document(carenet_id=carenet_id, document_id=doc_id))

        # Bob should be able to list docs in the carenet
        carenet_documents_list = bob_chrome_client.get_carenet_documents(carenet_id=carenet_id).response[PRD][
            "Document"
        ]

        # with a parameter
        carenet_documents_list = bob_chrome_client.get_carenet_documents(
            carenet_id=carenet_id, parameters={"type": "http://indivo.org/vocab/xml/documents#Allergy"}
        ).response[PRD]["Document"]

        # Read carenet allergies
        assert_200(bob_chrome_client.read_carenet_allergies(carenet_id=carenet_id))
        assert_200(bob_chrome_client.read_carenet_problems(carenet_id=carenet_id))

        # Read the contact document, this should work
        contact_doc = parse_xml(
            bob_chrome_client.read_carenet_special_document(carenet_id=carenet_id, special_document="contact")
        )
        contact_name = xpath(
            contact_doc,
            "/ns:Contact/ns:name/ns:fullName/text()",
            namespaces={"ns": "http://indivo.org/vocab/xml/documents#"},
        )
        assert contact_name

        bob_chrome_client.get_account_permissions(account_id=bob_account_id)
        bob_chrome_client.get_carenet_account_permissions(
            carenet_id=carenet_id, record_id=record_id, account_id=bob_account_id
        )

        # Not yet implemented
        # bob_chrome_client.get_carenet_app_permissions(account_id=bob_account_id)

        return True
コード例 #9
0
    def admin_setup(bob_account_id):

        admin_client = IndivoClient(data.machine_app_email, data.machine_app_secret)
        admin_client.set_app_id(data.app_email)

        # Create a record for Alice and set her at the owner
        record_id = admin_client.create_record(data=data.contact).response[PRD]["Record"][0]
        admin_client.set_record_owner(data=data.account["account_id"])

        # Create a basic set of carenets
        carenet_names = ["Family2", "Friends2", "School/Office"]
        for cname in carenet_names:
            admin_client.create_carenet(data="name=" + cname)

        # Check to make sure the admin can list the carenets and the accounts within each one
        carenets = xpath(parse_xml(admin_client.get_record_carenets(record_id=record_id)), "/Carenets/Carenet/@id")

        for carenet_id in carenets:
            assert (
                len(xpath(parse_xml(admin_client.get_carenet_accounts(carenet_id=carenet_id)), "/CarenetAccounts")) > 0
            )

        return record_id
コード例 #10
0
ファイル: sharing.py プロジェクト: Dhanayan123/indivo_server
  def bob_setup(bob_account_id, record_id, carenet_id, allowed_docs, disallowed_docs):
    bob_chrome_client = IndivoClient('chrome', 'chrome')
    bob_chrome_client.create_session(data.account02)

    # SZ: Bob should NOT be able to read the docs directly in the record
    for doc_id in allowed_docs+disallowed_docs:
      assert_403(bob_chrome_client.read_document(record_id=record_id, document_id=doc_id))

    assert_403(bob_chrome_client.get_record_carenets(record_id=record_id))

    # Bob should be able to read the allowed docs

    for doc_id in allowed_docs:
      assert_200(bob_chrome_client.get_carenet_document(carenet_id = carenet_id, document_id = doc_id))

    # Bob should not be able to read the disallowed docs
    for doc_id in disallowed_docs:
      assert_404(bob_chrome_client.get_carenet_document(carenet_id = carenet_id, document_id = doc_id))
    
    # Bob should be able to list docs in the carenet
    carenet_documents_list = bob_chrome_client.get_carenet_documents(carenet_id = carenet_id).response[PRD]['Document']

    # with a parameter
    carenet_documents_list = bob_chrome_client.get_carenet_documents(carenet_id = carenet_id, parameters={'type': 'http://indivo.org/vocab/xml/documents#Allergy'}).response[PRD]['Document']

    # Read carenet allergies
    # TODO: replace with generic call
    # assert_200(bob_chrome_client.read_carenet_allergies(carenet_id = carenet_id))

    # Read the demographics document, this should work
    resp = bob_chrome_client.call('GET', '/carenets/%s/demographics'%carenet_id, options={'parameters':{'response_format':'application/xml'}} )
    demographics_doc = parse_xml(resp)
    family_name = xpath(demographics_doc, '/Models/Model/Field[@name="name_family"]/text()')
    assert(family_name)

    bob_chrome_client.get_account_permissions(account_id=bob_account_id)
    bob_chrome_client.get_carenet_account_permissions(carenet_id= carenet_id,
                                                      record_id=record_id, 
                                                      account_id=bob_account_id)

    # Not yet implemented
    #bob_chrome_client.get_carenet_app_permissions(account_id=bob_account_id)

    return True
コード例 #11
0
ファイル: sharing.py プロジェクト: travisjgood/indivo_server
    def alice_setup(record_id, bob_account_id):

        allergy_type = {'type': 'http://indivo.org/vocab/xml/documents#Models'}

        alice_chrome_client = IndivoClient('chrome', 'chrome')
        alice_chrome_client.create_session(data.account)
        alice_chrome_client.read_record(record_id=record_id)
        alice_chrome_client.get_account_permissions(
            account_id=data.account['account_id'])

        alice_chrome_client.get_account_records(
            account_id=data.account['account_id'])

        # Alice posts a document
        # (We save the first doc instead of zero
        #   due to the demographics doc already in alice's account)
        alice_chrome_client.post_document(data=data.doc01)
        document_id = alice_chrome_client.read_documents(
        ).response[PRD]['Document'][1]

        # Save the document_id in the client's datastore
        alice_chrome_client.ds.document_id = document_id

        # Save the first carenet_id in the client's datastore
        carenet_id = alice_chrome_client.get_record_carenets(
        ).response[PRD]['Carenet'][0]

        # post four documents to Alice's record, 2 allergies and 2 immunizations
        document_1_id = xpath(
            parse_xml(alice_chrome_client.post_document(data=data.allergy)),
            "/Document/@id")[0]
        document_2_id = xpath(
            parse_xml(alice_chrome_client.post_document(data=data.allergy)),
            "/Document/@id")[0]
        document_3_id = xpath(
            parse_xml(
                alice_chrome_client.post_document(data=data.immunization)),
            "/Document/@id")[0]
        document_4_id = xpath(
            parse_xml(
                alice_chrome_client.post_document(data=data.immunization)),
            "/Document/@id")[0]

        # and one more to test nevershare
        document_5_id = xpath(
            parse_xml(alice_chrome_client.post_document(data=data.allergy)),
            "/Document/@id")[0]

        # auto-share allergies
        alice_chrome_client.post_autoshare(data=allergy_type,
                                           carenet_id=carenet_id)

        assert_200(
            alice_chrome_client.get_autoshare_bytype_all(record_id=record_id))

        # unshare that one allergy, which should negate the autoshare
        alice_chrome_client.delete_carenet_document(record_id=record_id,
                                                    document_id=document_2_id,
                                                    carenet_id=carenet_id)

        # nevershare the third allergy
        alice_chrome_client.document_nevershare_set(record_id=record_id,
                                                    document_id=document_5_id)

        # immunizations are individually shared (well only one of them)
        alice_chrome_client.post_carenet_document(document_id=document_3_id,
                                                  carenet_id=carenet_id)
        alice_chrome_client.delete_carenet_document(record_id=record_id,
                                                    document_id=document_4_id,
                                                    carenet_id=carenet_id)

        # Alice shares her demographics document(s) with the carenet
        demographics_doc = parse_xml(
            alice_chrome_client.read_documents(
                record_id=record_id, parameters={'type': 'Demographics'}))
        for doc_id in xpath(demographics_doc, '/Documents/Document/@id'):
            alice_chrome_client.post_carenet_document(record_id=record_id,
                                                      document_id=doc_id,
                                                      carenet_id=carenet_id)

        # Alice adds bob_account_id to carenet[0]
        alice_chrome_client.post_carenet_account(
            carenet_id=carenet_id,
            data='account_id=' + bob_account_id + '&write=false')

        # Review all accounts within carenet[0]
        assert xpath(
            parse_xml(
                alice_chrome_client.get_carenet_accounts(
                    carenet_id=carenet_id)), '/CarenetAccounts')
        alice_chrome_client.get_carenet_apps(carenet_id=carenet_id)

        alice_chrome_client.read_allergies(record_id=record_id)

        # Finally, return the carenet_id, document_id
        # in order to check Bob's access
        # and a second document that is disallowed
        return carenet_id, [document_1_id, document_3_id
                            ], [document_2_id, document_4_id, document_5_id]
コード例 #12
0
ファイル: document.py プロジェクト: gabalese/lepub
 def __body(self):
     return xpath(self.__tree, ".//xhtml:body")
コード例 #13
0
ファイル: sharing.py プロジェクト: travisjgood/indivo_server
    def bob_setup(bob_account_id, record_id, carenet_id, allowed_docs,
                  disallowed_docs):
        bob_chrome_client = IndivoClient('chrome', 'chrome')
        bob_chrome_client.create_session(data.account02)

        # SZ: Bob should NOT be able to read the docs directly in the record
        for doc_id in allowed_docs + disallowed_docs:
            assert_403(
                bob_chrome_client.read_document(record_id=record_id,
                                                document_id=doc_id))

        assert_403(bob_chrome_client.get_record_carenets(record_id=record_id))

        # Bob should be able to read the allowed docs

        for doc_id in allowed_docs:
            assert_200(
                bob_chrome_client.get_carenet_document(carenet_id=carenet_id,
                                                       document_id=doc_id))

        # Bob should not be able to read the disallowed docs
        for doc_id in disallowed_docs:
            assert_404(
                bob_chrome_client.get_carenet_document(carenet_id=carenet_id,
                                                       document_id=doc_id))

        # Bob should be able to list docs in the carenet
        carenet_documents_list = bob_chrome_client.get_carenet_documents(
            carenet_id=carenet_id).response[PRD]['Document']

        # with a parameter
        carenet_documents_list = bob_chrome_client.get_carenet_documents(
            carenet_id=carenet_id,
            parameters={
                'type': 'http://indivo.org/vocab/xml/documents#Allergy'
            }).response[PRD]['Document']

        # Read carenet allergies
        # TODO: replace with generic call
        # assert_200(bob_chrome_client.read_carenet_allergies(carenet_id = carenet_id))

        # Read the demographics document, this should work
        resp = bob_chrome_client.call(
            'GET',
            '/carenets/%s/demographics' % carenet_id,
            options={'parameters': {
                'response_format': 'application/xml'
            }})
        demographics_doc = parse_xml(resp)
        family_name = xpath(demographics_doc,
                            '/Models/Model/Field[@name="name_family"]/text()')
        assert (family_name)

        bob_chrome_client.get_account_permissions(account_id=bob_account_id)
        bob_chrome_client.get_carenet_account_permissions(
            carenet_id=carenet_id,
            record_id=record_id,
            account_id=bob_account_id)

        # Not yet implemented
        #bob_chrome_client.get_carenet_app_permissions(account_id=bob_account_id)

        return True
コード例 #14
0
ファイル: sharing.py プロジェクト: claimat/indivo_server
    def bob_setup(bob_account_id, record_id, carenet_id, allowed_docs,
                  disallowed_docs):
        bob_chrome_client = IndivoClient('chrome', 'chrome')
        bob_chrome_client.create_session(data.account02)

        # SZ: Bob should NOT be able to read the docs directly in the record
        for doc_id in allowed_docs + disallowed_docs:
            assert_403(
                bob_chrome_client.read_document(record_id=record_id,
                                                document_id=doc_id))

        assert_403(bob_chrome_client.get_record_carenets(record_id=record_id))

        # Bob should be able to read the allowed docs
        for doc_id in allowed_docs:
            assert_200(
                bob_chrome_client.get_carenet_document(carenet_id=carenet_id,
                                                       document_id=doc_id))

        # Bob should not be able to read the disallowed docs
        for doc_id in disallowed_docs:
            assert_404(
                bob_chrome_client.get_carenet_document(carenet_id=carenet_id,
                                                       document_id=doc_id))

        # Bob should be able to list docs in the carenet
        carenet_documents_list = bob_chrome_client.get_carenet_documents(
            carenet_id=carenet_id).response[PRD]['Document']

        # with a parameter
        carenet_documents_list = bob_chrome_client.get_carenet_documents(
            carenet_id=carenet_id,
            parameters={
                'type': 'http://indivo.org/vocab/xml/documents#Allergy'
            }).response[PRD]['Document']

        # Read carenet allergies
        assert_200(
            bob_chrome_client.read_carenet_allergies(carenet_id=carenet_id))
        assert_200(
            bob_chrome_client.read_carenet_problems(carenet_id=carenet_id))

        # Read the contact document, this should work
        contact_doc = parse_xml(
            bob_chrome_client.read_carenet_special_document(
                carenet_id=carenet_id, special_document='contact'))
        contact_name = xpath(
            contact_doc,
            '/ns:Contact/ns:name/ns:fullName/text()',
            namespaces={'ns': 'http://indivo.org/vocab/xml/documents#'})
        assert (contact_name)

        bob_chrome_client.get_account_permissions(account_id=bob_account_id)
        bob_chrome_client.get_carenet_account_permissions(
            carenet_id=carenet_id,
            record_id=record_id,
            account_id=bob_account_id)

        # Not yet implemented
        #bob_chrome_client.get_carenet_app_permissions(account_id=bob_account_id)

        return True
コード例 #15
0
ファイル: sharing.py プロジェクト: Dhanayan123/indivo_server
  def alice_setup(record_id, bob_account_id):

    allergy_type = {'type' : 'http://indivo.org/vocab/xml/documents#Models'}

    alice_chrome_client = IndivoClient('chrome', 'chrome')
    alice_chrome_client.create_session(data.account)
    alice_chrome_client.read_record(record_id=record_id)
    alice_chrome_client.get_account_permissions(account_id=data.account['account_id'])

    alice_chrome_client.get_account_records(account_id = data.account['account_id'])

    # Alice posts a document
    # (We save the first doc instead of zero 
    #   due to the demographics doc already in alice's account)
    alice_chrome_client.post_document(data=data.doc01)
    document_id = alice_chrome_client.read_documents().response[PRD]['Document'][1]

    # Save the document_id in the client's datastore
    alice_chrome_client.ds.document_id = document_id

    # Save the first carenet_id in the client's datastore
    carenet_id = alice_chrome_client.get_record_carenets().response[PRD]['Carenet'][0]

    # post four documents to Alice's record, 2 allergies and 2 immunizations
    document_1_id = xpath(parse_xml(alice_chrome_client.post_document(data=data.allergy)), "/Document/@id")[0]
    document_2_id = xpath(parse_xml(alice_chrome_client.post_document(data=data.allergy)), "/Document/@id")[0]
    document_3_id = xpath(parse_xml(alice_chrome_client.post_document(data=data.immunization)), "/Document/@id")[0]
    document_4_id = xpath(parse_xml(alice_chrome_client.post_document(data=data.immunization)), "/Document/@id")[0]

    # and one more to test nevershare
    document_5_id = xpath(parse_xml(alice_chrome_client.post_document(data=data.allergy)), "/Document/@id")[0]

    # auto-share allergies
    alice_chrome_client.post_autoshare(data=allergy_type, carenet_id=carenet_id)

    assert_200(alice_chrome_client.get_autoshare_bytype_all(record_id=record_id))

    # unshare that one allergy, which should negate the autoshare
    alice_chrome_client.delete_carenet_document(record_id = record_id, document_id = document_2_id, carenet_id=carenet_id)

    # nevershare the third allergy
    alice_chrome_client.document_nevershare_set(record_id = record_id, document_id = document_5_id)

    # immunizations are individually shared (well only one of them)
    alice_chrome_client.post_carenet_document(document_id = document_3_id, carenet_id=carenet_id)
    alice_chrome_client.delete_carenet_document(record_id=record_id, document_id=document_4_id, carenet_id=carenet_id)

    # Alice shares her demographics document(s) with the carenet
    demographics_doc = parse_xml(alice_chrome_client.read_documents(record_id = record_id, parameters={'type':'Demographics'}))
    for doc_id in xpath(demographics_doc, '/Documents/Document/@id'):
      alice_chrome_client.post_carenet_document(record_id = record_id, document_id = doc_id, carenet_id = carenet_id)

    # Alice adds bob_account_id to carenet[0]
    alice_chrome_client.post_carenet_account(carenet_id = carenet_id, data='account_id=' + bob_account_id + '&write=false')

    # Review all accounts within carenet[0]
    assert xpath(parse_xml(alice_chrome_client.get_carenet_accounts(carenet_id = carenet_id)), '/CarenetAccounts')
    alice_chrome_client.get_carenet_apps(carenet_id = carenet_id)

    alice_chrome_client.read_allergies(record_id = record_id)

    # Finally, return the carenet_id, document_id
    # in order to check Bob's access
    # and a second document that is disallowed
    return carenet_id, [document_1_id, document_3_id], [document_2_id, document_4_id, document_5_id]
コード例 #16
0
def main(qfx_file_in, qfx_file_out):
    """Main."""

    # parse xml
    doc, ns = getXmlEtree(qfx_file_in)
    logger.debug("doc: {}".format(pprintXml(doc).decode()))
    logger.debug("ns: {}".format(json.dumps(ns, indent=2)))

    # fix transactions
    for trn in doc.xpath('.//STMTTRN', namespaces=ns):
        logger.info("#" * 80)
        logger.info("trn: {}".format(pprintXml(trn).decode()))
        memo_elt = xpath(trn, 'MEMO', ns)
        memo = memo_elt.text[:32]
        logger.info("memo: {}".format(memo))
        logger.info("type memo: {}".format(type(memo)))

        # extract name
        match = TRN_RE.search(memo)
        if match:
            name = match.group(1)
            logger.info("name: {}".format(name))
            name_elt = SubElement(trn, "NAME")
            name_elt.text = name
            trn.remove(memo_elt)
            logger.info("trn: {}".format(pprintXml(trn).decode()))
            continue

        # monthly interest paid?
        match = INT_RE.search(memo)
        if match:
            name_elt = SubElement(trn, "NAME")
            name_elt.text = "Capital One"
            trn.remove(memo_elt)
            logger.info("trn: {}".format(pprintXml(trn).decode()))
            continue

        # check
        match = CHK_RE.search(memo)
        if match:
            name_elt = SubElement(trn, "NAME")
            name_elt.text = match.group(0)
            trn.remove(memo_elt)
            logger.info("trn: {}".format(pprintXml(trn).decode()))
            continue

        # prenote
        match = PRENOTE_RE.search(memo)
        if match:
            name_elt = SubElement(trn, "NAME")
            name_elt.text = match.group(0)
            trn.remove(memo_elt)
            logger.info("trn: {}".format(pprintXml(trn).decode()))
            continue

        # refund
        match = re.search(r'LMU', memo)
        if match:
            name_elt = SubElement(trn, "NAME")
            name_elt.text = match.group(0)
            trn.remove(memo_elt)
            logger.info("trn: {}".format(pprintXml(trn).decode()))
            continue

        # refund
        match = re.search(r'360 Checking', memo)
        if match:
            name_elt = SubElement(trn, "NAME")
            name_elt.text = match.group(0)
            trn.remove(memo_elt)
            logger.info("trn: {}".format(pprintXml(trn).decode()))
            continue

        # zelle
        match = re.search(r'Zelle money (received from|sent to|returned).*',
                          memo)
        if match:
            name_elt = SubElement(trn, "NAME")
            name_elt.text = match.group(0)
            trn.remove(memo_elt)
            logger.info("trn: {}".format(pprintXml(trn).decode()))
            continue

        # transfer to savings
        match = re.search(r'Withdrawal to', memo)
        if match:
            name_elt = SubElement(trn, "NAME")
            name_elt.text = match.group(0)
            trn.remove(memo_elt)
            logger.info("trn: {}".format(pprintXml(trn).decode()))
            continue

        # checkbook order
        match = re.search(r'Checkbook Order', memo)
        if match:
            name_elt = SubElement(trn, "NAME")
            name_elt.text = match.group(0)
            trn.remove(memo_elt)
            logger.info("trn: {}".format(pprintXml(trn).decode()))
            continue

        # uncaught case
        logger.info("trn: {}".format(pprintXml(trn).decode()))
        raise RuntimeError("Unhandled transaction.")

    # write output file
    v2_message = '<?xml version="1.0" encoding="utf-8"?>\n'
    v2_message += '<?OFX OFXHEADER="200" VERSION="202" SECURITY="NONE" OLDFILEUID="NONE" NEWFILEUID="NONE"?>\n'
    v2_message += pprintXml(doc).decode()
    parser = OFXTree()
    parser.parse(BytesIO(v2_message.encode()))
    ofx = parser.convert()
    client = OFXClient(None)
    v1_message = client.serialize(ofx,
                                  version=102,
                                  prettyprint=True,
                                  close_elements=False).decode()
    with open(qfx_file_out, 'w') as f:
        f.write(v1_message)
コード例 #17
0
ファイル: document.py プロジェクト: gabalese/lepub
 def title(self):
     return xpath(self.__tree, ".//title/text()")