~aaron-whitehouse/duplicity/08-unicode

« back to all changes in this revision

Viewing changes to testing/functional/test_replicate.py

  • Committer: Aaron A Whitehouse
  • Date: 2017-06-25 17:56:04 UTC
  • mfrom: (1189.1.56 duplicity-src8)
  • Revision ID: lists@whitehouse.kiwi.nz-20170625175604-r6bum9cmofa1jrl1
Merge with trunk, turning string literals in the new testing/functional/test_replicate.py into unicode.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
 
2
#
 
3
# Copyright 2002 Ben Escoto <ben@emerose.org>
 
4
# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
 
5
#
 
6
# This file is part of duplicity.
 
7
#
 
8
# Duplicity is free software; you can redistribute it and/or modify it
 
9
# under the terms of the GNU General Public License as published by the
 
10
# Free Software Foundation; either version 2 of the License, or (at your
 
11
# option) any later version.
 
12
#
 
13
# Duplicity is distributed in the hope that it will be useful, but
 
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
# General Public License for more details.
 
17
#
 
18
# You should have received a copy of the GNU General Public License
 
19
# along with duplicity; if not, write to the Free Software Foundation,
 
20
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
21
 
 
22
import os
 
23
import unittest
 
24
 
 
25
from duplicity import path
 
26
from . import CmdError, FunctionalTestCase
 
27
 
 
28
 
 
29
class ReplicateTest(FunctionalTestCase):
 
30
    """
 
31
    Test backup/replicate/restore using duplicity binary
 
32
    """
 
33
 
 
34
    def runtest(self, dirlist, backup_options=[], replicate_options=[], restore_options=[]):
 
35
        # Back up directories to local backend
 
36
        current_time = 100000
 
37
        self.backup(u"full", dirlist[0], current_time=current_time,
 
38
                    options=backup_options)
 
39
        for new_dir in dirlist[1:]:
 
40
            current_time += 100000
 
41
            self.backup(u"inc", new_dir, current_time=current_time,
 
42
                        options=backup_options)
 
43
 
 
44
        # Replicate to other backend
 
45
        source_url = self.backend_url
 
46
        target_url = u"file://testfiles/replicate_out"
 
47
        self.run_duplicity(options=[u"replicate"] +
 
48
                           replicate_options + [source_url, target_url])
 
49
 
 
50
        self.backend_url = target_url
 
51
 
 
52
        # Restore each and compare them
 
53
        for i in range(len(dirlist)):
 
54
            dirname = dirlist[i]
 
55
            current_time = 100000 * (i + 1)
 
56
            self.restore(time=current_time, options=restore_options)
 
57
            self.check_same(dirname, u"testfiles/restore_out")
 
58
            self.verify(dirname,
 
59
                        time=current_time, options=restore_options)
 
60
 
 
61
    def check_same(self, filename1, filename2):
 
62
        """Verify two filenames are the same"""
 
63
        path1, path2 = path.Path(filename1), path.Path(filename2)
 
64
        assert path1.compare_recursive(path2, verbose=1)
 
65
 
 
66
    def test_replicate(self):
 
67
        """Test replication"""
 
68
        self.runtest([u"testfiles/dir1", u"testfiles/dir2"])
 
69
 
 
70
    def test_replicate_noencryption(self):
 
71
        """Test replication with decryption"""
 
72
        self.runtest([u"testfiles/dir1", u"testfiles/dir2"],
 
73
                     replicate_options=[u"--no-encryption"])
 
74
 
 
75
    def test_replicate_asym(self):
 
76
        """Test replication with reencryption"""
 
77
        asym_options = [u"--encrypt-key", self.encrypt_key1]
 
78
        self.runtest([u"testfiles/dir1", u"testfiles/dir2"],
 
79
                     replicate_options=asym_options, restore_options=asym_options)