-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_jupyter_connect.py
113 lines (97 loc) · 4.81 KB
/
test_jupyter_connect.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
""" Selenium tests for Sunet Drive
Author: Richard Freitag <[email protected]>
Selenium tests to test apps in Sunet Drive
"""
from datetime import datetime
import xmlrunner
import unittest
import sunetnextcloud
from webdav3.client import Client
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
import os
import time
import logging
class TestJupyterSelenium(unittest.TestCase):
logger = logging.getLogger(__name__)
logging.basicConfig(format = '%(asctime)s - %(module)s.%(funcName)s - %(levelname)s: %(message)s',
datefmt = '%Y-%m-%d %H:%M:%S', level = logging.INFO)
def deleteCookies(self, driver):
cookies = driver.get_cookies()
self.logger.info(f'Deleting all cookies: {cookies}')
driver.delete_all_cookies()
cookies = driver.get_cookies()
self.logger.info(f'Cookies deleted: {cookies}')
def test_logger(self):
self.logger.info(f'self.logger.info test_logger')
pass
def test_authorize_jupyter(self):
delay = 30 # seconds
drv = sunetnextcloud.TestTarget()
for fullnode in drv.fullnodes:
with self.subTest(mynode=fullnode):
loginurl = drv.get_node_login_url(fullnode)
self.logger.info(f'URL: {loginurl}')
nodeuser = drv.get_jupyteruser(fullnode)
self.logger.info(f'Username: {nodeuser}')
nodepwd = drv.get_jupyteruserpassword(fullnode)
# Create folder for testing using webdav
url = drv.get_webdav_url(fullnode, nodeuser)
options = {
'webdav_hostname': url,
'webdav_login' : nodeuser,
'webdav_password' : nodepwd
}
client = Client(options)
dir = 'SharedFolder'
self.logger.info(f'Make and check directory: {dir}')
client.mkdir(dir)
self.assertEqual(client.list().count('SharedFolder/'), 1)
try:
options = Options()
driver = webdriver.Chrome(options=options)
except:
self.logger.error(f'Error initializing Chrome driver')
self.assertTrue(False)
driver.maximize_window()
# driver2 = webdriver.Firefox()
driver.get(loginurl)
wait = WebDriverWait(driver, delay)
wait.until(EC.presence_of_element_located((By.ID, 'user'))).send_keys(nodeuser)
wait.until(EC.presence_of_element_located((By.ID, 'password'))).send_keys(nodepwd + Keys.ENTER)
try:
wait.until(EC.presence_of_element_located((By.CLASS_NAME, 'app-menu')))
self.logger.info(f'App menu is ready!')
except TimeoutException:
self.logger.info(f'Loading of app menu took too much time!')
# Check URLs after login
dashboardUrl = drv.get_dashboard_url(fullnode)
currentUrl = driver.current_url
# self.assertEqual(dashboardUrl, currentUrl)
jupyter = driver.find_element(By.XPATH, '//a[@href="'+ '/index.php/apps/integration_jupyterhub/' +'"]')
jupyter.click()
try:
self.logger.info(f'Waiting for jupyter iframe')
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, '//*[@id="content"]/iframe')))
self.logger.info('Jupyter iframe loaded')
except:
self.logger.error(f'Jupyter iframe not loaded')
try:
self.logger.info(f'Authorizing Jupyter app')
wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="login-form"]/input'))).click()
self.logger.info(f'Logged in to jupyter app')
wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="submit-wrapper"]/input'))).click()
self.logger.info(f'Authorization granted')
except:
self.logger.error(f'Error authorizing JupyterHub app')
self.logger.info(f'Done...')
time.sleep(2)
if __name__ == '__main__':
# unittest.main()
unittest.main(testRunner=xmlrunner.XMLTestRunner(output='test-reports'))