How to use url_should_be method in lettuce_webdriver

Best Python code snippet using lettuce_webdriver_python

test_agent.py

Source:test_agent.py Github

copy

Full Screen

1import pytest2from hydra_agent.agent import Agent3from hydra_agent.helpers import expand_template4from urllib.parse import urlparse5@pytest.mark.usefixtures("setup_agent_for_tests")6class TestAgent:7 """TestCase for Agent Class"""8 @pytest.fixture(autouse=True)9 def init_agent(self, constants):10 """Setting up Agent object"""11 def init_agent_():12 try:13 print(constants["ENTRYPOINT_URL"])14 self.agent = Agent(constants["ENTRYPOINT_URL"])15 except (SyntaxError, ConnectionResetError) as e:16 init_agent_()17 init_agent_()18 def test_get_url(self, get_session_mock, portfolio_object):19 """Tests get method from the Agent with URL"""20 get_session_mock.return_value.status_code = 20021 get_session_mock.return_value.json.return_value = portfolio_object22 response = self.agent.get(self.entrypoint_url + "/Borrower/1")23 assert response == portfolio_object24 def test_get_class_properties(self, get_session_mock, portfolio_object):25 """Tests get method from the Agent by class name and properties"""26 get_session_mock.return_value.status_code = 20027 get_session_mock.return_value.json.return_value = portfolio_object28 response_url = self.agent.get(self.entrypoint_url + "/Portfolio/1")29 response_cached = self.agent.get(30 resource_type="Portfolio",31 filters={"has_cutoff_date": "2020-03-20T14:28:23.382748"},32 cached_limit=1,33 )34 response_cached = response_cached[0]35 assert response_url == response_cached36 response_not_cached = self.agent.get(self.entrypoint_url + "/Portfolio/1")37 assert response_not_cached == response_cached38 def test_get_collection(39 self, get_session_mock, put_session_mock, borrower_object, simplified_collection40 ):41 """Tests get method from the Agent when fetching collections"""42 collection_url = self.entrypoint_url + "/Borrower_collection/"43 new_collection_url = collection_url + "1"44 put_session_mock.return_value.status_code = 20145 put_session_mock.return_value.json.return_value = borrower_object46 put_session_mock.return_value.headers = {"Location": new_collection_url}47 get_session_mock.return_value.json.return_value = simplified_collection48 get_session_mock.return_value.status_code = 20049 response, new_object_url = self.agent.put(collection_url, borrower_object)50 get_collection_url = self.agent.get(collection_url)51 assert type(get_collection_url) == dict52 # get_collection_cached = self.agent.get(resource_type="Borrower",53 # cached_limit=0)54 # self.assertEqual(get_collection_cached[-1]["@id"],55 # get_collection_url['members'][-1]["@id"])56 def test_put(57 self,58 mocker,59 get_session_mock,60 put_session_mock,61 new_object,62 portfolio_object,63 borrower_res,64 ):65 """Tests put method from the Agent"""66 class_url = self.entrypoint_url + "/Borrower/"67 new_object_url = class_url + "1"68 put_session_mock.return_value.status_code = 20169 put_session_mock.return_value.json.return_value = new_object70 put_session_mock.return_value.headers = {"Location": new_object_url}71 fake_responses = [mocker.Mock(), mocker.Mock(), mocker.Mock(), mocker.Mock()]72 fake_responses[0].json.return_value = borrower_res73 fake_responses[0].status_code = 20074 fake_responses[1].json.return_value = borrower_res75 fake_responses[1].status_code = 20076 fake_responses[2].json.return_value = borrower_res77 fake_responses[2].status_code = 20078 fake_responses[3].json.return_value = portfolio_object79 fake_responses[3].status_code = 20080 # Mocking an object to be used for a property that has an embedded link81 get_session_mock.return_value.status_code = 20082 get_session_mock.side_effect = fake_responses83 response, new_object_url = self.agent.put(new_object_url, new_object)84 # Assert if object was inserted queried and inserted successfully85 get_new_object_url = self.agent.get(new_object_url)86 assert get_new_object_url == borrower_res87 get_new_object_type = self.agent.get(88 new_object_url, filters={"has_cutoff_date": "2020-03-20T14:28:23.382748"}89 )90 assert get_new_object_url == get_new_object_type91 def test_post(92 self,93 put_session_mock,94 post_session_mock,95 get_session_mock,96 new_object,97 portfolio_object,98 borrower_res,99 mocker,100 ):101 """Tests post method from the Agent"""102 class_url = self.entrypoint_url + "/Borrower/"103 new_object_url = class_url + "2"104 put_session_mock.return_value.status_code = 201105 put_session_mock.return_value.json.return_value = new_object106 put_session_mock.return_value.headers = {"Location": new_object_url}107 fake_responses = [mocker.Mock(), mocker.Mock()]108 fake_responses[0].json.return_value = borrower_res109 fake_responses[0].status_code = 200110 fake_responses[1].json.return_value = portfolio_object111 fake_responses[1].status_code = 200112 # Mocking an object to be used for a property that has an embedded link113 get_session_mock.return_value.status_code = 200114 get_session_mock.side_effect = fake_responses115 response, new_object_url = self.agent.put(new_object_url, new_object)116 post_session_mock.return_value.status_code = 200117 post_session_mock.return_value.json.return_value = {"msg": "success"}118 new_object["borrower_is_part_of_portfolio"][119 "@id"120 ] = f"/{self.entrypoint_url}/Portfolio/1"121 new_object["has_cutoff_date"] = "2022-06-20T14:28:23.382748"122 # Mocking an object to be used for a property that has an embedded link123 response = self.agent.post(new_object_url, new_object)124 # Assert if object was updated successfully as intended125 fake_responses[1].json.return_value = new_object126 fake_responses[1].status_code = 200127 get_new_object = self.agent.get(new_object_url)128 assert get_new_object == new_object129 def test_delete(130 self,131 put_session_mock,132 delete_session_mock,133 get_session_mock,134 mocker,135 new_object,136 borrower_res,137 ):138 """Tests post method from the Agent"""139 class_url = self.entrypoint_url + "/Borrower/"140 new_object_url = class_url + "3"141 put_session_mock.return_value.status_code = 201142 put_session_mock.return_value.json.return_value = new_object143 put_session_mock.return_value.headers = {"Location": new_object_url}144 fake_responses = [mocker.Mock(), mocker.Mock()]145 fake_responses[0].json.return_value = borrower_res146 fake_responses[0].status_code = 200147 fake_responses[1].text = {"msg": "resource doesn't exist"}148 # Mocking an object to be used for a property that has an embedded link149 get_session_mock.return_value.status_code = 200150 get_session_mock.side_effect = fake_responses151 response, new_object_url = self.agent.put(new_object_url, new_object)152 delete_session_mock.return_value.status_code = 200153 delete_session_mock.return_value.json.return_value = {"msg": "success"}154 response = self.agent.delete(new_object_url)155 get_new_object = self.agent.get(new_object_url)156 # Assert if nothing different was returned by Redis157 assert get_new_object == {"msg": "resource doesn't exist"}158 def test_basic_iri_templates(self, simplified_collection):159 """Tests the URI constructed on the basis of Basic Representation"""160 sample_mapping_object = {161 "borrower_is_part_of_portfolio[has_cutoff_date]": "2020-03-20T14:28:23.382748",162 "pageIndex": "1",163 "limit": "10",164 "offset": "1",165 }166 url = urlparse(167 expand_template(168 "http://localhost:8080/serverapi/BorrowerCollection",169 simplified_collection,170 sample_mapping_object,171 )172 )173 url_should_be = urlparse(174 "http://localhost:8080/creditrisk_api/Borrower_collection?borrower_is_part_of_portfolio%5Bhas_cutoff_date%5D=2020-03-20T14%3A28%3A23.382748&pageIndex=1&limit=10&offset=1"175 )176 assert sorted(url.query) == sorted(url_should_be.query)177 def test_explicit_iri_templates(self, simplified_collection):178 """Tests the URI constructed on the basis of Basic Representation"""179 simplified_collection["search"][180 "hydra:variableRepresentation"181 ] = "hydra:ExplicitRepresentation"182 sample_mapping_object = {183 "url_demo": {"@id": "http://www.hydra-cg.com/"},184 "prop_with_language": {"@language": "en", "@value": "A simple string"},185 "prop_with_type": {186 "@value": "5.5",187 "@type": "http://www.w3.org/2001/XMLSchema#decimal",188 },189 "str_prop": "A simple string",190 }191 url = urlparse(192 expand_template(193 "http://localhost:8080/creditrisk_api/Borrower_collection",194 simplified_collection,195 sample_mapping_object,196 )197 )198 url_should_be = urlparse(199 "http://localhost:8080/credirisk_api/Borrower_collection?url_demo=http%3A%2F%2Fwww.hydra-cg.com%2F&prop_with_language=%22A%20simple%20string%22%40en&prop_with_type=%225.5%22%5E%5Ehttp%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema%23decimal&str_prop=%22A%20simple%20string%22"200 )...

