Skip to content

Commit

Permalink
tests: review style and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nacho committed Aug 10, 2017
1 parent 101c9d9 commit 5894514
Showing 1 changed file with 46 additions and 40 deletions.
86 changes: 46 additions & 40 deletions tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,74 +1,77 @@
#!/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
#
"""
Automatic testing for NextCloudPi
Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
GPL licensed (see LICENSE file in repository root).
Use at your own risk!
./tests.py <IP>
More at https://ownyourbits.com
"""

import unittest
import sys
import time
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):
"""
Log as admin and assert that all internal checks pass ("All checks passed!")
Also checks for correct trusted domain setting
"""

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

#@unittest.skip("Skipping...")
def test_login(self):
# @unittest.skip("Skipping...")
def test_admin_checks(self):
""" Login and assert admin page checks"""
driver = self.driver
driver.implicitly_wait(150) # first run can be really slow on QEMU
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 )
trusted_domain_str = "You are accessing the server from an untrusted domain"
self.assertNotIn(trusted_domain_str, 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 )
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")))
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):
"""
Create a user, then navigate a little bit
"""

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

#@unittest.skip("Skipping...")
def test_login(self):
# @unittest.skip("Skipping...")
def test_user_creation(self):
""" Create user test_user1 """
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 )
self.assertNotIn("Wrong password", driver.page_source)

wait = WebDriverWait(driver, 150)
wait.until(lambda driver: driver.find_element_by_id("newusername"))
Expand All @@ -77,7 +80,7 @@ def test_login(self):
driver.find_element_by_id("newuserpassword").send_keys("ownyourbits")
driver.find_element_by_id("newuserpassword").send_keys(Keys.RETURN)

time.sleep( 5 )
time.sleep(5)

# navigate a little bit
driver.get("https://" + IP + "/index.php/settings/admin")
Expand All @@ -88,26 +91,29 @@ def test_login(self):
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):
"""
Login as the newly created user and check that we are in the Files App
"""

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

#@unittest.skip("Skipping...")
def test_login(self):
# @unittest.skip("Skipping...")
def test_user_login(self):
""" Login as test_user1 """
driver = self.driver
driver.implicitly_wait(210) # first run can be really slow on QEMU
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)
time.sleep(60) # first run can be really slow on QEMU
wait = WebDriverWait(driver, 210)
wait.until(lambda driver: driver.find_element_by_id("fileList"))

# navigate a little bit
Expand All @@ -117,12 +123,13 @@ def test_login(self):
def tearDown(self):
self.driver.close()


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

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

# License
#
Expand All @@ -140,4 +147,3 @@ def tearDown(self):
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA

0 comments on commit 5894514

Please sign in to comment.