~ubuntu-branches/ubuntu/saucy/deja-dup/saucy

« back to all changes in this revision

Viewing changes to tests/ldtp/quiescent

  • Committer: Package Import Robot
  • Author(s): Michael Terry
  • Date: 2012-10-30 19:03:03 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20121030190303-w3fatge63ncm5uiw
Tags: 25.1.1-0ubuntu1
* New upstream release
* debian/control:
  - Use libsecret, not libgnome-keyring
  - Switch to valac-0.18
  - Add various deja-dup-backend-* metapackages to make seeding
    different ones easier for flavors
* debian/tests:
  - Add dep8 test to run upstream test suite against system install
* debian/patches/support-new-u1backend.patch:
  - Support new u1backend in duplicity 0.6.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-
 
3
#
 
4
# This file is part of Déjà Dup.
 
5
# For copyright information, see AUTHORS.
 
6
#
 
7
# Déjà Dup is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation; either version 3 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# Déjà Dup is distributed in the hope that it will be useful, but
 
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
# General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
# Test how well we handle user mucking with files while we back up
 
21
 
 
22
import sys
 
23
import os
 
24
sys.path.insert(0, sys.path[0]+'/..')
 
25
import base
 
26
import ldtp
 
27
import time
 
28
import re
 
29
 
 
30
last_written = 'a'
 
31
 
 
32
def rewrite(name, size):
 
33
  global last_written
 
34
  f = open(name, 'wb')
 
35
  string = ('{:%s<%d}' % (last_written, size)).format('')
 
36
  f.write(string)
 
37
  f.close()
 
38
  last_written = chr(ord(last_written) + 1) if last_written != 'z' else 'a'
 
39
 
 
40
def keep_writing(destdir, sourcename):
 
41
  count = 0
 
42
  rewrite(sourcename, 30 * 1024 * 1024)
 
43
  assert ldtp.waittillguiexist('frmBackUp')
 
44
  while ldtp.guiexist('frmBackUp'):
 
45
    rewrite(sourcename, 30 * 1024 * 1024)
 
46
    count += 1
 
47
    assert count < 200
 
48
 
 
49
def wait_for_volume(destdir):
 
50
  count = 0
 
51
  while len(os.listdir(destdir)) < 2 and count < 200:
 
52
    time.sleep(1)
 
53
    count += 1
 
54
 
 
55
def writing():
 
56
  global last_written
 
57
  last_written = 'a'
 
58
  base.setup()
 
59
  sourcedir = base.get_temp_name('source')
 
60
  os.makedirs(sourcedir)
 
61
  sourcefile = os.path.join(sourcedir, 'file')
 
62
  base.backup_simple(backend='file', includes=[sourcedir], finish=False)
 
63
 
 
64
  destdir = base.get_temp_name('local')
 
65
  keep_writing(destdir, sourcefile)
 
66
 
 
67
  restoredir = base.get_temp_name('restore')
 
68
  restorefile = os.path.join(restoredir, './'+sourcefile)
 
69
  base.restore_simple(restoredir)
 
70
 
 
71
  # make sure that whatever version of the file got written, got written complete
 
72
  f = open(restorefile, 'rb')
 
73
  string = f.read()
 
74
  f.close()
 
75
  assert re.match('^%c+$' % string[0], string), string
 
76
 
 
77
def pause_before():
 
78
  global last_written
 
79
  last_written = 'a'
 
80
  base.setup()
 
81
  sourcedir = base.get_temp_name('source')
 
82
  os.makedirs(sourcedir)
 
83
 
 
84
  rewrite(os.path.join(sourcedir, 'a'), 20)
 
85
  rewrite(os.path.join(sourcedir, 'b'), 30 * 1024 * 1024)
 
86
  rewrite(os.path.join(sourcedir, 'c'), 30)
 
87
 
 
88
  base.backup_simple(backend='file', includes=[sourcedir], finish=False)
 
89
 
 
90
  destdir = base.get_temp_name('local')
 
91
  wait_for_volume(destdir)
 
92
  ldtp.click('frmBackUp', 'btnResumeLater')
 
93
 
 
94
  rewrite(os.path.join(sourcedir, 'a'), 20)
 
95
 
 
96
  base.backup_simple()
 
97
 
 
98
  restoredir = base.get_temp_name('restore')
 
99
  restorefile = os.path.join(restoredir, './'+sourcedir, 'a')
 
100
  base.restore_simple(restoredir)
 
101
 
 
102
  f = open(restorefile, 'rb')
 
103
  string = f.read()
 
104
  f.close()
 
105
  assert len(string) == 20, string
 
106
  assert re.match('^d+$', string), string
 
107
 
 
108
def pause_middle():
 
109
  global last_written
 
110
  last_written = 'a'
 
111
  base.setup()
 
112
  sourcedir = base.get_temp_name('source')
 
113
  os.makedirs(sourcedir)
 
114
 
 
115
  rewrite(os.path.join(sourcedir, 'a'), 20)
 
116
  rewrite(os.path.join(sourcedir, 'b'), 30 * 1024 * 1024)
 
117
  rewrite(os.path.join(sourcedir, 'c'), 30)
 
118
 
 
119
  base.backup_simple(backend='file', includes=[sourcedir], finish=False)
 
120
 
 
121
  destdir = base.get_temp_name('local')
 
122
  wait_for_volume(destdir)
 
123
  ldtp.click('frmBackUp', 'btnResumeLater')
 
124
 
 
125
  rewrite(os.path.join(sourcedir, 'b'), 30 * 1024 * 1024)
 
126
 
 
127
  base.backup_simple()
 
128
 
 
129
  restoredir = base.get_temp_name('restore')
 
130
  restorefile = os.path.join(restoredir, './'+sourcedir, 'b')
 
131
  base.restore_simple(restoredir)
 
132
 
 
133
  f = open(restorefile, 'rb')
 
134
  string = f.read()
 
135
  f.close()
 
136
  assert len(string) == 30 * 1024 * 1024, string[0:1024]
 
137
  assert re.match('^d+$', string), string[0:1024]
 
138
 
 
139
base.run(writing)
 
140
base.run(pause_before)
 
141
base.run(pause_middle)
 
142