def test_create_remote_path_negative(self): """Test that a failure returns False""" self.stderr.channel.recv_exit_status = 1 remote_path = mysql_backup.create_remote_path(self.ssh, self.remote_backup_dir) self.assertFalse(remote_path)
def test_create_remote_path(self): """Test remote path creation with a mock object""" self.stderr.channel.recv_exit_status = 0 remote_path = mysql_backup.create_remote_path(self.ssh, self.remote_backup_dir) self.assertEqual(self.remote_backup_dir, remote_path)
def test_create_remote_path_negative(self): """Test that we handle remote path failures properly""" self.stdout.channel.recv_exit_status.return_value = 1 error_msg = "mkdir: cannot create directory ‘tests’: File exists" self.stderr.read.return_value.decode.return_value = error_msg remote_path = mysql_backup.create_remote_path(self.ssh, self.remote_backup_dir) self.assertIsNone(remote_path)
def test_backup_db_negative(self): """ Test that we the backup_database function returns None when the command executes unsuccessfully """ self.stdout.channel.recv_exit_status.return_value = 0 remote_path = mysql_backup.create_remote_path(self.ssh, self.remote_backup_dir) self.stdout.channel.recv_exit_status.return_value = 1 error_msg = "mysqldump: permission denied" self.stderr.read.return_value.decode.return_value = error_msg db_backup = mysql_backup.backup_database(self.ssh, 'test_database', remote_path) self.assertIsNone(db_backup)
def test_backup_db(self): """ Test that the backup_database function returns the pre-defined path if the command executes successfully """ self.stdout.channel.recv_exit_status.return_value = 0 remote_path = mysql_backup.create_remote_path(self.ssh, self.remote_backup_dir) self.stdout.channel.recv_exit_status.return_value = 0 db_backup = mysql_backup.backup_database(self.ssh, 'test_database', remote_path) re_string = '/'.join([self.remote_backup_dir, 'test_database' '-\d{2}-\d{2}-\d{4}-\d{2}:\d{2}:\d{2}.sql']) regex = re.compile(re_string) self.assertTrue(regex.match(db_backup))