def tearDownClass(cls): cls.proxy.stop() cls.driver.get('http://' + get_Host_IP() + ':8083') cls.stop_calibre_web() # close the browser window and stop calibre-web cls.driver.quit() cls.p.terminate() save_logfiles(cls, cls.__name__)
def setUpClass(cls): try: host = 'http://' + get_Host_IP() + ':8083' cls.proxy = Reverse_Proxy(sitename=host) cls.proxy.start() startup(cls, cls.py_version, {'config_calibre_dir':TEST_DB}, host=host, parameter=["-i", get_Host_IP()], env={"APP_MODE": "test"}) time.sleep(3) cls.driver.get('http://127.0.0.1:8080/cw') cls.login('admin', 'admin123') except Exception: cls.driver.quit() cls.p.kill()
def test_bind_to_single_interface(self): address = get_Host_IP() p = process_open([ self.py_version, "-B", os.path.join(CALIBRE_WEB_PATH, u'cps.py'), '-i', 'http://' + address ], [1]) time.sleep(2) if p.poll() is None: p.kill() p.stdout.close() p.stderr.close() nextline = p.communicate()[0] self.assertIsNotNone(re.findall('Illegal IP address string', nextline)) p = process_open([ self.py_version, "-B", os.path.join(CALIBRE_WEB_PATH, u'cps.py'), '-i', address ], [1]) time.sleep(BOOT_TIME) # navigate to the application home page try: self.driver.switch_to.alert.accept() except Exception: pass try: error = "" self.driver.get("http://127.0.0.1:8083") except WebDriverException as e: error = e.msg self.assertTrue( re.findall( 'Reached error page:\sabout:neterror\?e=connectionFailure', error)) try: self.driver.get("http://" + address + ":8083") except WebDriverException: self.assertIsNone('Limit listening address not working') self.assertTrue(self.check_element_on_page((By.ID, "username"))) p.stdout.close() p.stderr.close() p.terminate() time.sleep(3) p.poll()
def setUpClass(cls): add_dependency(cls.json_line, cls.__name__) try: host = 'http://' + get_Host_IP() + ':8083' startup(cls, cls.py_version, {'config_calibre_dir':TEST_DB, 'config_log_level': 'DEBUG', 'config_kobo_sync':1, 'config_kepubifypath': "", 'config_kobo_proxy':0}, host=host, env={"APP_MODE": "test"}) time.sleep(3) WebDriverWait(cls.driver, 5).until(EC.presence_of_element_located((By.ID, "flash_success"))) cls.goto_page('user_setup') cls.check_element_on_page((By.ID, "config_create_kobo_token")).click() link = cls.check_element_on_page((By.CLASS_NAME, "well")) cls.kobo_adress = host + '/kobo/' + re.findall(".*/kobo/(.*)", link.text)[0] cls.check_element_on_page((By.ID, "kobo_close")).click() cls.driver.get('http://127.0.0.1:8083') cls.login('admin', 'admin123') time.sleep(2) except Exception as e: print(e) cls.driver.quit() cls.p.terminate() cls.p.poll()
def test_kobo_sync_multi_user(self): # create 2 users self.create_user( 'user1', { 'password': '******', 'email': '*****@*****.**', "edit_role": 1, "download_role": 1 }) self.create_user( 'user2', { 'password': '******', 'email': '*****@*****.**', "edit_role": 1, "download_role": 1 }) host = 'http://' + get_Host_IP() + ':8083' self.driver.get(host) # still logged in # create links for both users self.navigate_to_user("user1") self.check_element_on_page((By.ID, "config_create_kobo_token")).click() link = self.check_element_on_page((By.CLASS_NAME, "well")) user1_kobo = host + '/kobo/' + re.findall(".*/kobo/(.*)", link.text)[0] self.check_element_on_page((By.ID, "kobo_close")).click() time.sleep(1) # wait for dialog to close self.goto_page( "nav_new" ) # otherwise there is a chance that page change is not detected self.navigate_to_user("user2") self.check_element_on_page((By.ID, "config_create_kobo_token")).click() link = self.check_element_on_page((By.CLASS_NAME, "well")) user2_kobo = host + '/kobo/' + re.findall(".*/kobo/(.*)", link.text)[0] self.check_element_on_page((By.ID, "kobo_close")).click() # sync user 1 # check number of books synced (-> is done in inital_sync) self.inital_sync(user1_kobo) # sync user 2 # check number of books synced (-> is done in inital_sync) self.inital_sync(user2_kobo) # change one book self.get_book_details(104, host) self.check_element_on_page((By.ID, "edit_book")).click() self.edit_book(content={'book_title': u'Nonomatics'}) # sync both user -> both get the new book synced data1 = self.sync_kobo(user1_kobo) data2 = self.sync_kobo(user2_kobo) self.assertEqual(1, len(data1[0])) self.assertEqual(1, len(data2[0])) self.assertIn('ChangedEntitlement', data1[0][0]) self.assertIn('ChangedEntitlement', data2[0][0]) # upload one book self.fill_basic_config({'config_uploading': 1}) time.sleep(3) self.assertTrue(self.check_element_on_page((By.ID, "flash_success"))) self.goto_page('nav_new') new_epub_file = os.path.join(base_path, 'files', 'book.epub') upload = self.check_element_on_page((By.ID, 'btn-upload')) upload.send_keys(new_epub_file) time.sleep(3) self.check_element_on_page((By.ID, 'edit_cancel')).click() time.sleep(1) book_details = self.get_book_details(-1, host) # sync both user -> both get the new book synced data1 = self.sync_kobo(user1_kobo) data2 = self.sync_kobo(user2_kobo) self.assertEqual(1, len(data1[0])) self.assertEqual(1, len(data2[0])) self.assertIn('NewEntitlement', data1[0][0]) self.assertIn('NewEntitlement', data2[0][0]) self.fill_basic_config({'config_uploading': 0}) time.sleep(3) self.assertTrue(self.check_element_on_page((By.ID, "flash_success"))) # delete book to make book count as before self.delete_book(book_details['id'], host) data1 = self.sync_kobo(user1_kobo) data2 = self.sync_kobo(user2_kobo) self.assertEqual(0, len(data1[0])) self.assertEqual(0, len(data2[0])) # archive one book for user 1 in cw (is archived last_modified value?) self.logout() self.login("user1", "123") self.get_book_details(110, host) self.check_element_on_page( (By.XPATH, "//*[@id='archived_cb']")).click() # sync books for both user -> only archived for user1 data1 = self.sync_kobo(user1_kobo) data2 = self.sync_kobo(user2_kobo) self.assertEqual(1, len(data1[0])) self.assertEqual(0, len(data2[0])) self.assertIn('ChangedEntitlement', data1[0][0]) self.logout() # archive one book for user 2 on kobo self.login("user2", "321") self.get_book_details(140, host) self.check_element_on_page( (By.XPATH, "//*[@id='archived_cb']")).click() self.logout() # sync books for both user -> only archived for user2 data1 = self.sync_kobo(user1_kobo) data2 = self.sync_kobo(user2_kobo) self.assertEqual(0, len(data1[0])) self.assertEqual(1, len(data2[0])) self.assertIn('ChangedEntitlement', data2[0][0]) # create shelf for one user add books # sync books for both user -> only changed for user1 self.login("user1", "123") self.create_shelf('syncShelf', False) self.assertTrue(self.check_element_on_page((By.ID, "flash_success"))) self.get_book_details(122, host) self.check_element_on_page((By.ID, "add-to-shelf")).click() self.check_element_on_page( (By.XPATH, "//ul[@id='add-to-shelves']/li/a[contains(.,'syncShelf')]" )).click() self.get_book_details(55, host) self.check_element_on_page((By.ID, "add-to-shelf")).click() self.check_element_on_page( (By.XPATH, "//ul[@id='add-to-shelves']/li/a[contains(.,'syncShelf')]" )).click() self.logout() data1 = self.sync_kobo(user1_kobo) data2 = self.sync_kobo(user2_kobo) self.assertEqual(1, len(data1[0])) self.assertEqual(0, len(data2[0])) self.assertIn('NewTag', data1[0][0]) self.assertEqual(2, len(data1[0][0]['NewTag']['Tag']['Items'])) # switch user2 to sync selected shelfs and add books self.login("user2", "321") self.create_shelf('syncShelf2', False) self.get_book_details(122, host) self.check_element_on_page((By.ID, "add-to-shelf")).click() self.check_element_on_page( (By.XPATH, "//ul[@id='add-to-shelves']/li/a[contains(.,'syncShelf2')]" )).click() self.get_book_details(56, host) self.check_element_on_page((By.ID, "add-to-shelf")).click() self.check_element_on_page( (By.XPATH, "//ul[@id='add-to-shelves']/li/a[contains(.,'syncShelf2')]" )).click() self.change_visibility_me({"kobo_only_shelves_sync": 1}) time.sleep(40) # ToDo: Revert to 40 self.assertTrue(self.check_element_on_page((By.ID, "flash_success"))) self.change_shelf('syncShelf2', sync=1) self.logout() # sync books for both user -> only changed for user2 data1 = self.sync_kobo(user1_kobo) data2 = self.sync_kobo(user2_kobo) self.assertEqual(0, len(data1[0])) self.assertEqual(3, len(data2[0])) self.assertTrue('NewTag' in data2[0][-1]) self.assertFalse('DeletedTag' in data2[0][-2]) self.assertEqual(2, len(data2[0][2]['NewTag']['Tag']['Items'])) # Todo Fix and check user2 sync result self.login("admin", "admin123") self.edit_user("user1", {"delete": 1}) self.edit_user("user2", {"delete": 1}) self.driver.get('http://127.0.0.1:8083') # still logged in