How to use _build_url method in locust

Best Python code snippet using locust

client.py

Source:client.py Github

copy

Full Screen

...31 # Save the content.32 with open(file=file_path, mode='w+') as data_file:33 json.dump(obj=content, fp=data_file, indent=2)34 return str(file_path)35 def _build_url(self, endpoint: str, arguments: List[str] = None) -> str:36 """Builds a full URL for the API Client.37 Arguments:38 ----39 endpoint (str): The endpoint to be requested.40 arguments (List[str]): Any additional arguments needed to be41 joined with the URL.42 Returns:43 ----44 str: The full `HTTPS` url.45 """46 # If we have arguments we need to join that.47 if arguments:48 full_url = '/'.join(49 [self.api_base_url, endpoint] + arguments50 )51 else:52 full_url = '/'.join(53 [self.api_base_url, endpoint]54 )55 full_url_with_format = full_url56 return full_url_with_format57 def _make_request(self, url: str, method: str, params: dict = None) -> dict:58 """Used to make all the request for the client.59 Arguments:60 ----61 url (str): The url to the specified endpoint.62 method (str): The request method to make.63 params (dict): Parameters to send along in the request.64 Returns:65 ----66 dict: The JSON content parsed.67 """68 # Define the headers.69 headers = {70 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',71 'accept-language': 'en-US,en;q=0.9'72 }73 # Make the request.74 if method == 'get':75 response = requests.get(url=url, headers=headers, verify=True)76 # If it's a good response, send back.77 if response.ok:78 return response.json()79 def data_sources(self) -> List[Dict]:80 """Grabs all the data sources provided.81 Returns:82 ----83 List[Dict]: A list of database resources.84 """85 # Build the URL.86 full_url = self._build_url(endpoint='bulkdata/json')87 # Make the request.88 content = self._make_request(89 url=full_url,90 method='get'91 )92 return content93 def privacy_act_issuances(self, folder: str) -> List[Dict]:94 """Grabs the data resources for the specified folder under the Privacy Act Issuances Resource.95 Arguments:96 ----97 Folder (str): The name of the folder resource to return.98 Returns:99 ----100 List[Dict]: A list of file resources.101 """102 # Build the URL.103 full_url = self._build_url(104 endpoint='bulkdata/json/PAI/{folder}'.format(folder=folder)105 )106 # Make the request.107 content = self._make_request(108 url=full_url,109 method='get'110 )111 return content112 def code_of_federal_regulations(self, folder: str) -> List[Dict]:113 """Grabs the data resources for the specified folder under the Code of Federal Regulations Resource.114 Arguments:115 ----116 folder (str): The name of the folder resource to return.117 Returns:118 ----119 List[Dict]: A list of file resources.120 """121 # Build the URL.122 full_url = self._build_url(123 endpoint='bulkdata/json/CFR/{folder}'.format(folder=folder)124 )125 # Make the request.126 content = self._make_request(127 url=full_url,128 method='get'129 )130 return content131 def federal_register(self, folder: str) -> List[Dict]:132 """Grabs the data resources for the specified folder under the Federal Register Resource.133 Arguments:134 ----135 folder (str): The name of the folder resource to return.136 Returns:137 ----138 List[Dict]: A list of file resources.139 """140 # Build the URL.141 full_url = self._build_url(142 endpoint='bulkdata/json/FR/{folder}'.format(folder=folder)143 )144 # Make the request.145 content = self._make_request(146 url=full_url,147 method='get'148 )149 return content150 def bill_status(self, folder: str) -> List[Dict]:151 """Grabs the data resources for the specified folder under the Bill Status Resource.152 Arguments:153 ----154 folder (str): The name of the folder resource to return.155 Returns:156 ----157 List[Dict]: A list of file resources.158 """159 # Build the URL.160 full_url = self._build_url(161 endpoint='bulkdata/json/BILLSTATUS/{folder}'.format(folder=folder)162 )163 # Make the request.164 content = self._make_request(165 url=full_url,166 method='get'167 )168 return content169 def commerce_business_daily(self, folder: str) -> List[Dict]:170 """Grabs the data resources for the specified folder under the Commerce Business Daily Resource.171 Arguments:172 ----173 folder (str): The name of the folder resource to return.174 Returns:175 ----176 List[Dict]: A list of file resources.177 """178 # Build the URL.179 full_url = self._build_url(180 endpoint='bulkdata/json/CBD/{folder}'.format(folder=folder)181 )182 # Make the request.183 content = self._make_request(184 url=full_url,185 method='get'186 )187 return content188 def public_papers_president(self, folder: str) -> List[Dict]:189 """Grabs the data resources for the specified folder under the Public Papers of the Presidents of the United States Resource.190 Arguments:191 ----192 folder (str): The name of the folder resource to return.193 Returns:194 ----195 List[Dict]: A list of file resources.196 """197 # Build the URL.198 full_url = self._build_url(199 endpoint='bulkdata/json/PPP/{folder}'.format(folder=folder)200 )201 # Make the request.202 content = self._make_request(203 url=full_url,204 method='get'205 )206 return content207 def supreme_court_decisions(self, folder: str) -> List[Dict]:208 """Grabs the data resources for the specified folder under the Supreme Court Decisions 1937-1975 (FLITE) Resource.209 Arguments:210 ----211 folder (str): The name of the folder resource to return.212 Returns:213 ----214 List[Dict]: A list of file resources.215 """216 # Build the URL.217 full_url = self._build_url(218 endpoint='bulkdata/json/SCD/{folder}'.format(folder=folder)219 )220 # Make the request.221 content = self._make_request(222 url=full_url,223 method='get'224 )225 return content226 def congressional_bills(self, folder: str) -> List[Dict]:227 """Grabs the data resources for the specified folder under the Congressional Bills Resource.228 Arguments:229 ----230 folder (str): The name of the folder resource to return.231 Returns:232 ----233 List[Dict]: A list of file resources.234 """235 # Build the URL.236 full_url = self._build_url(237 endpoint='bulkdata/json/BILLS/{folder}'.format(folder=folder)238 )239 # Make the request.240 content = self._make_request(241 url=full_url,242 method='get'243 )244 return content245 def us_government_manuals(self, folder: str) -> List[Dict]:246 """Grabs the data resources for the specified folder under the United States Government Manual Resource.247 Arguments:248 ----249 folder (str): The name of the folder resource to return.250 Returns:251 ----252 List[Dict]: A list of file resources.253 """254 # Build the URL.255 full_url = self._build_url(256 endpoint='bulkdata/json/GOVMAN/{folder}'.format(folder=folder)257 )258 # Make the request.259 content = self._make_request(260 url=full_url,261 method='get'262 )263 return content264 def bill_summaries(self, folder: str) -> List[Dict]:265 """Grabs the data resources for the specified folder under the Bill Summaries Resource.266 Arguments:267 ----268 folder (str): The name of the folder resource to return.269 Returns:270 ----271 List[Dict]: A list of file resources.272 """273 # Build the URL.274 full_url = self._build_url(275 endpoint='bulkdata/json/BILLSUM/{folder}'.format(folder=folder)276 )277 # Make the request.278 content = self._make_request(279 url=full_url,280 method='get'281 )282 return content283 def electronic_code_of_federal_regulation(self, folder: str) -> List[Dict]:284 """Grabs the data resources for the specified folder under the Electronic Code of Federal Regulations Resource.285 Arguments:286 ----287 folder (str): The name of the folder resource to return.288 Returns:289 ----290 List[Dict]: A list of file resources.291 """292 # Build the URL.293 full_url = self._build_url(294 endpoint='bulkdata/json/ECFR/{folder}'.format(folder=folder)295 )296 # Make the request.297 content = self._make_request(298 url=full_url,299 method='get'300 )301 return content302 def house_rules_and_manual(self, folder: str) -> List[Dict]:303 """Grabs the data resources for the specified folder under the House Rules and Manual Resource.304 Arguments:305 ----306 folder (str): The name of the folder resource to return.307 Returns:308 ----309 List[Dict]: A list of file resources.310 """311 # Build the URL.312 full_url = self._build_url(313 endpoint='bulkdata/json/HMAN/{folder}'.format(folder=folder)314 )315 # Make the request.316 content = self._make_request(317 url=full_url,318 method='get'319 )320 return content321 def private_and_public_laws(self, folder: str) -> List[Dict]:322 """Grabs the data resources for the specified folder under the Public and Private Laws (xml uslm beta) Resource.323 Arguments:324 ----325 folder (str): The name of the folder resource to return.326 Returns:327 ----328 List[Dict]: A list of file resources.329 """330 # Build the URL.331 full_url = self._build_url(332 endpoint='bulkdata/json/PLAW/{folder}'.format(folder=folder)333 )334 # Make the request.335 content = self._make_request(336 url=full_url,337 method='get'338 )339 return content340 def statutes_at_large(self, folder: str) -> List[Dict]:341 """Grabs the data resources for the specified folder under the Statutes at Large (xml uslm beta) Resource.342 Arguments:343 ----344 folder (str): The name of the folder resource to return.345 Returns:346 ----347 List[Dict]: A list of file resources.348 """349 # Build the URL.350 full_url = self._build_url(351 endpoint='bulkdata/json/STATUTE/{folder}'.format(folder=folder)352 )353 # Make the request.354 content = self._make_request(355 url=full_url,356 method='get'357 )...

