How to use get_egg_url method in avocado

Best Python code snippet using avocado_python

dragcave.py

Source:dragcave.py Github

copy

Full Screen

1import requests2from bs4 import BeautifulSoup as soup3from dragcavebot.dragons import dragons_description_to_name4class DragCave:5 base_url = "https://dragcave.net"6 COAST = f"{base_url}/locations/1"7 DESERT = f"{base_url}/locations/2"8 FOREST = f"{base_url}/locations/3"9 JUNGLE = f"{base_url}/locations/4"10 ALPINE = f"{base_url}/locations/5"11 VOLCANO = f"{base_url}/locations/6"12 LOCATIONS = (COAST, DESERT, FOREST, JUNGLE, ALPINE, VOLCANO)13 WANTED_EGGS = {}14 def set_wanted_eggs(self, eggs):15 self.WANTED_EGGS = {**eggs}16 def login(self, user, password):17 login_url = f"{self.base_url}/login"18 login_res = requests.post(19 login_url,20 data={21 "username": user,22 "password": password23 },24 timeout=525 )26 login_page = soup(login_res.content, 'lxml')27 if login_page.find_all(string=user):28 login_post_res = login_res.history[0]29 self.cookies = login_post_res.cookies30 return True31 return False32 def logout(self):33 print("Logging out")34 # Temp logout35 res = requests.get(36 f"{self.base_url}/logout",37 cookies=self.cookies,38 )39 # request = requests.Request(40 # "POST",41 # f"{self.base_url}/account/sessions",42 # files={43 # "logout": self.cookies["s"]44 # },45 # cookies=self.cookies,46 # headers={47 # "Content-Type": "application/x-www-form-urlencoded"48 # }49 # ).prepare()50 # session = requests.Session()51 # res = session.send(request)52 # res = requests.post(53 # f"{self.base_url}/account/sessions",54 # files=dict(logout=self.cookies["s"]),55 # cookies=self.cookies,56 # headers={57 # "Content-Type": "application/x-www-form-urlencoded"58 # }59 # )60 # print(res.content)61 # print(res.status_code)62 print("Logged out")63 def get_available_eggs(self, location):64 eggs = []65 try:66 res = requests.get(67 location,68 cookies=self.cookies,69 timeout=370 )71 page = soup(res.content, "lxml")72 egg_section = page.find("div", {"class": "eggs"})73 for egg in egg_section.children:74 egg_link = egg.a["href"]75 egg_description = egg.text76 name = dragons_description_to_name.get(egg_description, None)77 if self.WANTED_EGGS.get(name, None):78 egg_result = self.get_egg(egg_link)79 eggs.append((name, egg_result))80 except requests.exceptions.ReadTimeout as e:81 print(e)82 except Exception as e:83 print(e)84 return eggs85 def get_egg(self, egg_link):86 get_egg_url = f"{self.base_url}{egg_link}"87 print(get_egg_url)88 try:89 res = requests.post(90 get_egg_url,91 cookies=self.cookies,92 )93 egg_result = self.get_egg_result(soup(res.content, "lxml"))94 return egg_result95 except requests.exceptions.ReadTimeout as e:96 print(e)97 return "Error"98 def get_egg_result(self, content):99 try:100 is_overburdened = content.find_all(string="You are already overburdened and decide not to stress yourself by taking this egg")101 is_late = content.find_all(string="Sorry, this egg has already been taken by somebody else.")102 if is_overburdened:103 return is_overburdened[0]104 if is_late:105 return is_late[0]106 return "Collected"107 except Exception as e:108 print(e)...

Full Screen

Full Screen

test_fetch.py

Source:test_fetch.py Github

copy

Full Screen

1from insights.client import InsightsClient2from insights.client.config import InsightsConfig3from insights.client.constants import InsightsConstants as constants4from mock.mock import Mock, patch5from pytest import fixture6from tempfile import NamedTemporaryFile7@fixture8def insights_client():9 config = InsightsConfig(http_timeout=123)10 client = InsightsClient(config)11 client.session = Mock(**{"get.return_value.headers.items.return_value": []})12 client.connection = Mock(base_url="http://www.example.com/")13 return client14def test_request_with_etag(insights_client):15 """16 An egg fetch request with Etag is issued with correct timeout set.17 """18 etag_file = NamedTemporaryFile('w+t')19 etag_value = 'some_etag'20 etag_file.write(etag_value)21 etag_file.seek(0)22 source_path = 'some-source-path'23 insights_client._fetch(source_path, etag_file.name, "", force=False)24 url = "{0}{1}".format(insights_client.connection.base_url, source_path)25 headers = {'If-None-Match': etag_value}26 timeout = insights_client.config.http_timeout27 insights_client.session.get.assert_called_once_with(url, headers=headers, timeout=timeout)28def test_request_forced(insights_client):29 """30 A forced egg fetch request is issued with correct timeout set.31 """32 source_path = 'some-source-path'33 insights_client._fetch(source_path, "", "", force=False)34 url = "{0}{1}".format(insights_client.connection.base_url, source_path)35 timeout = insights_client.config.http_timeout36 insights_client.session.get.assert_called_once_with(url, timeout=timeout)37@patch('insights.client.InsightsClient._fetch', Mock())38@patch('insights.client.os.path', Mock())39@patch('insights.client.tempfile', Mock())40@patch('insights.client.InsightsClient.get_egg_url', return_value='/testvalue')41@patch('insights.client.write_to_disk')42def test_egg_release_written(write_to_disk, get_egg_url, insights_client):43 '''44 Verify egg release file successfully written after request45 '''46 insights_client.fetch(force=False)47 write_to_disk.assert_called_once_with(constants.egg_release_file, content='/testvalue')48@patch('insights.client.InsightsClient._fetch')49@patch('insights.client.os.path', Mock())50@patch('insights.client.tempfile', Mock())51@patch('insights.client.InsightsClient.get_egg_url', return_value='/testvalue')52@patch('insights.client.write_to_disk')53def test_egg_release_error(write_to_disk, get_egg_url, _fetch, insights_client):54 '''55 Verify OSError and IOError are caught and process continues on56 '''57 write_to_disk.side_effect = OSError('test')58 assert insights_client.fetch(force=False)59 write_to_disk.assert_called_once_with(constants.egg_release_file, content='/testvalue')60 assert _fetch.call_count == 261 write_to_disk.side_effect = None62 write_to_disk.reset_mock()63 _fetch.reset_mock()64 write_to_disk.side_effect = IOError('test')65 assert insights_client.fetch(force=False)66 write_to_disk.assert_called_once_with(constants.egg_release_file, content='/testvalue')...

Full Screen

Full Screen

avocado-fetch-eggs.py

Source:avocado-fetch-eggs.py Github

copy

Full Screen

...25 logger_handler = logging.StreamHandler()26 LOG.addHandler(logger_handler)27 formatter = logging.Formatter("%(levelname)s: %(message)s")28 logger_handler.setFormatter(formatter)29def get_egg_url(avocado_version=None, python_version=None):30 if avocado_version is None:31 avocado_version = VERSION32 if python_version is None:33 version = sys.version_info34 python_version = f"{version.major}.{version.minor}"35 asset = f"avocado_framework-{avocado_version}-py{python_version}.egg"36 return f"https://github.com/avocado-framework/avocado/releases/download/{avocado_version}/{asset}"37def main():38 configure_logging_settings()39 for version in ["3.6", "3.7", "3.8", "3.9", "3.10"]:40 url = get_egg_url(python_version=version)41 asset = Asset(url, cache_dirs=CACHE_DIRS)42 asset.fetch()43 return True44if __name__ == "__main__":...

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