Esempio n. 1
0
def teardown():
    config = ConfigParser()
    config.read(conf_path)
    config['setup']['initial_setup'] = 'true'
    config['auth']['method'] = 'local'
    config['ldap']['server'] = ''
    config['ldap']['port'] = ''
    config['ldap']['base_dn'] = ''
    config['redpen']['java_home'] = ''
    config['redpen']['conf'] = ''
    config['dev']['check_csrf'] = 'true'
    f = open(conf_path, 'w')
    config.write(f)
    f.close()

    con = sqlite3.connect(db_path)
    cur = con.cursor()
    sql = 'UPDATE user SET username=(?), password=(?) WHERE username=(?)'
    cur.execute(sql, ('Admin', gen_pass_hash('webtex'), 'test-user',))
    con.commit()
    cur.close()
    con.close()

    res = client.get('/')
    eq_(302, res.status_code)
    eq_('http://localhost/login', res.headers['Location'])

    res = client.get('/initialize')
    eq_(302, res.status_code)
    eq_('http://localhost/login', res.headers['Location'])

    res = client.get('/login')
    eq_(200, res.status_code)
Esempio n. 2
0
def init():
    config = ConfigParser()
    config.read(conf_path)
    config['setup']['initial_setup'] = 'true'
    config['auth']['method'] = 'local'
    config['ldap']['server'] = ''
    config['ldap']['port'] = ''
    config['ldap']['base_dn'] = ''
    config['redpen']['java_home'] = ''
    config['redpen']['conf'] = ''
    config['dev']['check_csrf'] = 'true'
    f = open(conf_path, 'w')
    config.write(f)
    f.close()

    con = sqlite3.connect(db_path)
    cur = con.cursor()
    sql = 'DELETE FROM user'
    cur.execute(sql)
    con.commit()
    sql = 'INSERT INTO user VALUES(?,?)'
    cur.execute(sql, ('Admin', gen_pass_hash('webtex')))
    con.commit()
    cur.close()
    con.close()
Esempio n. 3
0
def test_login_logout():
    driver = webdriver.PhantomJS()
    wait = WebDriverWait(driver, 5)

    driver.get('http://localhost:8080/')
    wait.until(ec.presence_of_all_elements_located)
    eq_('http://localhost:8080/login', driver.current_url)

    driver.get('http://localhost:8080/initialize')
    wait.until(ec.presence_of_all_elements_located)
    eq_('http://localhost:8080/login', driver.current_url)

    show_signin = driver.find_element_by_id('showSignIn')
    show_signin.click()

    wait.until(ec.visibility_of_element_located((By.ID, 'username')))
    username = driver.find_element_by_id('username')
    username.send_keys('Admin')

    wait.until(ec.visibility_of_element_located((By.ID, 'password')))
    password = driver.find_element_by_id('password')
    password.send_keys('webtex')

    wait.until(ec.visibility_of_element_located((By.ID, 'signIn')))
    signin = driver.find_element_by_id('signIn')
    signin.click()

    wait.until(ec.presence_of_all_elements_located)
    eq_('http://localhost:8080/initialize', driver.current_url)

    user_name = driver.find_element_by_id('user-name')
    user_name.send_keys('test-user')
    user_pass = driver.find_element_by_id('user-password')
    user_pass.send_keys('test-pass')

    java_home = driver.find_element_by_id('java_home')
    java_home.send_keys('/usr/lib/jvm/java-8-oracle')

    redpen_path = driver.find_element_by_id('redpen_path')
    redpen_path.send_keys(
        os.path.expanduser('~/redpen/conf/redpen-conf-en.xml'))

    initialize_ok = driver.find_element_by_id('OK')
    initialize_ok.click()
    wait.until(ec.presence_of_all_elements_located)

    show_signin = driver.find_element_by_id('showSignIn')
    show_signin.click()

    wait.until(ec.visibility_of_element_located((By.ID, 'username')))
    username = driver.find_element_by_id('username')
    username.send_keys('test-user')

    wait.until(ec.visibility_of_element_located((By.ID, 'password')))
    password = driver.find_element_by_id('password')
    password.send_keys('test-pass')

    wait.until(ec.visibility_of_element_located((By.ID, 'signIn')))
    signin = driver.find_element_by_id('signIn')
    signin.click()

    wait.until(ec.presence_of_all_elements_located)
    print(driver.current_url)
    eq_('http://localhost:8080/', driver.current_url)
    logout = driver.find_element_by_id('logout')
    logout.click()

    wait.until(ec.presence_of_all_elements_located)
    print(driver.current_url)
    eq_('http://localhost:8080/login', driver.current_url)
    driver.close()

    config = ConfigParser()
    config.read(conf_path)
    config['setup']['initial_setup'] = 'true'
    config['auth']['method'] = 'local'
    config['ldap']['server'] = ''
    config['ldap']['port'] = ''
    config['ldap']['base_dn'] = ''
    config['redpen']['java_home'] = ''
    config['redpen']['conf'] = ''
    f = open(conf_path, 'w')
    config.write(f)
    f.close()

    con = sqlite3.connect(db_path)
    cur = con.cursor()
    sql = 'UPDATE user SET username=(?), password=(?) WHERE username=(?)'
    cur.execute(sql, ('Admin', gen_pass_hash('webtex'), 'test-user',))
    con.commit()
    cur.close()
    con.close()
Esempio n. 4
0
def test_login_logout():
    driver = webdriver.PhantomJS()
    wait = WebDriverWait(driver, 5)

    driver.get('http://localhost:8080/')
    wait.until(ec.presence_of_all_elements_located)
    eq_('http://localhost:8080/login', driver.current_url)

    driver.get('http://localhost:8080/initialize')
    wait.until(ec.presence_of_all_elements_located)
    eq_('http://localhost:8080/login', driver.current_url)

    show_signin = driver.find_element_by_id('showSignIn')
    show_signin.click()

    wait.until(ec.visibility_of_element_located((By.ID, 'username')))
    username = driver.find_element_by_id('username')
    username.send_keys('Admin')

    wait.until(ec.visibility_of_element_located((By.ID, 'password')))
    password = driver.find_element_by_id('password')
    password.send_keys('webtex')

    wait.until(ec.visibility_of_element_located((By.ID, 'signIn')))
    signin = driver.find_element_by_id('signIn')
    signin.click()

    wait.until(ec.presence_of_all_elements_located)
    eq_('http://localhost:8080/initialize', driver.current_url)

    user_name = driver.find_element_by_id('user-name')
    user_name.send_keys('test-user')
    user_pass = driver.find_element_by_id('user-password')
    user_pass.send_keys('test-pass')

    java_home = driver.find_element_by_id('java_home')
    java_home.send_keys('/usr/lib/jvm/java-8-oracle')

    redpen_path = driver.find_element_by_id('redpen_path')
    redpen_path.send_keys(
        os.path.expanduser('~/redpen/conf/redpen-conf-en.xml'))

    initialize_ok = driver.find_element_by_id('OK')
    initialize_ok.click()
    wait.until(ec.presence_of_all_elements_located)

    show_signin = driver.find_element_by_id('showSignIn')
    show_signin.click()

    wait.until(ec.visibility_of_element_located((By.ID, 'username')))
    username = driver.find_element_by_id('username')
    username.send_keys('test-user')

    wait.until(ec.visibility_of_element_located((By.ID, 'password')))
    password = driver.find_element_by_id('password')
    password.send_keys('test-pass')

    wait.until(ec.visibility_of_element_located((By.ID, 'signIn')))
    signin = driver.find_element_by_id('signIn')
    signin.click()

    wait.until(ec.presence_of_all_elements_located)
    print(driver.current_url)
    eq_('http://localhost:8080/', driver.current_url)
    logout = driver.find_element_by_id('logout')
    logout.click()

    wait.until(ec.presence_of_all_elements_located)
    print(driver.current_url)
    eq_('http://localhost:8080/login', driver.current_url)
    driver.close()

    config = ConfigParser()
    config.read(conf_path)
    config['setup']['initial_setup'] = 'true'
    config['auth']['method'] = 'local'
    config['ldap']['server'] = ''
    config['ldap']['port'] = ''
    config['ldap']['base_dn'] = ''
    config['redpen']['java_home'] = ''
    config['redpen']['conf'] = ''
    f = open(conf_path, 'w')
    config.write(f)
    f.close()

    con = sqlite3.connect(db_path)
    cur = con.cursor()
    sql = 'UPDATE user SET username=(?), password=(?) WHERE username=(?)'
    cur.execute(sql, (
        'Admin',
        gen_pass_hash('webtex'),
        'test-user',
    ))
    con.commit()
    cur.close()
    con.close()