Full Screen

Full Screen

bittrex_client.py

Source:bittrex_client.py Github

copy

Full Screen

...14 return self.api_version15 def _get_nonce(self):16 """Authenticated requests all require a nonce."""17 return str(round(time.time()))18 def _build_url(self, endpoint):19 """Helper function to build the full URL."""20 return self.api_base + endpoint21 def _call(self, url, params=None):22 """Call the API """23 if not params:24 # for authenticated requests with no parameters25 params = {}26 # figure out if we need to authenticate or not27 if 'public' in url:28 auth = None29 else:30 auth = BittrexAuth(self.api_secret)31 params['apikey'] = self.api_key32 params['nonce'] = self._get_nonce()33 return self.session.get(url, params=params, auth=auth)34 # Public API35 # ----------36 def get_markets(self):37 """Used to get the open and available trading markets at Bittrex along with other metadata."""38 url = self._build_url('/public/getmarkets')39 return self._call(url)40 def get_currencies(self):41 """Used to get all supported currencies at Bittrex along with other metadata."""42 url = self._build_url('/public/getcurrencies')43 return self._call(url)44 def get_ticker(self, market, *args, **kwargs):45 """Used to get the current tick values for a market."""46 url = self._build_url('/public/getticker')47 payload = {'market': market}48 return self._call(url, params=payload)49 def get_market_summaries(self):50 """Used to get the last 24 hour summary of all active exchanges."""51 url = self._build_url('/public/getmarketsummaries')52 return self._call(url)53 def get_market_summary(self, market, *args, **kwargs):54 """Used to get the last 24 hour summary of all active exchanges."""55 url = self._build_url('/public/getmarketsummary')56 payload = {'market': market}57 return self._call(url, params=payload)58 def get_orderbook(self, market, type, *args, **kwargs):59 """Used to get retrieve the orderbook for a given market."""60 url = self._build_url('/public/getorderbook')61 payload = {'market': market, 'type': type}62 return self._call(url, params=payload)63 def get_market_history(self, market, *args, **kwargs):64 """Used to retrieve the latest trades that have occured for a specific market."""65 url = self._build_url('/public/getmarkethistory')66 payload = {'market': market}67 return self._call(url, params=payload)68 # Market API69 # ----------70 def buy_limit(self, market, qty, price, *args, **kwargs):71 """Used to place a buy order in a specific market. Use buylimit to place limit orders. Make sure you have the proper permissions set on your API keys for this call to work."""72 url = self._build_url('/market/buylimit')73 payload = {'market': market, 'quantity': qty, 'rate': price}74 return self._call(url, params=payload)75 def sell_limit(self, market, qty, price, *args, **kwargs):76 """Used to place an sell order in a specific market. Use selllimit to place limit orders. Make sure you have the proper permissions set on your API keys for this call to work."""77 url = self._build_url('/market/selllimit')78 payload = {'market': market, 'quantity': qty, 'rate': price}79 return self._call(url, params=payload)80 def market_cancel(self, uuid, *args, **kwargs):81 """Used to cancel a buy or sell order."""82 url = self._build_url('/market/cancel')83 payload = {'uuid': uuid}84 return self._call(url, params=payload)85 def get_open_orders(self, market=None, *args, **kwargs):86 """Get all orders that you currently have opened. A specific market can be requested."""87 url = self._build_url('/market/getopenorders')88 payload = {'market': market} if market else ''89 return self._call(url, params=payload)90 # Account API91 # -----------92 def get_balances(self, *args, **kwargs):93 """Used to retrieve balances from your account."""94 url = self._build_url('/account/getbalances')95 return self._call(url, params=payload)96 def get_balance(self, currency, *args, **kwargs):97 """Used to retrieve the balance from your account for a specific currency."""98 url = self._build_url('/account/getbalance')99 payload = {'currency': currency}100 return self._call(url, params=payload)101 def get_deposit_address(self, currency, *args, **kwargs):102 """Used to retrieve or generate an address for a specific currency. If one does not exist, the call will fail and return ADDRESS_GENERATING until one is available."""103 url = self._build_url('/account/getdepositaddress')104 payload = {'currency': currency}105 return self._call(url, params=payload)106 def withdraw(self, currency, qty, address, memo=None, *args, **kwargs):107 """Used to withdraw funds from your account. note: please account for txfee."""108 url = self._build_url('/account/withdraw')109 payload = {'currency': currency, 'quantity': qty, 'address': address, 'paymentid': memo}110 return self._call(url, params=payload)111 def get_order(self, uuid, *args, **kwargs):112 """Used to retrieve a single order by uuid."""113 url = self._build_url('/account/getorder')114 payload = {'uuid': uuid}115 return self._call(url, params=payload)116 def get_order_history(self, market=None, *args, **kwargs):117 """Used to retrieve your order history."""118 url = self._build_url('/account/getorderhistory')119 payload = {'market': market} if market else None120 return self._call(url, params=payload)121 def get_withdrawal_history(self, currency=None, *args, **kwargs):122 """Used to retrieve your withdrawal history."""123 url = self._build_url('/account/getwithdrawalhistory')124 payload = {'currency': currency} if currency else None125 return self._call(url, params=payload)126 def get_deposit_history(self, currency=None, *args, **kwargs):127 """Used to retrieve your deposit history."""128 url = self._build_url('/account/getdeposithistory')129 payload = {'currency': currency} if currency else None...

Full Screen

Full Screen

stock_series.py

Source:stock_series.py Github

copy

Full Screen

...8 def _build_path(self, function, symbol, **kwargs):9 path = f"function={function}&symbol={symbol}"10 options = [f"{item[0]}={item[1]}" for item in kwargs.items()]11 path = f"{path}&{'&'.join(options)}" if options else path12 def _build_url(self, path):13 return f"{self.base_url}?{path}&apikey={self.api_key}"14 def _make_request(self, url):15 resp = requests.get(url)16 if resp.status_code == 200:17 return resp.json()18 raise APICallError(19 f"Não foi possivel consumir o serviço: STATUS_CODE"20 f"={resp.status_code}"21 )22 def intraday_series(self, function, symbol, interval, **kwargs):23 path = f"function={function}&symbol={symbol}&interval={interval}"24 options = [f"{item[0]}={item[1]}" for item in kwargs.items()]25 path = f"{path}&{'&'.join(options)}" if options else path26 url = self._build_url(path)27 resp = self._make_request(url)28 def daily_series(self, function, symbol, **kwargs):29 path = self._build_path(function, symbol, **kwargs)30 url = self._build_url(path) # gera url31 resp = self._make_request(url) # faz requisição e retorna response.json()32 def daily_adjusted_series(self, function, symbol, **kwargs):33 path = self._build_path(function, symbol, **kwargs)34 url = self._build_url(path)35 resp = self._make_request(url)36 def weekly_series(self, function, symbol, *args, **kwargs):37 path = self._build_path(function, symbol, **kwargs)38 url = self._build_url(path)39 resp = self._make_request(url)40 def weekly_adjusted_series(self, function, symbol, **kwargs):41 path = self._build_path(function, symbol, **kwargs)42 url = self._build_url(path)43 resp = self._make_request(url)44 def monthly_series(self, function, symbol, **kwargs):45 path = self._build_path(function, symbol, **kwargs)46 url = self._build_url(path)47 resp = self._make_request(url)48 def monthly_adjusted_series(self, function, symbol, **kwargs):49 path = self._build_path(function, symbol, **kwargs)50 url = self._build_url(path)51 resp = self._make_request(url)52 def quote_series(self, function, symbol, **kwargs):53 path = self._build_path(function, symbol, **kwargs)54 url = self._build_url(path)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run locust automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful