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
|
from os.path import dirname, join
import pytest
from lektor_ng.publisher import RsyncPublisher
def test_get_server(env):
server = env.load_config().get_server("production")
assert server.name == "Production"
assert server.name_i18n["de"] == "Produktion"
assert server.target == "rsync://myserver.com/path/to/website"
assert server.extra == {"extra_field": "extra_value"}
def test_rsync_command_credentials(tmpdir, mocker, env):
output_path = tmpdir.mkdir("output")
publisher = RsyncPublisher(env, str(output_path))
target_url = "http://example.com"
credentials = {
"username": "fakeuser",
"password": "fakepass",
}
mock_popen = mocker.patch("lektor_ng.publisher.portable_popen")
with publisher.get_command(target_url, credentials):
assert mock_popen.called
assert mock_popen.call_args[0] == (
[
"rsync",
"-rclzv",
"--exclude=.lektor",
str(output_path) + "/",
"fakeuser@example.com:/",
],
)
output_path = join(dirname(__file__), "OUTPUT_PATH")
@pytest.mark.parametrize(
"target_url,called_command",
[
(
"http://example.com",
[
"rsync",
"-rclzv",
"--exclude=.lektor",
str(output_path) + "/",
"example.com:/",
],
),
(
"http://fakeuser@example.com",
[
"rsync",
"-rclzv",
"--exclude=.lektor",
str(output_path) + "/",
"fakeuser@example.com:/",
],
),
(
"http://example.com?exclude=file",
[
"rsync",
"-rclzv",
"--exclude=.lektor",
"--exclude",
"file",
str(output_path) + "/",
"example.com:/",
],
),
(
"http://example.com?exclude=file_one&exclude=file_two",
[
"rsync",
"-rclzv",
"--exclude=.lektor",
"--exclude",
"file_one",
"--exclude",
"file_two",
str(output_path) + "/",
"example.com:/",
],
),
(
"""http://example.com?exclude='user's "special" file name'""",
[
"rsync",
"-rclzv",
"--exclude=.lektor",
"--exclude",
"'user's \"special\" file name'",
str(output_path) + "/",
"example.com:/",
],
),
(
'http://example.com?exclude="file name"',
[
"rsync",
"-rclzv",
"--exclude=.lektor",
"--exclude",
'"file name"',
str(output_path) + "/",
"example.com:/",
],
),
(
"http://example.com?delete",
[
"rsync",
"-rclzv",
"--exclude=.lektor",
"--delete-after",
str(output_path) + "/",
"example.com:/",
],
),
(
"http://example.com?delete=yes",
[
"rsync",
"-rclzv",
"--exclude=.lektor",
"--delete-after",
str(output_path) + "/",
"example.com:/",
],
),
(
"http://example.com?delete=no",
[
"rsync",
"-rclzv",
"--exclude=.lektor",
str(output_path) + "/",
"example.com:/",
],
),
(
"file:///path/to/directory",
[
"rsync",
"-rclzv",
"--exclude=.lektor",
str(output_path) + "/",
"/path/to/directory/",
],
),
],
)
def test_rsync_publisher(target_url, called_command, tmpdir, mocker, env):
publisher = RsyncPublisher(env, str(output_path))
mock_popen = mocker.patch("lektor_ng.publisher.portable_popen")
with publisher.get_command(target_url, credentials=None):
assert mock_popen.called
assert mock_popen.call_args[0] == (called_command,)
|