Best Python code snippet using tempest_python
test_network_advanced_server_ops.py
Source:test_network_advanced_server_ops.py  
...114        self._wait_server_status_and_check_network_connectivity()115    @testtools.skipUnless(CONF.compute_feature_enabled.suspend,116                          'Suspend is not available.')117    @test.services('compute', 'network')118    def test_server_connectivity_suspend_resume(self):119        self._setup_network_and_servers()120        self.servers_client.suspend_server(self.server['id'])121        self.servers_client.wait_for_server_status(self.server['id'],122                                                   'SUSPENDED')123        self._check_network_connectivity(should_connect=False)124        self.servers_client.resume_server(self.server['id'])125        self._wait_server_status_and_check_network_connectivity()126    @test.skip_because(bug="1323658")127    @testtools.skipUnless(CONF.compute_feature_enabled.resize,128                          'Resize is not available.')129    @test.services('compute', 'network')130    def test_server_connectivity_resize(self):131        resize_flavor = CONF.compute.flavor_ref_alt132        if resize_flavor == CONF.compute.flavor_ref:...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!!
