Пример #1
0
    def test_get_contacts_by_ids(self):
        with patch.object(XeroApiWrapper,
                          'rate_limit_retry_query',
                          return_value=[self.example_api_contact]):
            xero = XeroApiWrapper(**self.example_api_creds)
            contacts = xero.get_contacts_by_ids(
                ['a3e4631c-c02d-461d-a5ec-641c5aaace1f'], limit=1)

        self.assertEqual(len(contacts), 1)
        self.assertEqual(contacts[0].contact_id,
                         'a3e4631c-c02d-461d-a5ec-641c5aaace1f')
Пример #2
0
def get_map_contacts(conf):
    xero = XeroApiWrapper(**dict(conf.XeroApiConfig))
    map_contact_groups = conf.FilterConfig.get("contact_groups", "").split("|")
    PKG_LOGGER.debug("map contact groups: %s", map_contact_groups)
    contact_limit = conf.BaseConfig.contact_limit or None
    PKG_LOGGER.debug("contact limit: %s", contact_limit)
    map_contacts = xero.get_contacts_in_group_names(names=map_contact_groups,
                                                    limit=contact_limit)
    for filter_attr, contact_attr in [
        ("states", "main_address_state"),
        ("countries", "main_address_country"),
    ]:
        bad_contacts = set()

        if filter_attr not in conf.FilterConfig:
            continue
        filter_values = [
            sanitize_filter_term(value)
            for value in getattr(conf.FilterConfig, filter_attr).split("|")
        ]
        filtered_contacts = []
        for contact in map_contacts:
            contact_value = getattr(contact, contact_attr)
            if not contact_value:
                PKG_LOGGER.warn(
                    "Contact has no value for %s filter: %s" %
                    (filter_attr, pprint.pformat(contact.contact_id)))
                bad_contacts.add(contact)
            if sanitize_filter_term(contact_value) in filter_values:
                filtered_contacts.append(contact)
        if not filtered_contacts:
            PKG_LOGGER.error("No contacts matching %s filter" % filter_attr)
        map_contacts = filtered_contacts

        if bad_contacts:
            bad_contact_urls = [
                "https://go.xero.com/Contacts/View/" + contact.contact_id
                for contact in bad_contacts
            ]
            warning = ("The following contacts are missing " + contact_attr +
                       ", please fix! ")
            PKG_LOGGER.warn(warning + repr(bad_contact_urls))
            with open("warnings.txt", "w+") as warnings:
                warnings.write(warning + "\r\n")
                for url in bad_contact_urls:
                    warnings.write(" -> " + url + "\r\n")

    # TODO: validate addresses
    PKG_LOGGER.info(
        "map contacts: \n%s",
        XeroContactGroup.dump_contacts_sanitized_table(map_contacts),
    )
    return map_contacts
Пример #3
0
 def test_get_contact_group_ids_from_names(self):
     with patch.object(XeroApiWrapper,
                       'rate_limit_retry_query',
                       return_value=[{
                           'ContactGroupID':
                           '4f935b4a-9406-41c0-ba45-b36b67c0123e',
                           'Contacts': [self.example_api_contact],
                           'HasValidationErrors': False,
                           'Name': 'ACME Agencies',
                           'Status': 'ACTIVE'
                       }]):
         xero = XeroApiWrapper(**self.example_api_creds)
         ids = xero._get_contact_group_ids_from_names(['ACME Agencies'])
     self.assertEqual(ids, ['4f935b4a-9406-41c0-ba45-b36b67c0123e'])
Пример #4
0
 def test_get_contact_group_ids_from_names(self):
     with patch.object(
             XeroApiWrapper,
             "rate_limit_retry_query",
             return_value=[{
                 "ContactGroupID": "4f935b4a-9406-41c0-ba45-b36b67c0123e",
                 "Contacts": [self.example_api_contact],
                 "HasValidationErrors": False,
                 "Name": "ACME Agencies",
                 "Status": "ACTIVE",
             }],
     ):
         xero = XeroApiWrapper(**self.example_api_creds)
         ids = xero._get_contact_group_ids_from_names(["ACME Agencies"])
     self.assertEqual(ids, ["4f935b4a-9406-41c0-ba45-b36b67c0123e"])
Пример #5
0
    def test_get_contacts_in_group_names(self):
        with patch.object(
                XeroApiWrapper,
                "_get_contact_group_ids_from_names",
                return_value=["4f935b4a-9406-41c0-ba45-b36b67c0123e"],
        ), patch.object(
                XeroApiWrapper,
                "_get_contact_ids_in_group_ids",
                return_value=["a3e4631c-c02d-461d-a5ec-641c5aaace1f"],
        ), patch.object(
                XeroApiWrapper,
                "get_contacts_by_ids",
                return_value=[self.example_api_contact],
        ):
            xero = XeroApiWrapper(**self.example_api_creds)
            contacts = xero.get_contacts_in_group_names(["ACME Agencies"],
                                                        limit=1)

        self.assertEqual(len(contacts), 1)
Пример #6
0
 def test_get_creds_file(self):
     api_creds = self.example_api_creds.copy()
     del api_creds['rsa_key_raw']
     api_creds['rsa_key_path'] = 'tests/sample_data/dummy_rsa_key.pem'
     xero = XeroApiWrapper(**api_creds)
     self.assertTrue(xero)
Пример #7
0
 def test_transport_basic(self):
     xero = XeroApiWrapper(**self.example_api_creds)
     self.assertTrue(xero)