How to use _wait_for_validation method in tempest

Best Python code snippet using tempest_python

link_checker.py

Source:link_checker.py Github

copy

Full Screen

...118 if not urlparse(url).scheme:119 normalized_links[i] = urljoin("http://", "//" + url)120 return normalized_links121 @staticmethod122 def _wait_for_validation(url):123 """Return the status of a url as dict {`url`, `status`, `reason`}"""124 host, path = urlsplit(url)[1:3]125 connection = httplib.HTTPConnection(host)126 status, reason = None, None127 try:128 connection.request("HEAD", path) 129 except gaierror: # bad host130 pass131 else: 132 response = connection.getresponse() # wait for response133 status, reason = response.status, response.reason134 return {'url': url, 'status': status, 'reason': reason}135 @staticmethod136 def _check_links_threaded(url_list, timeout):137 """Employeer which starts worker threads to check urls."""138 url_queue = Queue()139 result_hash = {} 140 map(url_queue.put_nowait, url_list)141 num_urls = len(url_list)142 timer = _WorkerTimer(num_urls, timeout)143 num_threads = max(min(NUM_WORKER_THREADS, num_urls), 1)144 for _ in xrange(num_threads):145 LinkChecker._start_link_worker(url_queue, result_hash, timer)146 timer.start_workers_and_wait()147 for url in set(url_list).difference(result_hash.keys()):148 # if the url timedout then give None for `status` and `reason`149 result_hash[url] = result_hash.get(url, {'url': url, 150 'status': None,151 'reason':None })152 return result_hash 153 @staticmethod154 def _start_link_worker(url_queue, result_hash, timer):155 """Worker thread which does work on elements of `url_queue` and places156 results on `done_queue` using `timer` for synchronization and timing."""157 def hard_worker():158 """Contionusly waits for work and performs work if available and159 time left."""160 timer.worker_wait()161 while True:162 try:163 url = url_queue.get_nowait()164 except EmptyQueue: 165 break 166 ret_val = LinkChecker._wait_for_validation(url)167 if not timer.work_has_finished(): 168 timer.worker_task_done()169 result_hash[ret_val['url']] = ret_val170 else: 171 break172 thread = Thread(target=hard_worker)173 thread.setDaemon(True)174 thread.start()175if __name__ == '__main__':176 from time import time as now177 lc = LinkChecker()178 # short list179 url_list = ["http://thinkgeek.com", "http://sonothere.com", "http://gmail.com"]180 print "testing list of length %s" % len(url_list)...

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 tempest 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