def get_xero_tenant_id(): token = obtain_xero_oauth2_token() if not token: return None identity_api = IdentityApi(api_client) for connection in identity_api.get_connections(): if connection.tenant_type == "ORGANISATION": return connection.tenant_id
def tenants(): identity_api = IdentityApi(api_client) accounting_api = AccountingApi(api_client) available_tenants = [] for connection in identity_api.get_connections(): tenant = serialize(connection) if connection.tenant_type == "ORGANISATION": organisations = accounting_api.get_organisations( xero_tenant_id=connection.tenant_id) tenant["organisations"] = serialize(organisations) available_tenants.append(tenant) return render_template( "code.html", title="Xero Tenants", code=json.dumps(available_tenants, sort_keys=True, indent=4), )
def test_get_connections(identity_api: IdentityApi): """ Test IdentityApi.get_connections() """ # Given correct api client and xero tenant id # When fetching connections response = identity_api.get_connections() # Then expect correct response with list of connections assert isinstance(response, list) assert len(response) == 1 connection = response[0] assert isinstance(connection, models.Connection) assert connection.tenant_id
def identity_api(api_client): return IdentityApi(api_client=api_client)