def get_billable_organisation(user, role_code=models.Role.BILLING_ROLE_CODE): """Retrieve the organisation for which the given user is a "billing" user: this organisation is subsequently this users' 'billable organisation' Raises ValueError in case of """ synced = False while True: # Repeat so we can sync one time if things go wrong try: return models.get_organisation_with_role(user, role_code) except (models.Organisation.DoesNotExist, models.Organisation.MultipleObjectsReturned): if synced: # We have already synced and it still goes wrong: raise ValueError( "Configuration error, can't find single " "billable organisation") else: sso_sync_user_organisation_roles(user) synced = True
def test_call_get_organisation_with_role(self): org = models.get_organisation_with_role(self.user, 'billing') self.assertEquals(org.name, 'Nelen & Schuurmans')