Best Python code snippet using Airtest
test_users.py
Source: test_users.py
...14 'senha': '12345'15 }16 def mock_user(self):17 db.usuarios.insert_one(self.user_data)18 def tear_down(self, email):19 query = {'email': email}20 db.usuarios.delete_one(query)21 def test_criar_usuario(self, client):22 url = '/usuarios/novo'23 self.tear_down(self.user_data['email'])24 res = client.post(url, data=json.dumps(self.user_data),25 headers=self.headers)26 assert res.status_code == 20127 self.tear_down(self.user_data['email'])28 def test_deletar_usuario(self, client):29 url = '/usuario/deletar/test@sme.prefeitura.sp.gov.br'30 self.tear_down(self.user_data['email'])31 self.mock_user()32 res = client.delete(url, headers=self.headers)33 assert res.status_code == 20034 self.tear_down(self.user_data['email'])35 def test_get_usuarios(self, client):36 res = client.get('/usuarios')37 assert res.status_code == 20038 def test_get_usuario(self, client):39 self.tear_down(self.user_data['email'])40 self.mock_user()41 res = client.get('/usuario/test@sme.prefeitura.sp.gov.br')42 assert res.json == [{43 "email": "test@sme.prefeitura.sp.gov.br",44 "senha": "12345"45 }]46 self.tear_down(self.user_data['email'])47 def test_editar_usuario(self, client):48 url = '/usuario/editar/test@sme.prefeitura.sp.gov.br'49 self.tear_down(self.user_data['email'])50 self.mock_user()51 new_user_data = {52 'email': 'test@sme.prefeitura.sp.gov.br',53 'senha': '12345678'54 }55 res = client.put(url, data=json.dumps(new_user_data),56 headers=self.headers)57 assert res.status_code == 201...
_testcase.py
Source: _testcase.py
...5 def __init__(self):6 self._on_teardown = []7 def add_teardown(self, teardown):8 self._on_teardown.append(teardown)9 def tear_down(self):10 for func in reversed(self._on_teardown):11 func()12class TearDownConvenience(object):13 def __init__(self, setup_stack=None):14 self._own_setup_stack = setup_stack is None15 if setup_stack is None:16 setup_stack = SetupStack()17 self._setup_stack = setup_stack18 # only call this convenience method if no setup_stack was supplied to c'tor19 def tear_down(self):20 assert self._own_setup_stack21 self._setup_stack.tear_down()22class TempDirMaker(TearDownConvenience):23 def make_temp_dir(self):24 temp_dir = tempfile.mkdtemp(prefix="tmp-%s-" % self.__class__.__name__)25 def tear_down():26 shutil.rmtree(temp_dir)27 self._setup_stack.add_teardown(tear_down)28 return temp_dir29class MonkeyPatcher(TearDownConvenience):30 def monkey_patch(self, obj, name, value):31 orig_value = getattr(obj, name)32 setattr(obj, name, value)33 def reverse_patch():34 setattr(obj, name, orig_value)35 self._setup_stack.add_teardown(reverse_patch)36class TestCase(unittest.TestCase):37 def setUp(self):38 self._setup_stack = SetupStack()39 def tearDown(self):40 self._setup_stack.tear_down()41 def make_temp_dir(self, *args, **kwds):42 return TempDirMaker(self._setup_stack).make_temp_dir(*args, **kwds)43 def monkey_patch(self, *args, **kwds):44 return MonkeyPatcher(self._setup_stack).monkey_patch(*args, **kwds)45 def assert_contains(self, container, containee):46 self.assertTrue(containee in container, "%r not in %r" %47 (containee, container))48 def assert_less_than(self, got, expected):49 self.assertTrue(got < expected, "%r >= %r" %...
fixtures.py
Source: fixtures.py
...4@pytest.fixture(scope='function')5def create_eNB(request):6 proc = Popen('build/CP_eNB/src/hwserver')7 8 def tear_down():9 proc.kill()10 11 request.addfinalizer(tear_down)12@pytest.fixture(scope='function')13def create_mme(request):14 context = zmq.Context()15 mme = context.socket(zmq.DEALER)16 port = 555517 mme.connect("tcp://localhost:%s" % port)18 mme.RCVTIMEO = 100019 20 def tear_down():21 mme.close()22 23 request.addfinalizer(tear_down)24 ...
Check out the latest blogs from LambdaTest on this topic:
Unit testing is typically software testing within the developer domain. As the QA role expands in DevOps, QAOps, DesignOps, or within an Agile team, QA testers often find themselves creating unit tests. QA testers may create unit tests within the code using a specified unit testing tool, or independently using a variety of methods.
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.
The purpose of developing test cases is to ensure the application functions as expected for the customer. Test cases provide basic application documentation for every function, feature, and integrated connection. Test case development often detects defects in the design or missing requirements early in the development process. Additionally, well-written test cases provide internal documentation for all application processing. Test case development is an important part of determining software quality and keeping defects away from customers.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
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!!