def idservice_api_login(username=None, password=None, url=None): """Login to ID service, return auth token and user info; prompt if necessary @param username: str @param password: str @param url: str @returns: idservice.IDServiceClient """ if username: logging.debug('Username: %s' % username) elif os.environ.get(IDSERVICE_ENVIRONMENT_USERNAME): username = os.environ.get(IDSERVICE_ENVIRONMENT_USERNAME) else: username = raw_input('Username: '******''.join(['*' for n in password]) logging.debug('Password: %s' % redacted) elif os.environ.get(IDSERVICE_ENVIRONMENT_PASSWORD): password = os.environ.get(IDSERVICE_ENVIRONMENT_PASSWORD) redacted = ''.join(['*' for n in password]) logging.debug('Password: %s' % redacted) else: password = getpass.getpass(prompt='Password: '******'Login failed[1]: %s %s' % (status1, reason1)) sys.exit(1) return ic
def _idservice_login(username, password): ic = idservice.IDServiceClient() http_status, reason = ic.login(username, password) if http_status != 200: click.echo('Login error: %s %s' % (http_status, reason)) sys.exit(1) return ic
def test_login(): ic = idservice.IDServiceClient() print(config.IDSERVICE_USERNAME) print(config.IDSERVICE_PASSWORD) code, status = ic.login(config.IDSERVICE_USERNAME, config.IDSERVICE_PASSWORD) print(code, status) assert code == 200 assert status == 'OK'
def test_detail(): ic = idservice.IDServiceClient() code, status = ic.login(config.IDSERVICE_USERNAME, config.IDSERVICE_PASSWORD) assert code == 200 print(code, status) url = mkurl('objectids/ddr-testing-1/') print(url) r = requests.get(url) print(r.status_code, r.reason) assert r.status_code == 200
def test_next_entity(): """Test if app can get or post next entity """ ic = idservice.IDServiceClient() code, status = ic.login(config.IDSERVICE_USERNAME, config.IDSERVICE_PASSWORD) assert code == 200 url = mkurl('objectids/ddr-testing-1/next/entity/') print(url) r = requests.get(url) assert r.status_code == 200 print(r.status_code) print(r.text) data = r.json() assert isinstance(data, dict) assert data['group'] == 'testing' assert data['model'] == 'entity' assert 'ddr-testing-1-' in data['id']
def test_children(): """Test that app returns list of children """ ic = idservice.IDServiceClient() code, status = ic.login(config.IDSERVICE_USERNAME, config.IDSERVICE_PASSWORD) assert code == 200 url = mkurl('objectids/ddr-testing-1/children/') r = requests.get(url) assert r.status_code == 200 print(r.text) data = r.json() print(data) assert isinstance(data, list) assert len(data) assert data[0]['group'] == 'testing' assert data[0]['model'] in ['entity', 'segment'] assert 'ddr-testing-' in data[0]['id']