-
Notifications
You must be signed in to change notification settings - Fork 671
/
Copy pathaccount_context.py
353 lines (261 loc) · 10.5 KB
/
account_context.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
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
from pageObjects.AccountConnectionWizard import AccountConnectionWizard
from pageObjects.SyncConnectionWizard import SyncConnectionWizard
from pageObjects.EnterPassword import EnterPassword
from pageObjects.Toolbar import Toolbar
from pageObjects.AccountSetting import AccountSetting
from helpers.SetupClientHelper import (
setUpClient,
startClient,
substituteInLineCodes,
getClientDetails,
generate_account_config,
getResourcePath,
)
from helpers.UserHelper import getDisplaynameForUser, getPasswordForUser
from helpers.SyncHelper import waitForInitialSyncToComplete, listenSyncStatusForItem
from helpers.ConfigHelper import get_config, isWindows, isLinux
@When('the user adds the following user credentials:')
def step(context):
account_details = getClientDetails(context)
AccountConnectionWizard.addUserCreds(
account_details['user'], account_details['password']
)
@Then('the account with displayname "|any|" and host "|any|" should be displayed')
def step(context, displayname, host):
displayname = substituteInLineCodes(displayname)
host = substituteInLineCodes(host)
test.compare(
Toolbar.getDisplayedAccountText(displayname, host),
displayname + "\n" + host,
)
@Then('the account with displayname "|any|" and host "|any|" should not be displayed')
def step(context, displayname, host):
displayname = substituteInLineCodes(displayname)
host = substituteInLineCodes(host)
account_title = displayname + "\n" + host
timeout = get_config("lowestSyncTimeout") * 1000
test.compare(
False,
Toolbar.hasItem(account_title, timeout),
f"Expected account '{displayname}' to be removed",
)
@Given('user "|any|" has set up a client with default settings')
def step(context, username):
password = getPasswordForUser(username)
setUpClient(username)
enter_password = EnterPassword()
if get_config('ocis'):
enter_password.accept_certificate()
enter_password.loginAfterSetup(username, password)
# wait for files to sync
waitForInitialSyncToComplete(getResourcePath('/', username))
@Given('the user has set up the following accounts with default settings:')
def step(context):
users = []
for row in context.table:
users.append(row[0])
sync_paths = generate_account_config(users)
startClient()
if get_config('ocis'):
# accept certificate for each user
for idx, _ in enumerate(users):
enter_password = EnterPassword(len(users) - idx)
enter_password.accept_certificate()
for idx, sync_path in enumerate(sync_paths.values()):
# login from last dialog
account_idx = len(sync_paths) - idx
enter_password = EnterPassword(account_idx)
username = enter_password.get_username()
password = getPasswordForUser(username)
listenSyncStatusForItem(sync_paths[username])
enter_password.loginAfterSetup(username, password)
# wait for files to sync
waitForInitialSyncToComplete(sync_paths[username])
@Given('the user has started the client')
def step(context):
startClient()
@When('the user starts the client')
def step(context):
startClient()
@When('the user opens the add-account dialog')
def step(context):
Toolbar.openNewAccountSetup()
@When('the user adds the following account:')
def step(context):
account_details = getClientDetails(context)
AccountConnectionWizard.addAccount(account_details)
# wait for files to sync
waitForInitialSyncToComplete(getResourcePath('/', account_details["user"]))
@Given('the user has entered the following account information:')
def step(context):
account_details = getClientDetails(context)
AccountConnectionWizard.addAccountInformation(account_details)
@When('the user "|any|" logs out of the client-UI')
def step(context, username):
AccountSetting.logout()
@Then('user "|any|" should be signed out')
def step(context, username):
displayname = getDisplaynameForUser(username)
server = get_config('localBackendUrl')
test.compare(
AccountSetting.isUserSignedOut(displayname, server),
True,
"User '%s' is signed out" % username,
)
@Given('user "|any|" has logged out of the client-UI')
def step(context, username):
AccountSetting.logout()
displayname = getDisplaynameForUser(username)
server = get_config('localBackendUrl')
if not AccountSetting.isUserSignedOut(displayname, server):
raise Exception("Failed to logout user '%s'" % username)
@When('user "|any|" logs in to the client-UI')
def step(context, username):
AccountSetting.login()
password = getPasswordForUser(username)
enter_password = EnterPassword()
enter_password.reLogin(username, password)
# wait for files to sync
waitForInitialSyncToComplete(getResourcePath('/', username))
@When('user "|any|" logs in to the client-UI with oauth2')
def step(context, username):
AccountSetting.login()
password = getPasswordForUser(username)
enter_password = EnterPassword()
enter_password.reLogin(username, password, True)
# wait for files to sync
waitForInitialSyncToComplete(getResourcePath('/', username))
@When('user "|any|" opens login dialog')
def step(context, username):
AccountSetting.login()
@When('user "|any|" enters the password "|any|"')
def step(context, username, password):
enter_password = EnterPassword()
enter_password.reLogin(username, password)
@Then('user "|any|" should be connect to the client-UI')
def step(context, username):
displayname = getDisplaynameForUser(username)
server = get_config('localBackendUrl')
AccountSetting.waitUntilAccountIsConnected(displayname, server)
AccountSetting.wait_until_sync_folder_is_configured()
@When('the user removes the connection for user "|any|" and host |any|')
def step(context, username, host):
displayname = getDisplaynameForUser(username)
displayname = substituteInLineCodes(displayname)
host = substituteInLineCodes(host)
Toolbar.openAccount(displayname, host)
AccountSetting.removeAccountConnection()
@Then('connection wizard should be visible')
def step(context):
test.compare(
AccountConnectionWizard.isNewConnectionWindowVisible(),
True,
"Connection window is visible",
)
@When('the user accepts the certificate')
def step(context):
AccountConnectionWizard.acceptCertificate()
@Then('the error "|any|" should be displayed in the account connection wizard')
def step(context, errorMsg):
test.verify(errorMsg in AccountConnectionWizard.getErrorMessage())
@When('the user adds the server "|any|"')
def step(context, server):
server_url = substituteInLineCodes(server)
AccountConnectionWizard.addServer(server_url)
@When('the user selects manual sync folder option in advanced section')
def step(context):
AccountConnectionWizard.selectManualSyncFolderOption()
AccountConnectionWizard.nextStep()
@Then("credentials wizard should be visible")
def step(context):
test.compare(
AccountConnectionWizard.isCredentialWindowVisible(),
True,
"Credentials wizard is visible",
)
@When('the user selects vfs option in advanced section')
def step(context):
AccountConnectionWizard.selectVFSOption()
AccountConnectionWizard.nextStep()
@When('the user selects download everything option in advanced section')
def step(context):
AccountConnectionWizard.selectDownloadEverythingOption()
AccountConnectionWizard.nextStep()
@When("the user opens the advanced configuration")
def step(context):
AccountConnectionWizard.selectAdvancedConfig()
@Then("the user should be able to choose the local download directory")
def step(context):
test.compare(True, AccountConnectionWizard.canChangeLocalSyncDir())
@Then("the download everything option should be selected by default for Linux")
def step(context):
if isLinux():
test.compare(
True,
AccountConnectionWizard.isSyncEverythingOptionChecked(),
"Sync everything option is checked",
)
@Then("the VFS option should be selected by default for Windows")
def step(context):
if isWindows():
test.compare(
True,
AccountConnectionWizard.isVFSOptionChecked(),
"VFS option is checked",
)
@When(r'^the user presses the "([^"]*)" key(?:s)?', regexp=True)
def step(context, key):
AccountSetting.pressKey(key)
@Then('the log dialog should be opened')
def step(context):
test.compare(True, AccountSetting.isLogDialogVisible(), "Log dialog is opened")
@When('the user adds the following oauth2 account:')
def step(context):
account_details = getClientDetails(context)
account_details.update({'oauth': True})
AccountConnectionWizard.addAccount(account_details)
# wait for files to sync
waitForInitialSyncToComplete(getResourcePath('/', account_details["user"]))
@Step('the user cancels the sync connection wizard')
def step(context):
SyncConnectionWizard.cancelFolderSyncConnectionWizard()
@When('user "|any|" logs out from the login required dialog')
def step(context, username):
enter_password = EnterPassword()
enter_password.logout()
@When("the user quits the client")
def step(context):
Toolbar.quit_owncloud()
@Then('"|any|" account should be opened')
def step(context, displayname):
displayname = substituteInLineCodes(displayname)
host = substituteInLineCodes("%local_server_hostname%")
account = displayname + "\n" + host
has_focus = Toolbar.account_has_focus(account)
if not has_focus:
raise LookupError(f"Account '{displayname}' should be opened, but it is not")
@Then(
r'the default local sync path should contain "([^"]*)" in the (configuration|sync connection) wizard',
regexp=True,
)
def step(context, sync_path, wizard):
sync_path = substituteInLineCodes(sync_path)
actual_sync_path = ""
if wizard == 'configuration':
actual_sync_path = AccountConnectionWizard.get_local_sync_path()
else:
actual_sync_path = SyncConnectionWizard.get_local_sync_path()
test.compare(
actual_sync_path,
sync_path,
"Compare sync path contains the expected path",
)
@Then('the warning "|any|" should appear in the sync connection wizard')
def step(context, warn_message):
actual_message = SyncConnectionWizard.get_warn_label()
contains_warning = True if warn_message in actual_message else False
test.compare(
True,
contains_warning,
"Contains warning message",
)