File: application.py

package info (click to toggle)
plinth 19.1%2Bdeb10u2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 28,292 kB
  • sloc: python: 22,066; xml: 12,007; sh: 568; javascript: 406; pascal: 74; makefile: 49; php: 11
file content (425 lines) | stat: -rw-r--r-- 14,573 bytes parent folder | download
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#
# This file is part of FreedomBox.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import pytest
import splinter
from pytest_bdd import given, parsers, then, when

from support import application


@given(parsers.parse('the {app_name:w} application is installed'))
def application_is_installed(browser, app_name):
    application.install(browser, app_name)
    assert (application.is_installed(browser, app_name))


@given(parsers.parse('the {app_name:w} application is enabled'))
def application_is_enabled(browser, app_name):
    application.enable(browser, app_name)


@given(parsers.parse('the {app_name:w} application is disabled'))
def application_is_disabled(browser, app_name):
    application.disable(browser, app_name)


@given(parsers.parse('the network time application is enabled'))
def ntp_is_enabled(browser):
    application.enable(browser, 'ntp')


@given(parsers.parse('the network time application is disabled'))
def ntp_is_disabled(browser):
    application.disable(browser, 'ntp')


@when(parsers.parse('I set the time zone to {time_zone:S}'))
def time_zone_set(browser, time_zone):
    application.time_zone_set(browser, time_zone)


@then(parsers.parse('the time zone should be {time_zone:S}'))
def time_zone_assert(browser, time_zone):
    assert time_zone == application.time_zone_get(browser)


@given(parsers.parse('the service discovery application is enabled'))
def avahi_is_enabled(browser):
    application.enable(browser, 'avahi')


@given(parsers.parse('the service discovery application is disabled'))
def avahi_is_disabled(browser):
    application.disable(browser, 'avahi')


@when(parsers.parse('I enable the {app_name:w} application'))
def enable_application(browser, app_name):
    application.enable(browser, app_name)


@when(parsers.parse('I disable the {app_name:w} application'))
def disable_application(browser, app_name):
    application.disable(browser, app_name)


@when(parsers.parse('I enable the network time application'))
def enable_ntp(browser):
    application.enable(browser, 'ntp')


@when(parsers.parse('I disable the network time application'))
def disable_ntp(browser):
    application.disable(browser, 'ntp')


@when(parsers.parse('I enable the service discovery application'))
def enable_avahi(browser):
    application.enable(browser, 'avahi')


@when(parsers.parse('I disable the service discovery application'))
def disable_avahi(browser):
    application.disable(browser, 'avahi')


@given(
    parsers.parse('the domain name for {app_name:w} is set to {domain_name:S}')
)
def select_domain_name(browser, app_name, domain_name):
    application.select_domain_name(browser, app_name, domain_name)


@given('the shadowsocks application is configured')
def configure_shadowsocks(browser):
    application.configure_shadowsocks(browser, 'example.com',
                                      'fakepassword')


@when(
    parsers.parse(
        'I configure shadowsocks with server {server:S} and password {password:w}'
    ))
def configure_shadowsocks_with_details(browser, server, password):
    application.configure_shadowsocks(browser, server, password)


@then(
    parsers.parse(
        'shadowsocks should be configured with server {server:S} and password {password:w}'
    ))
def assert_shadowsocks_configuration(browser, server, password):
    assert (server,
            password) == application.shadowsocks_get_configuration(browser)


@when(
    parsers.parse('I modify the maximum file size of coquelicot to {size:d}'))
def modify_max_file_size(browser, size):
    application.modify_max_file_size(browser, size)


@then(parsers.parse('the maximum file size of coquelicot should be {size:d}'))
def assert_max_file_size(browser, size):
    assert application.get_max_file_size(browser) == size


@when(parsers.parse('I modify the coquelicot upload password to {password:w}'))
def modify_upload_password(browser, password):
    application.modify_upload_password(browser, password)


@given(parsers.parse('share {name:w} is not available'))
def remove_share(browser, name):
    application.remove_share(browser, name)


@when(parsers.parse('I add a share {name:w} from path {path} for {group:w}'))
def add_share(browser, name, path, group):
    application.add_share(browser, name, path, group)


@when(
    parsers.parse(
        'I edit share {old_name:w} to {new_name:w} from path {path} for {group:w}'
    ))
def edit_share(browser, old_name, new_name, path, group):
    application.edit_share(browser, old_name, new_name, path, group)


@when(parsers.parse('I remove share {name:w}'))
def remove_share2(browser, name):
    application.remove_share(browser, name)


@then(
    parsers.parse(
        'the share {name:w} should be listed from path {path} for {group:w}'))
def verify_share(browser, name, path, group):
    application.verify_share(browser, name, path, group)


@then(parsers.parse('the share {name:w} should not be listed'))
def verify_invalid_share(browser, name):
    with pytest.raises(splinter.exceptions.ElementDoesNotExist):
        application.get_share(browser, name)


@then(parsers.parse('the share {name:w} should be accessible'))
def access_share(browser, name):
    application.access_share(browser, name)


@then(parsers.parse('the share {name:w} should not exist'))
def verify_nonexistant_share(browser, name):
    application.verify_nonexistant_share(browser, name)


@then(parsers.parse('the share {name:w} should not be accessible'))
def verify_inaccessible_share(browser, name):
    application.verify_inaccessible_share(browser, name)


@when(parsers.parse('I enable mediawiki public registrations'))
def enable_mediawiki_public_registrations(browser):
    application.enable_mediawiki_public_registrations(browser)


@when(parsers.parse('I disable mediawiki public registrations'))
def disable_mediawiki_public_registrations(browser):
    application.disable_mediawiki_public_registrations(browser)


@when(parsers.parse('I enable mediawiki private mode'))
def enable_mediawiki_private_mode(browser):
    application.enable_mediawiki_private_mode(browser)


@when(parsers.parse('I disable mediawiki private mode'))
def disable_mediawiki_private_mode(browser):
    application.disable_mediawiki_private_mode(browser)


@when(parsers.parse('I set the mediawiki admin password to {password}'))
def set_mediawiki_admin_password(browser, password):
    application.set_mediawiki_admin_password(browser, password)


@when(parsers.parse('I enable message archive management'))
def mediawiki_enable_archive_management(browser):
    application.enable_ejabberd_message_archive_management(browser)


@when(parsers.parse('I disable message archive management'))
def mediawiki_disable_archive_management(browser):
    application.disable_ejabberd_message_archive_management(browser)


@when('there is an ikiwiki wiki')
def ikiwiki_create_wiki_if_needed(browser):
    application.ikiwiki_create_wiki_if_needed(browser)


@when('I delete the ikiwiki wiki')
def ikiwiki_delete_wiki(browser):
    application.ikiwiki_delete_wiki(browser)


@then('the ikiwiki wiki should be restored')
def ikiwiki_should_exist(browser):
    assert application.ikiwiki_wiki_exists(browser)


@given('I have added a contact to my roster')
def ejabberd_add_contact(browser):
    application.ejabberd_add_contact(browser)


@when('I delete the contact from my roster')
def ejabberd_delete_contact(browser):
    application.ejabberd_delete_contact(browser)


@then('I should have a contact on my roster')
def ejabberd_should_have_contact(browser):
    assert application.ejabberd_has_contact(browser)


@given(parsers.parse('tor relay is {enabled:w}'))
def tor_given_relay_enable(browser, enabled):
    application.tor_feature_enable(browser, 'relay', enabled)


@when(parsers.parse('I {enable:w} tor relay'))
def tor_relay_enable(browser, enable):
    application.tor_feature_enable(browser, 'relay', enable)


@then(parsers.parse('tor relay should be {enabled:w}'))
def tor_assert_relay_enabled(browser, enabled):
    application.tor_assert_feature_enabled(browser, 'relay', enabled)


@then(parsers.parse('tor {port_name:w} port should be displayed'))
def tor_assert_port_displayed(browser, port_name):
    assert port_name in application.tor_get_relay_ports(browser)


@given(parsers.parse('tor bridge relay is {enabled:w}'))
def tor_given_bridge_relay_enable(browser, enabled):
    application.tor_feature_enable(browser, 'bridge-relay', enabled)


@when(parsers.parse('I {enable:w} tor bridge relay'))
def tor_bridge_relay_enable(browser, enable):
    application.tor_feature_enable(browser, 'bridge-relay', enable)


@then(parsers.parse('tor bridge relay should be {enabled:w}'))
def tor_assert_bridge_relay_enabled(browser, enabled):
    application.tor_assert_feature_enabled(browser, 'bridge-relay', enabled)


@given(parsers.parse('tor hidden services are {enabled:w}'))
def tor_given_hidden_services_enable(browser, enabled):
    application.tor_feature_enable(browser, 'hidden-services', enabled)


@when(parsers.parse('I {enable:w} tor hidden services'))
def tor_hidden_services_enable(browser, enable):
    application.tor_feature_enable(browser, 'hidden-services', enable)


