]> arthur.barton.de Git - bup.git/blob - test/ext/test_ftp.py
test-fuse: improve/broaden applicability checks
[bup.git] / test / ext / test_ftp.py
1
2 from __future__ import absolute_import, print_function
3 from os import chdir, mkdir, symlink, unlink
4 from subprocess import PIPE
5 from time import localtime, strftime, tzset
6
7 from bup.compat import environ
8 from bup.helpers import unlink as unlink_if_exists
9 from buptest import ex, exo
10 from wvpytest import wvfail, wvpass, wvpasseq, wvpassne, wvstart
11 import bup.path
12
13 bup_cmd = bup.path.exe()
14
15 def bup(*args, **kwargs):
16     if 'stdout' not in kwargs:
17         return exo((bup_cmd,) + args, **kwargs)
18     return ex((bup_cmd,) + args, **kwargs)
19
20 def jl(*lines):
21     return b''.join(line + b'\n' for line in lines)
22
23 environ[b'GIT_AUTHOR_NAME'] = b'bup test'
24 environ[b'GIT_COMMITTER_NAME'] = b'bup test'
25 environ[b'GIT_AUTHOR_EMAIL'] = b'bup@a425bc70a02811e49bdf73ee56450e6f'
26 environ[b'GIT_COMMITTER_EMAIL'] = b'bup@a425bc70a02811e49bdf73ee56450e6f'
27
28 import subprocess
29
30 def test_ftp(tmpdir):
31     environ[b'BUP_DIR'] = tmpdir + b'/repo'
32     environ[b'GIT_DIR'] = tmpdir + b'/repo'
33     environ[b'TZ'] = b'UTC'
34     tzset()
35
36     chdir(tmpdir)
37     mkdir(b'src')
38     chdir(b'src')
39     mkdir(b'dir')
40     with open(b'file-1', 'wb') as f:
41         f.write(b'excitement!\n')
42     with open(b'dir/file-2', 'wb') as f:
43         f.write(b'more excitement!\n')
44     symlink(b'file-1', b'file-symlink')
45     symlink(b'dir', b'dir-symlink')
46     symlink(b'not-there', b'bad-symlink')
47
48     chdir(tmpdir)    
49     bup(b'init')
50     bup(b'index', b'src')
51     bup(b'save', b'-n', b'src', b'--strip', b'src')
52     save_utc = int(exo((b'git', b'show',
53                         b'-s', b'--format=%at', b'src')).out.strip())
54     save_name = strftime('%Y-%m-%d-%H%M%S', localtime(save_utc)).encode('ascii')
55     
56     wvstart('help')
57     wvpasseq(b'Commands: ls cd pwd cat get mget help quit\n',
58              exo((bup_cmd, b'ftp'), input=b'help\n', stderr=PIPE).out)
59
60     wvstart('pwd/cd')
61     wvpasseq(b'/\n', bup(b'ftp', input=b'pwd\n').out)
62     wvpasseq(b'', bup(b'ftp', input=b'cd src\n').out)
63     wvpasseq(b'/src\n', bup(b'ftp', input=jl(b'cd src', b'pwd')).out)
64     wvpasseq(b'/src\n/\n', bup(b'ftp', input=jl(b'cd src', b'pwd',
65                                                 b'cd ..', b'pwd')).out)
66     wvpasseq(b'/src\n/\n', bup(b'ftp', input=jl(b'cd src', b'pwd',
67                                                 b'cd ..', b'cd ..',
68                                                 b'pwd')).out)
69     wvpasseq(b'/src/%s/dir\n' % save_name,
70              bup(b'ftp', input=jl(b'cd src/latest/dir-symlink', b'pwd')).out)
71     wvpasseq(b'/src/%s/dir\n' % save_name,
72              bup(b'ftp', input=jl(b'cd src latest dir-symlink', b'pwd')).out)
73     wvpassne(0, bup(b'ftp',
74                     input=jl(b'cd src/latest/bad-symlink', b'pwd'),
75                     check=False, stdout=None).rc)
76     wvpassne(0, bup(b'ftp',
77                     input=jl(b'cd src/latest/not-there', b'pwd'),
78                     check=False, stdout=None).rc)
79
80     wvstart('ls')
81     # FIXME: elaborate
82     wvpasseq(b'src\n', bup(b'ftp', input=b'ls\n').out)
83     wvpasseq(save_name + b'\nlatest\n',
84              bup(b'ftp', input=b'ls src\n').out)
85
86     wvstart('cat')
87     wvpasseq(b'excitement!\n',
88              bup(b'ftp', input=b'cat src/latest/file-1\n').out)
89     wvpasseq(b'excitement!\nmore excitement!\n',
90              bup(b'ftp',
91                  input=b'cat src/latest/file-1 src/latest/dir/file-2\n').out)
92     
93     wvstart('get')
94     bup(b'ftp', input=jl(b'get src/latest/file-1 dest'))
95     with open(b'dest', 'rb') as f:
96         wvpasseq(b'excitement!\n', f.read())
97     unlink(b'dest')
98     bup(b'ftp', input=jl(b'get src/latest/file-symlink dest'))
99     with open(b'dest', 'rb') as f:
100         wvpasseq(b'excitement!\n', f.read())
101     unlink(b'dest')
102     wvpassne(0, bup(b'ftp',
103                     input=jl(b'get src/latest/bad-symlink dest'),
104                     check=False, stdout=None).rc)
105     wvpassne(0, bup(b'ftp',
106                     input=jl(b'get src/latest/not-there'),
107                     check=False, stdout=None).rc)
108     
109     wvstart('mget')
110     unlink_if_exists(b'file-1')
111     bup(b'ftp', input=jl(b'mget src/latest/file-1'))
112     with open(b'file-1', 'rb') as f:
113         wvpasseq(b'excitement!\n', f.read())
114     unlink_if_exists(b'file-1')
115     unlink_if_exists(b'file-2')
116     bup(b'ftp', input=jl(b'mget src/latest/file-1 src/latest/dir/file-2'))
117     with open(b'file-1', 'rb') as f:
118         wvpasseq(b'excitement!\n', f.read())
119     with open(b'file-2', 'rb') as f:
120         wvpasseq(b'more excitement!\n', f.read())
121     unlink_if_exists(b'file-symlink')
122     bup(b'ftp', input=jl(b'mget src/latest/file-symlink'))
123     with open(b'file-symlink', 'rb') as f:
124         wvpasseq(b'excitement!\n', f.read())
125     wvpassne(0, bup(b'ftp',
126                     input=jl(b'mget src/latest/bad-symlink dest'),
127                     check=False, stdout=None).rc)
128     # bup mget currently always does pattern matching
129     bup(b'ftp', input=b'mget src/latest/not-there\n')