Best Python code snippet using tempest_python
test_volumes_negative.py
Source:test_volumes_negative.py
...190 self.assertRaises(exceptions.NotFound,191 self.client.unreserve_volume,192 str(uuid.uuid4()))193 @attr(type=['negative', 'gate'])194 def test_reserve_volume_with_negative_volume_status(self):195 # Mark volume as reserved.196 resp, body = self.client.reserve_volume(self.volume['id'])197 self.assertEqual(202, resp.status)198 # Mark volume which is marked as reserved before199 self.assertRaises(exceptions.BadRequest,200 self.client.reserve_volume,201 self.volume['id'])202 # Unmark volume as reserved.203 resp, body = self.client.unreserve_volume(self.volume['id'])204 self.assertEqual(202, resp.status)205 @attr(type=['negative', 'gate'])206 def test_list_volumes_with_nonexistent_name(self):207 v_name = data_utils.rand_name('Volume-')208 params = {'display_name': v_name}...
test_tempest_mail.py
Source:test_tempest_mail.py
1import mock2import os3import unittest4from email.mime.text import MIMEText5import tempestmail.config6import tempestmail.mail7from tempestmail import tests8JOB = 'periodic-tripleo-ci-centos-7-ovb-ha-tempest'9class TestTempestMail(unittest.TestCase):10 def setUp(self):11 self.template_path = os.path.join(os.path.dirname(tests.__file__),12 'fixtures', 'mail')13 self.config_file = os.path.join(os.path.dirname(tests.__file__),14 'fixtures', 'config_validate',15 'good.yaml')16 self.config = tempestmail.config.loadConfig(self.config_file)17 self.config.template_path = self.template_path18 self.job = self.config.jobs[JOB]19 self.fail = [20 ('tempest.scenario.test_volume_boot_pattern.TestVolumeBootPattern.'21 'test_volume_boot_pattern'),22 ('tempest.scenario.test_volume_boot_pattern.TestVolumeBootPattern'23 'V2.test_volume_boot_pattern')24 ]25 self.covered = [26 ('tempest.api.volume.admin.v3.test_user_messages.UserMessagesTest'27 '.test_list_messages'),28 ('tempest.api.identity.v3.test_tokens.TokensV3Test.'29 'test_create_token')30 ]31 self.new = [32 ('tempest.scenario.test_network_basic_ops.TestNetworkBasicOps.'33 'test_port_security_macspoofing_port'),34 ('tempest.scenario.test_network_advanced_server_ops.TestNetworkA'35 'dvancedServerOps.test_server_connectivity_suspend_resume')36 ]37 self.errors = [38 ('tempest.api.volume.test_volumes_snapshots_negative.VolumesV1S'39 'napshotNegativeTestJSON.test_create_snapshot_with_nonexistent_'40 'volume_id'),41 ('tempest.api.volume.test_volumes_negative.VolumesV2NegativeTest.'42 'test_reserve_volume_with_negative_volume_status')43 ]44 def test_render_template(self):45 _mail = tempestmail.mail.Mail(self.config)46 data = {47 'failed': self.fail,48 'covered': self.covered,49 'new': self.new,50 'errors': self.errors51 }52 render = _mail.render_template('template.html', data)53 self.assertIn('<h2>New failures</h2>', render)54 data.pop('new')55 render = _mail.render_template('template.html', data)56 self.assertIn('<h2>Success</h2>', render)57 data.pop('failed')58 render = _mail.render_template('template.html', data)59 self.assertIn('<h2>unexpected failures</h2>', render)60 @mock.patch('smtplib.SMTP')61 def test_send_mail(self, smtp_mock):62 _mail = tempestmail.mail.Mail(self.config)63 data = {64 'failed': self.fail,65 'covered': self.covered,66 'new': self.new,67 'errors': self.errors68 }69 render = _mail.render_template('template.html', data)70 msg = MIMEText(render)71 msg['Subject'] = self.job.subject72 msg['From'] = ''73 msg['To'] = ",".join(['arxcruz@gmail.com'])74 _mail.send_mail(self.job, data)75 smtp_mock.assert_called_once()76 smtp_mock.return_value.sendmail.assert_called_with(77 '', ['arxcruz@gmail.com'], msg.as_string())78 smtp_mock.reset_mock()79 self.job.is_template = False80 self.job.message = 'Hello World'81 msg = MIMEText(self.job.message)82 msg['Subject'] = self.job.subject83 msg['From'] = ''84 msg['To'] = ",".join(['arxcruz@gmail.com'])85 _mail.send_mail(self.job, data)86 smtp_mock.assert_called_once()87 smtp_mock.return_value.sendmail.assert_called_with(...
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!!