@then(parsers.parse('tor hidden services should be {enabled:w}'))
def tor_assert_hidden_services_enabled(browser, enabled):
    application.tor_assert_feature_enabled(browser, 'hidden-services', enabled)


@then(parsers.parse('tor hidden services information should be displayed'))
def tor_assert_hidden_services(browser):
    application.tor_assert_hidden_services(browser)


@given(parsers.parse('download software packages over tor is {enabled:w}'))
def tor_given_download_software_over_tor_enable(browser, enabled):
    application.tor_feature_enable(browser, 'software', enabled)


@when(parsers.parse('I {enable:w} download software packages over tor'))
def tor_download_software_over_tor_enable(browser, enable):
    application.tor_feature_enable(browser, 'software', enable)


@then(
    parsers.parse('download software packages over tor should be {enabled:w}'))
def tor_assert_download_software_over_tor(browser, enabled):
    application.tor_assert_feature_enabled(browser, 'software', enabled)


@then(
    parsers.parse(
        '{domain:S} should be a tahoe {introducer_type:w} introducer'))
def tahoe_assert_introducer(browser, domain, introducer_type):
    assert application.tahoe_get_introducer(browser, domain, introducer_type)


@then(
    parsers.parse(
        '{domain:S} should not be a tahoe {introducer_type:w} introducer'))
def tahoe_assert_not_introducer(browser, domain, introducer_type):
    assert not application.tahoe_get_introducer(browser, domain,
                                                introducer_type)


@given(parsers.parse('{domain:S} is not a tahoe introducer'))
def tahoe_given_remove_introducer(browser, domain):
    if application.tahoe_get_introducer(browser, domain, 'connected'):
        application.tahoe_remove_introducer(browser, domain)


@when(parsers.parse('I add {domain:S} as a tahoe introducer'))
def tahoe_add_introducer(browser, domain):
    application.tahoe_add_introducer(browser, domain)


@given(parsers.parse('{domain:S} is a tahoe introducer'))
def tahoe_given_add_introducer(browser, domain):
    if not application.tahoe_get_introducer(browser, domain, 'connected'):
        application.tahoe_add_introducer(browser, domain)


@when(parsers.parse('I remove {domain:S} as a tahoe introducer'))
def tahoe_remove_introducer(browser, domain):
    application.tahoe_remove_introducer(browser, domain)

@given('the access rights are set to "only the owner can view or make changes"')
def radicale_given_owner_only(browser):
    application.radicale_set_access_rights(browser, 'owner_only')

@given('the access rights are set to "any user can view, but only the owner can make changes"')
def radicale_given_owner_write(browser):
    application.radicale_set_access_rights(browser, 'owner_write')

@given('the access rights are set to "any user can view or make changes"')
def radicale_given_authenticated(browser):
    application.radicale_set_access_rights(browser, 'authenticated')

@when('I change the access rights to "only the owner can view or make changes"')
def radicale_set_owner_only(browser):
    application.radicale_set_access_rights(browser, 'owner_only')

@when('I change the access rights to "any user can view, but only the owner can make changes"')
def radicale_set_owner_write(browser):
    application.radicale_set_access_rights(browser, 'owner_write')

@when('I change the access rights to "any user can view or make changes"')
def radicale_set_authenticated(browser):
    application.radicale_set_access_rights(browser, 'authenticated')

@then('the access rights should be "only the owner can view or make changes"')
def radicale_check_owner_only(browser):
    assert application.radicale_get_access_rights(browser) == 'owner_only'

@then('the access rights should be "any user can view, but only the owner can make changes"')
def radicale_check_owner_write(browser):
    assert application.radicale_get_access_rights(browser) == 'owner_write'

@then('the access rights should be "any user can view or make changes"')
def radicale_check_authenticated(browser):
    assert application.radicale_get_access_rights(browser) == 'authenticated'


@given(parsers.parse('the openvpn application is setup'))
def openvpn_setup(browser):
    application.openvpn_setup(browser)


@given('I download openvpn profile')
def openvpn_download_profile(browser):
    return application.openvpn_download_profile(browser)


@then('the openvpn profile should be downloadable')
def openvpn_profile_downloadable(browser):
    application.openvpn_download_profile(browser)


@then('the openvpn profile downloaded should be same as before')
def openvpn_profile_download_compare(browser, openvpn_download_profile):
    new_profile = application.openvpn_download_profile(browser)
    assert openvpn_download_profile == new_profile