-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathfiles.py
More file actions
102 lines (82 loc) · 3.64 KB
/
files.py
File metadata and controls
102 lines (82 loc) · 3.64 KB
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
from mock import call, patch
from patchwork.files import directory, append, contains
class files:
class directory_:
def base_case_creates_dir_with_dash_p(self, cxn):
directory(cxn, "/some/dir")
cxn.run.assert_called_once_with('mkdir -p "/some/dir"')
def creates_dir_with_double_quotes(self, cxn):
directory(cxn, '/some/double"quote')
cxn.run.assert_called_once_with('mkdir -p "/some/double\\"quote"')
def user_sets_owner_and_group(self, cxn):
directory(cxn, "/some/dir", user="user")
cxn.run.assert_any_call('chown "user:user" "/some/dir"')
def group_may_be_given_to_change_group(self, cxn):
directory(cxn, "/some/dir", user="user", group="admins")
cxn.run.assert_any_call('chown "user:admins" "/some/dir"')
def mode_adds_a_chmod(self, cxn):
directory(cxn, "/some/dir", mode="0700")
cxn.run.assert_any_call('chmod "0700" "/some/dir"')
def all_args_in_play(self, cxn):
directory(
cxn, "/some/dir", user="user", group="admins", mode="0700"
)
assert cxn.run.call_args_list == [
call('mkdir -p "/some/dir"'),
call('chown "user:admins" "/some/dir"'),
call('chmod "0700" "/some/dir"'),
]
def contains_issue34(self, cxn):
contains(cxn, "/some/file", "'*'")
cxn.run.assert_any_call(
r'''egrep "'\\*'" "/some/file"''',
hide=True, warn=True
)
def contains_trailing_dollar(self, cxn):
contains(cxn, "/some/file", "trailing $")
cxn.run.assert_called_once_with(
r'egrep "trailing \\\$" "/some/file"',
hide=True, warn=True
)
def contains_trailing_backslash(self, cxn):
contains(cxn, "/some/file", "trailing \\")
cxn.run.assert_called_once_with(
r'egrep "trailing \\\\" "/some/file"',
hide=True, warn=True
)
@patch('patchwork.files.contains')
def append_ending_single_quote(self, m, cxn):
m.return_value = False
append(cxn, "/some/file", "alias l='ls -rtl'")
cxn.run.assert_any_call(
'echo \'alias l=\'\\\'\'ls -rtl\'\\\'\'\' >> "/some/file"'
)
@patch('patchwork.files.contains')
def append_trailing_dollar(self, m, cxn):
m.return_value = False
append(cxn, "/some/file", "trailing $")
cxn.run.assert_any_call(
r'''echo 'trailing $' >> "/some/file"''',
)
@patch('patchwork.files.contains')
def append_trailing_backslash(self, m, cxn):
m.return_value = False
append(cxn, "/some/file", "trailing \\")
assert cxn.run.call_args_list == [
call('test -e "$(echo /some/file)"', hide=True, warn=True),
call(r'''echo 'trailing \' >> "/some/file"''')
]
@patch('patchwork.files.contains')
def append_trailing_backtick(self, m, cxn):
m.return_value = False
append(cxn, "/some/file", "trailing `")
cxn.run.assert_any_call(
r'''echo 'trailing `' >> "/some/file"'''
)
@patch('patchwork.files.contains')
def append_issue_34(self, m, cxn):
m.return_value = False
append(cxn, "/some/file", "listen_addresses='*'", escape=True)
cxn.run.assert_any_call(
'echo \'listen_addresses=\'\\\'\'*\'\\\'\'\' >> "/some/file"'
)