Best Python code snippet using tempest_python
test_volume_boot_pattern.py
Source:test_volume_boot_pattern.py  
...97    def _check_content_of_written_file(self, ssh_client, expected):98        actual = self._get_content(ssh_client)99        self.assertEqual(expected, actual)100    @services('compute', 'volume', 'image')101    def test_volume_boot_pattern(self):102        keypair = self.create_keypair()103        self._create_loginable_secgroup_rule_nova()104        # create an instance from volume105        volume_origin = self._create_volume_from_image()106        instance_1st = self._boot_instance_from_volume(volume_origin.id,107                                                       keypair)108        # write content to volume on instance109        ssh_client_for_instance_1st = self._ssh_to_server(instance_1st,110                                                          keypair)111        text = self._write_text(ssh_client_for_instance_1st)112        # delete instance113        self._delete_server(instance_1st)114        # create a 2nd instance from volume115        instance_2nd = self._boot_instance_from_volume(volume_origin.id,...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(...constants.py
Source:constants.py  
1import re2HREF = re.compile('href="([^"]+)"')3JOBRE = re.compile('[a-z0-9]{7}/')4TESTRE = re.compile('(tempest\.[^ \(\)]+)')5TIMEST = re.compile('(\d{4}-\d{2}-\d{2} \d{2}:\d{2}):\d{2}\.\d+ \|')6TITLE = re.compile('<title>(.*?)</title>')7FAILED = "... FAILED"8OK = "... ok"9ERROR = "... ERROR"10SKIPPED = "... SKIPPED"11TESTS = {12    'tempest.scenario.test_volume_boot_pattern.*':13        'http://bugzilla.redhat.com/1272289',14    'tempest.api.identity.*v3.*':15        'https://bugzilla.redhat.com/1266947',16    '.*test_external_network_visibility':17        'https://bugs.launchpad.net/tripleo/+bug/1577769',...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!!
