Best Python code snippet using localstack_python
hotelbeds_transport.py
Source:hotelbeds_transport.py
...74 return f"{self._get_host()}{hotelbeds_endpoint.value}"75 def _get_headers(self, **kwargs):76 headers = self._get_default_headers()77 headers["Content-Type"] = "application/json"78 headers["Api-Key"] = self._get_apikey()79 headers["X-Signature"] = self._get_xsignature()80 headers["Accept"] = "application/json"81 headers["Accept-Encoding"] = "gzip"82 headers.update(kwargs)83 return headers84 def _get_credentials(self):85 if self.test_mode:86 return {87 "Api-Key": "ba99fa9f7b504eae563b35b294ef2dcc",88 "Secret": "2e4a7d611f",89 }90 return {91 "Api-Key": get_config(Feature.HOTELBEDS_API_KEY),92 "Secret": get_config(Feature.HOTELBEDS_API_SECRET),93 }94 def _get_apikey(self):95 return self._get_credentials()["Api-Key"]96 def _get_secret(self):97 return self._get_credentials()["Secret"]98 def _get_xsignature(self):99 current_time_in_seconds = int(time.time())100 signature_str = f"{self._get_apikey()}{self._get_secret()}{current_time_in_seconds}"101 return hashlib.sha256(signature_str.encode()).hexdigest()102 def _get_host(self):103 if self.test_mode:104 return "https://api.test.hotelbeds.com"105 try:106 return get_config(Feature.HOTELBEDS_API_URL)107 except FeatureNotFoundException:...
login.py
Source:login.py
...20 global_conf = load_shub_config(load_local=False, load_env=False)21 if 'default' in global_conf.apikeys:22 raise AlreadyLoggedInException23 conf = load_shub_config()24 key = _get_apikey(25 suggestion=conf.apikeys.get('default'),26 endpoint=global_conf.endpoints.get('default'),27 )28 with update_yaml_dict(GLOBAL_SCRAPINGHUB_YML_PATH) as conf:29 conf.setdefault('apikeys', {})30 conf['apikeys']['default'] = key31def _get_apikey(suggestion='', endpoint=None):32 suggestion_txt = ' (%s)' % suggestion if suggestion else ''33 click.echo(34 "Enter your API key from https://app.scrapinghub.com/account/apikey"35 )36 while True:37 key = input('API key%s: ' % suggestion_txt) or suggestion38 click.echo("Validating API key...")39 if _is_valid_apikey(key, endpoint=endpoint):40 click.echo("API key is OK, you are logged in now.")41 return key42 else:43 click.echo("API key failed, try again.")44def _is_valid_apikey(key, endpoint=None):45 endpoint = endpoint or ShubConfig.DEFAULT_ENDPOINT...
client.py
Source:client.py
...15 base_path = settings.VRC_BASE_URL16 def __init__(self, username, password):17 self.username = username18 self.password = password19 self.api_key = self._get_apikey()20 self.auth_token = self._get_auth_token()21 def search_users(self, keyword=None, n=10):22 if keyword is None:23 return self.get('users', n=n)24 return self.get('users', search=keyword, n=n)25 def get(self, path, **params):26 queries = parse_params(params)27 path += queries28 url = urljoin(self.base_path, path)29 r = requests.get(30 url,31 params={32 'apiKey': self.api_key,33 'authToken': self.auth_token,34 })35 return r.json()36 def _get_apikey(self):37 url = '{}/config'.format(self.base_path)38 r = requests.get(url)39 return r.json()['clientApiKey']40 def _get_auth_token(self):41 url = '{}/auth/user'.format(self.base_path)42 r = requests.get(43 url,44 params={'apiKey': self.api_key},45 auth=HTTPBasicAuth(self.username, self.password))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!