How to use tear_down method in autotest

Best Python code snippet using autotest_python

test_users.py

Source:test_users.py Github

copy

Full Screen

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

Full Screen

Full Screen

_testcase.py

Source:_testcase.py Github

copy

Full Screen

...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" %...

Full Screen

Full Screen

fixtures.py

Source:fixtures.py Github

copy

Full Screen

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

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