-
Notifications
You must be signed in to change notification settings - Fork 19
/
integration_test.py
163 lines (146 loc) · 6.16 KB
/
integration_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import unittest
from ftpretty import ftpretty
import shutil
import os
conn = ftpretty('127.0.0.1', 'test', 'test')
class FtprettyIntegration(unittest.TestCase):
def test_get(self):
self.assertEqual([], conn.list(extra=True))
conn.put(None, 'b/b.txt', b'blah')
self.assertEqual(set(['b.txt']), set([f.name for f in conn.list('b', extra=True)]))
contents = conn.get('b/b.txt')
self.assertEqual(b'blah', contents)
conn.delete('b/b.txt')
conn.delete('b')
def test_put(self):
self.assertEqual([], conn.list(extra=True))
conn.put(None, 'a.txt', b'blah')
conn.put(None, 'b/b.txt', b'blah')
self.assertEqual(set(['a.txt', 'b']), set([f.name for f in conn.list(extra=True)]))
self.assertEqual(set(['b.txt']), set([f.name for f in conn.list('b', extra=True)]))
conn.delete('a.txt')
conn.delete('b/b.txt')
conn.delete('b')
self.assertEqual([], conn.list(extra=True))
def test_put_tree(self):
os.mkdir('testdata')
os.mkdir('testdata/a')
os.mkdir('testdata/a/b')
os.mkdir('testdata/a/b/c')
with open('testdata/a/a.txt', 'wb') as fh:
fh.write(b'blah')
with open('testdata/a/b/b.txt', 'wb') as fh:
fh.write(b'blah')
with open('testdata/a/b/c/c.txt', 'wb') as fh:
fh.write(b'blah')
conn.put_tree('testdata', '.')
conn.descend('a/b/c')
self.assertEqual(set(['c.txt']), set([f.name for f in conn.list(extra=True)]))
conn.delete('c.txt')
conn.cd('..')
self.assertEqual(set(['c','b.txt']), set([f.name for f in conn.list(extra=True)]))
conn.delete('c')
conn.delete('b.txt')
conn.cd('..')
self.assertEqual(set(['b', 'a.txt']), set([f.name for f in conn.list(extra=True)]))
conn.delete('b')
conn.delete('a.txt')
conn.cd('..')
self.assertEqual(set(['a']), set([f.name for f in conn.list(extra=True)]))
conn.delete('a')
self.assertEqual([], conn.list(extra=True))
shutil.rmtree("testdata")
def test_get_tree(self):
conn.put(None, 'a/b/c/c.log', b'log content')
conn.put(None, 'a/b/b.log', b'log content')
conn.put(None, 'a/a.log', b'log content')
os.mkdir('testdata')
conn.get_tree('.', 'testdata')
self.assertTrue(os.path.exists('testdata/a/b/c/c.log'))
self.assertTrue(os.path.exists('testdata/a/b/b.log'))
self.assertTrue(os.path.exists('testdata/a/a.log'))
conn.delete('a/b/c/c.log')
conn.delete('a/b/c')
conn.delete('a/b/b.log')
conn.delete('a/b')
conn.delete('a/a.log')
conn.delete('a')
self.assertEqual([], conn.list(extra=True))
shutil.rmtree("testdata")
def test_list(self):
self.assertEqual([], conn.list(extra=True))
conn.put(None, 'a.txt', b'blah')
conn.put(None, 'b/b.txt', b'blah')
self.assertEqual(set(['a.txt', 'b']), set([f.name for f in conn.list(extra=True)]))
self.assertEqual(set(['b.txt']), set([f.name for f in conn.list('b', extra=True)]))
conn.delete('a.txt')
conn.delete('b/b.txt')
conn.delete('b')
self.assertEqual([], conn.list(extra=True))
def test_descend(self):
conn.put(None, 'a/deeply/nested/folder/file.log', b'log content')
conn.descend('a/deeply/nested/folder')
self.assertEqual(set(['file.log']), set([f.name for f in conn.list(extra=True)]))
content = conn.get('file.log')
self.assertEqual(b'log content', content)
conn.cd('../../../..')
conn.delete('a/deeply/nested/folder/file.log')
self.assertEqual([], conn.list('a/deeply/nested/folder', extra=True))
conn.delete('a/deeply/nested/folder')
conn.delete('a/deeply/nested')
conn.delete('a/deeply')
conn.delete('a')
self.assertEqual([], conn.list(extra=True))
def test_delete(self):
self.assertEqual([], conn.list(extra=True))
conn.put(None, 'b/b.txt', b'blah')
self.assertEqual(set(['b.txt']), set([f.name for f in conn.list('b', extra=True)]))
conn.delete('b/b.txt')
conn.delete('b')
self.assertEqual([], conn.list(extra=True))
def test_cd(self):
conn.put(None, 'a/deeply/nested/folder/file.log', b'log content')
conn.cd('a')
conn.cd('deeply/nested')
conn.cd('folder')
self.assertEqual(set(['file.log']), set([f.name for f in conn.list(extra=True)]))
conn.cd('..')
self.assertEqual(set(['folder']), set([f.name for f in conn.list(extra=True)]))
conn.cd('../../..')
conn.delete('a/deeply/nested/folder/file.log')
conn.delete('a/deeply/nested/folder')
conn.delete('a/deeply/nested')
conn.delete('a/deeply')
conn.delete('a')
self.assertEqual([], conn.list(extra=True))
def test_pwd(self):
conn.put(None, 'a/deeply/nested/folder/file.log', b'log content')
conn.cd('a')
conn.cd('deeply/nested')
conn.cd('folder')
self.assertEqual('/a/deeply/nested/folder', conn.pwd())
conn.cd('../../../..')
conn.delete('a/deeply/nested/folder/file.log')
conn.delete('a/deeply/nested/folder')
conn.delete('a/deeply/nested')
conn.delete('a/deeply')
conn.delete('a')
self.assertEqual([], conn.list(extra=True))
def test_rename(self):
conn.put(None, 'file.log', b'log content')
conn.rename('file.log', 'renamed.txt')
self.assertEqual(set(['renamed.txt']), set([f.name for f in conn.list(extra=True)]))
conn.delete('renamed.txt')
self.assertEqual([], conn.list(extra=True))
def test_mkdir(self):
conn.mkdir('a')
self.assertEqual(set(['a']), set([f.name for f in conn.list(extra=True)]))
conn.delete('a')
self.assertEqual([], conn.list(extra=True))
def suite():
loader = unittest.TestLoader()
suite = unittest.TestSuite()
suite.addTest(loader.loadTestsFromTestCase(FtprettyIntegration))
return suite
if __name__ == '__main__':
unittest.TextTestRunner(verbosity=2).run(suite())