Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tests.py « tests - github.com/nextcloud/nextcloudpi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 47207ecf0d044919ac063e9b7985435422ab6905 (plain)
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
#!/usr/bin/env python3

# Automatic testing for NextCloudPi
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#
#   ./tests.py <IP>
#
# More at https://ownyourbits.com
#

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
import unittest
import pexpect
import sys
import time


IP = sys.argv[1]

#
# Login as Admin user and assert that all internal checks pass ( All checks passed! tick  )
# Also checks for correct trusted domain setting
#

class AdminWebTest(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Firefox()

    #@unittest.skip("Skipping...")
    def test_login(self):
        driver = self.driver
        driver.implicitly_wait(150) # first run can be really slow on QEMU
        driver.get("https://" + IP + "/index.php/settings/admin")
        self.assertIn("Nextcloud", driver.title)
        self.assertNotIn ( "You are accessing the server from an untrusted domain" , driver.page_source )
        driver.find_element_by_id("user").send_keys("admin")
        driver.find_element_by_id("password").send_keys("ownyourbits")
        driver.find_element_by_id("submit").click()
        self.assertNotIn ( "Wrong password" , driver.page_source )

        wait = WebDriverWait(driver, 150)
        element = wait.until(EC.visibility_of(driver.find_element_by_class_name("icon-checkmark")))

    def tearDown(self):
        self.driver.close()


#
# Create a user, then navigate a little bit
#

class CreateUserTest(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Firefox()

    #@unittest.skip("Skipping...")
    def test_login(self):
        driver = self.driver
        driver.get("https://" + IP + "/index.php/settings/users")

        driver.find_element_by_id("user").send_keys("admin")
        driver.find_element_by_id("password").send_keys("ownyourbits")
        driver.find_element_by_id("submit").click()
        self.assertNotIn ( "Wrong password" , driver.page_source )

        wait = WebDriverWait(driver, 150)
        wait.until(lambda driver: driver.find_element_by_id("newusername"))

        driver.find_element_by_id("newusername").send_keys("test_user1")
        driver.find_element_by_id("newuserpassword").send_keys("ownyourbits")
        driver.find_element_by_id("newuserpassword").send_keys(Keys.RETURN)

        time.sleep( 5 )

        # navigate a little bit
        driver.get("https://" + IP + "/index.php/settings/admin")
        self.assertIn("Nextcloud", driver.title)
        driver.get("https://" + IP + "/index.php/settings/apps")
        self.assertIn("Nextcloud", driver.title)

    def tearDown(self):
        self.driver.close()

#
# Login as the newly created user and check that we are in the Files App
#

class LoginNewUserTest(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Firefox()

    #@unittest.skip("Skipping...")
    def test_login(self):
        driver = self.driver
        driver.get("https://" + IP)

        self.assertIn("Nextcloud", driver.title)
        driver.find_element_by_id("user").send_keys("test_user1")
        driver.find_element_by_id("password").send_keys("ownyourbits")
        driver.find_element_by_id("submit").click()

        wait = WebDriverWait(driver, 60)
        wait.until(lambda driver: driver.find_element_by_id("fileList"))

        # navigate a little bit
        driver.get("https://" + IP + "/index.php/settings/personal")
        self.assertIn("Nextcloud", driver.title)

    def tearDown(self):
        self.driver.close()

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print( "IP argument required" )
        sys.exit()

    unittest.main(argv=['first-arg-is-ignored'],verbosity=2)

# License
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA