def setUp(self): self.api = iland.Api(client_id='fake', client_secret='fake', username='******', password='******') self.api._base_url = BASE_URL self.api._access_token_url = iland.ACCESS_URL
def test_unauthorized_errors(self): wrongCredsApi = iland.Api(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, username='******', password='******') wrongCredsApi._base_url = iland.constant.BASE_URL with self.assertRaises(UnauthorizedException): wrongCredsApi.login() with self.assertRaises(UnauthorizedException): wrongCredsApi.get_access_token() with self.assertRaises(UnauthorizedException): wrongCredsApi.refresh_access_token()
def test_with_default_base_url(self): self.api = iland.Api(client_id='fake', client_secret='fake', username='******', password='******') with requests_mock.mock() as m: m.post(iland.ACCESS_URL, text=json.dumps(VALID_TOKEN_PAYLOAD), status_code=200) rpath = '/user/jchirac' user_data = {'username': '******'} m.get(iland.BASE_URL + rpath, text=json.dumps(user_data), status_code=200) req = self.api.get(rpath) self.assertEquals(user_data, req)
def __init__(self, client_id, client_secret, username, password): self.username = username self.api = iland.Api(client_id=client_id, client_secret=client_secret, username=username, password=password)
def setUp(self): self._api = iland.Api(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, username=USERNAME, password=PASSWORD) self._api._base_url = iland.constant.BASE_URL
import iland import time CLIENT_ID = '' CLIENT_SECRET = '' USERNAME = '' PASSWORD = '' api = iland.Api(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, username=USERNAME, password=PASSWORD) def main(): vdc_uuid = print_entity_inventory() vapp_uuid = create_scratch_vapp(vdc_uuid) delete_vapp(vapp_uuid) ''' This function gets a user's inventory with the GET endpoint /users/{username}/inventory and filters to get vDCS, vApps and VMs. In this case I am printing all the vDCs the user has access. I also show how to get vApps and VMs but don't print them. Besides printing all the vDCS, this function lazily grabs the a vDC uuid for the scratch vApp that we create below. ''' def print_entity_inventory(): inventory = api.get('/users/%s/inventory' % USERNAME)['inventory'] for item in inventory: vdcs = item['entities']['IAAS_VDC'] vapps = item['entities']['IAAS_VAPP'] vms = item['entities']['IAAS_VM'] for vdc in vdcs: vdc_uuid = vdc['uuid'] print(vdc['name'] + ' ' + vdc['uuid']) return vdc_uuid