Best Python code snippet using locust
test_server.py
Source:test_server.py
...29 # ÐапиÑаÑÑ ÑобÑÑвеннÑй HTTP ÐºÐ»Ð¸ÐµÐ½Ñ Ñ Ð¸ÑполÑзованием библиоÑеки socket30 # оÑпÑавлÑÑÑ POST запÑоÑÑ31 req = requests.post(APP_URL)32 assert req.status_code == 20033 def test_client_put(self):34 # ÑеализоваÑÑ Ð¾Ð±ÑабоÑÐºÑ PUT запÑоÑов35 data = {"test": 123}36 req = requests.put(APP_URL + "/put_data", json={"test": 123})37 assert req.status_code == 20038 assert req.json() == {"data": str(data)}39 def test_mock_down(self):40 # пÑиложение поднÑÑо, а мок не поднÑÑ41 req = requests.get(APP_URL + "/mock_down")42 assert req.status_code == 50043 def test_mock_timeout(self):44 # пÑиложение поднÑÑо, а мок не оÑвеÑаеÑ(timeout)45 with pytest.raises(TimeoutError):46 client = Client(MOCK_HOST, MOCK_PORT)47 client.send("wait", "data", "GET", {})...
test_client.py
Source:test_client.py
...11 with pytest.raises(client.StorageError):12 storage_client.get('test')13def test_client_reader(storage_client, blob_reader_mock):14 assert storage_client.create_reader('test').read() == b'mocked'15def test_client_put(storage_client, blob_writer_mock, tmp_path):16 path = tmp_path / 'test'17 path.open('wb').write(b'test')18 assert storage_client.put(path) == 'mock_key'19def test_client_put_error(storage_client, stubber, tmp_path):20 stubber.add_client_error('put_object', 'broken', 'bad', 400)21 # Without mocking the writer, this will attempt to access a non-22 # -existent endpoint on example.com and hence fail.23 with pytest.raises(client.StorageError):24 path = tmp_path / 'test'25 path.open('wb').write(b'test')26 storage_client.put(path)27def test_client_writer(storage_client, blob_writer_mock):28 writer = storage_client.create_writer()29 writer.write(b'test')...
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!!