How to use test_ipv4_port method in yandex-tank

Best Python code snippet using yandex-tank

test_utils.py

Source: test_utils.py Github

copy

Full Screen

1"""Unit-тесты утилит"""2import sys3import os4import unittest5import json6sys.path.append(os.path.join(os.getcwd(), '..'))7from common.variables import RESPONSE, ERROR, USER, ACCOUNT_NAME, TIME, ACTION, PRESENCE, ENCODING8from common.utils import get_message, send_message, get_address_port9class TestSocket:10 '''11 Тестовый класс для тестирования отправки и получения,12 при создании требует словарь, который будет прогонятся13 через тестовую функцию14 '''15 def __init__(self, test_dict):16 self.test_dict = test_dict17 self.encoded_message = None18 self.receved_message = None19 def send(self, message_to_send):20 """21 Тестовая функция отправки, корретно кодирует сообщение,22 так-же сохраняет что должно было отправлено в сокет.23 message_to_send - то, что отправляем в сокет24 :param message_to_send:25 :return:26 """27 json_test_message = json.dumps(self.test_dict)28 # кодирует сообщение29 self.encoded_message = json_test_message.encode(ENCODING)30 # сохраняем что должно было отправлено в сокет31 self.receved_message = message_to_send32 def recv(self, max_len):33 """34 Получаем данные из сокета35 :param max_len:36 :return:37 """38 json_test_message = json.dumps(self.test_dict)39 return json_test_message.encode(ENCODING)40class Tests(unittest.TestCase):41 '''42 Тестовый класс, собственно выполняющий тестирование.43 '''44 test_dict_send = {45 ACTION: PRESENCE,46 TIME: 111111.111111,47 USER: {48 ACCOUNT_NAME: 'test_test'49 }50 }51 test_dict_recv_ok = {RESPONSE: 200}52 test_dict_recv_err = {53 RESPONSE: 400,54 ERROR: 'Bad Request'55 }56 def test_send_message(self):57 """58 Тестируем корректность работы фукции отправки,59 создадим тестовый сокет и проверим корректность отправки словаря60 :return:61 """62 # экземпляр тестового словаря, хранит собственно тестовый словарь63 test_socket = TestSocket(self.test_dict_send)64 # вызов тестируемой функции, результаты будут сохранены в тестовом сокете65 send_message(test_socket, self.test_dict_send)66 # проверка корретности кодирования словаря.67 # сравниваем результат довренного кодирования и результат от тестируемой функции68 self.assertEqual(test_socket.encoded_message, test_socket.receved_message)69 # дополнительно, проверим генерацию исключения, при не словаре на входе.70 with self.assertRaises(Exception):71 send_message(test_socket, test_socket)72 def test_get_message(self):73 """74 Тест функции приёма сообщения75 :return:76 """77 test_sock_ok = TestSocket(self.test_dict_recv_ok)78 test_sock_err = TestSocket(self.test_dict_recv_err)79 # тест корректной расшифровки корректного словаря80 self.assertEqual(get_message(test_sock_ok), self.test_dict_recv_ok)81 # тест корректной расшифровки ошибочного словаря82 self.assertEqual(get_message(test_sock_err), self.test_dict_recv_err)83 84 def test_default_get_address_port(self):85 """ 86 Тестирует формирование ipv4 адреса и порта по умолчанию87 """88 ipv4_port_default = [ '', 7777]89 90 test_ipv4_port = get_address_port()91 self.assertEqual(test_ipv4_port,ipv4_port_default)92 93 94 95if __name__ == '__main__':...

Full Screen

Full Screen

test_flask.py

Source: test_flask.py Github

copy

Full Screen

...12 headers = {'Host': 'my-host-0'}13 result = extract_connection_params(headers)14 assert result['hostname'] == 'my-host-0'15 assert 'port' not in result16 def test_ipv4_port(self):17 headers = {'Host': '192.168.1.1:9497'}18 result = extract_connection_params(headers)19 assert result['hostname'] == '192.168.1.1'20 assert result['port'] == 949721 def test_ipv4_no_port(self):22 headers = {'Host': '192.168.1.1'}23 result = extract_connection_params(headers)24 assert result['hostname'] == '192.168.1.1'25 assert 'port' not in result26 def test_ipv6_port(self):27 headers = {'Host': '[::1]:9497'}28 result = extract_connection_params(headers)29 assert result['hostname'] == '::1'30 assert result['port'] == 9497...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Webinar: Move Forward With An Effective Test Automation Strategy [Voices of Community]

The key to successful test automation is to focus on tasks that maximize the return on investment (ROI), ensuring that you are automating the right tests and automating them in the right way. This is where test automation strategies come into play.

Dec’22 Updates: The All-New LT Browser 2.0, XCUI App Automation with HyperExecute, And More!

Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.

Developers and Bugs – why are they happening again and again?

Entering the world of testers, one question started to formulate in my mind: “what is the reason that bugs happen?”.

Test Optimization for Continuous Integration

“Test frequently and early.” If you’ve been following my testing agenda, you’re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. I’ve encountered several teams who have a lot of automated tests but don’t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

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 yandex-tank 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