Full Screen

Full Screen

test_bot_model.py

Source:test_bot_model.py Github

copy

Full Screen

1import pytest2from django.conf import settings3from telegram_error_notifications.models import TelegramBot4@pytest.fixture5def telegram_bot():6 bot = TelegramBot.objects.create(name='Test Bot', chat_id=540784105)7 return bot8@pytest.fixture9def get_message():10 return 'Message for testing of generation URL.'11@pytest.mark.django_db12def test_generating_of_sending_message_url(telegram_bot, get_message):13 url = telegram_bot.generate_send_message_url(message=get_message)14 base_url = 'https://api.telegram.org/bot{}/'.format(15 settings.TELEGRAM_BOT_TOKEN)16 send_message_part = 'sendmessage?chat_id={0}&text={1}&parse_mode=html'.\17 format(telegram_bot.chat_id, get_message)18 url_should_be = '{0}{1}'.format(base_url, send_message_part)19 assert url_should_be == url20@pytest.mark.django_db21def test_bot_attributes(telegram_bot):22 assert telegram_bot.name == 'Test Bot'23 assert telegram_bot.chat_id == 54078410524@pytest.mark.django_db25def test_setting_bot_attributes(telegram_bot):26 telegram_bot.name = 'Test Bot 1'27 telegram_bot.chat_id = 54078410628 telegram_bot.save()29 assert telegram_bot.name == 'Test Bot 1'...

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