Best Python code snippet using tempest_python
test_volumes_backup.py
Source:test_volumes_backup.py
...85 self.assertTrue(export_backup['backup_service'].startswith(86 'cinder.backup.drivers'))87 self.assertIsNotNone(export_backup['backup_url'])88 # Import Backup89 import_backup = self.backups_adm_client.import_backup(90 backup_service=export_backup['backup_service'],91 backup_url=export_backup['backup_url'])['backup']92 self.addCleanup(self._delete_backup, import_backup['id'])93 self.assertIn("id", import_backup)94 self.backups_adm_client.wait_for_backup_status(import_backup['id'],95 'available')96 # Verify Import Backup97 backups = self.backups_adm_client.list_backups(detail=True)['backups']98 self.assertIn(import_backup['id'], [b['id'] for b in backups])99 # Restore backup100 restore = (self.backups_adm_client.restore_backup(import_backup['id'])101 ['restore'])102 self.addCleanup(self.admin_volume_client.delete_volume,103 restore['volume_id'])...
test_import_backup_command.py
Source:test_import_backup_command.py
1import tempfile2from logging import Logger3from pathlib import Path4from unittest.mock import patch5import django6from django.contrib.auth.models import User7from django.core.exceptions import ObjectDoesNotExist8from django.test import TransactionTestCase9from caretaker.frontend.abstract_frontend import FrontendFactory, \10 AbstractFrontend11from caretaker.management.commands import import_backup12from caretaker.utils import log13class TestImportSQLiteDjango(TransactionTestCase):14 def setUp(self):15 self.logger: Logger = log.get_logger('import-sqlite-test')16 self.logger.info('Setup for test SQLlite import command')17 self.frontend: AbstractFrontend = FrontendFactory.get_frontend('Django')18 django.setup()19 def tearDown(self):20 self.logger.info('Teardown for test SQLlite import command')21 pass22 def test(self):23 self.logger.info('Testing test SQLlite import command')24 # first, insert something into the database25 username: str = 'test_user'26 User.objects.create_user(username=username, email='martin@eve.gd',27 password='test_password_123')28 # now re-fetch the user29 user: User = User.objects.get(username=username)30 self.assertEqual(user.username, username)31 # dump a JSON backup into the temporary directory32 with tempfile.TemporaryDirectory() as temporary_directory_name:33 filename: str = 'data.sql'34 file_path: Path = Path(temporary_directory_name) / filename35 self.frontend.export_sql(output_file=str(file_path))36 self.assertTrue(file_path.exists())37 # now modify the database38 second_username: str = 'user2'39 user.username = second_username40 user.save()41 # assert we can't find it with the original username42 with self.assertRaises(ObjectDoesNotExist):43 User.objects.get(username=username)44 # now do the restore with dry run, which should fail45 import_backup.command.callback(46 input_file=file_path,47 dry_run=True,48 frontend_name=self.frontend.frontend_name49 )50 with self.assertRaises(ObjectDoesNotExist):51 User.objects.get(username=username)52 # now do the real restore with dry run, which should fail53 import_backup.command.callback(54 input_file=file_path,55 dry_run=False,56 frontend_name=self.frontend.frontend_name57 )58 # now this should not raise an error59 user: User = User.objects.get(username=username)60 self.assertEqual(user.username, username)61 # now test for loaders failing62 with self.assertLogs(level='ERROR') as log_obj:63 import_backup.command.callback(64 input_file=file_path,65 dry_run=False,66 frontend_name='NON'67 )68 self.assertIn('Unable to find a valid frontend',69 ''.join(log_obj.output))70 # patch for error handling71 with patch(72 'caretaker.frontend.abstract_frontend.FrontendFactory.'73 'get_frontend',74 side_effect=PermissionError('Oh dear how sad never mind')):75 with self.assertLogs(level='ERROR') as log_obj:76 import_backup.command.callback(77 input_file=file_path,78 dry_run=False,79 frontend_name='NON'80 )81 self.assertIn('Unable to open output file',...
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!!