WIP: Bug518-Esther #140

Closed
mponeja wants to merge 9 commits from Bug518-Esther into master
9 changed files with 112 additions and 40 deletions

1
EnglishPal Submodule

@ -0,0 +1 @@
Subproject commit 8cbc7c9a0ce543db48f80a743c4168ca847ca500

View File

@ -11,12 +11,14 @@
function login(){ function login(){
let username = $("#username").val(); let username = $("#username").val();
let password = $("#password").val(); let password = $("#password").val();
let regex = /^[a-zA-Z0-9_]*$/;
if (username === "" || password === ""){ if (username === "" || password === ""){
alert('输入不能为空!'); alert('输入不能为空!');
return false; return false;
} }
if (password.includes(' ')) { if (!regex.test(username) || !regex.test(password)) {
alert('输入不能包含空格!'); alert('用户名和密码只能包含英文字母和数字!');
return false; return false;
} }
$.post( $.post(
@ -29,7 +31,7 @@
window.location.href = "/"+username+"/userpage"; window.location.href = "/"+username+"/userpage";
} }
} }
) );
return false; return false;
} }
</script> </script>
@ -47,4 +49,3 @@
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -8,14 +8,12 @@
let old_password = $("#old-password").val(); let old_password = $("#old-password").val();
let new_password = $("#new-password").val(); let new_password = $("#new-password").val();
let re_new_password = $("#re-new-password").val(); let re_new_password = $("#re-new-password").val();
let regex = /^[a-zA-Z0-9_]*$/;
if (old_password === "" || new_password === "" || re_new_password === ""){ if (old_password === "" || new_password === "" || re_new_password === ""){
alert('输入不能为空!'); alert('输入不能为空!');
return false; return false;
} }
if (old_password.includes(' ') || new_password.includes(' ')) {
alert('输入不能包含空格!');
return false;
}
if (new_password !== re_new_password) { if (new_password !== re_new_password) {
alert('新密码不匹配,请重新输入'); alert('新密码不匹配,请重新输入');
return false; return false;
@ -24,6 +22,11 @@
alert('密码过于简单。(密码长度至少4位)'); alert('密码过于简单。(密码长度至少4位)');
return false; return false;
} }
if (!regex.test(new_password)) {
alert('新密码只能包含英文字母和数字!');
return false;
}
$.post("/reset", {'old-password': old_password, 'new-password': new_password}, $.post("/reset", {'old-password': old_password, 'new-password': new_password},
function (response) { function (response) {
if (response.status === '1') { if (response.status === '1') {
@ -34,7 +37,7 @@
window.location.href = "/reset"; window.location.href = "/reset";
} }
} }
) );
return false; return false;
} }
</script> </script>

View File

@ -12,14 +12,12 @@ You're logged in already! <a href="/logout">Logout</a>.
let username = $("#username").val(); let username = $("#username").val();
let password = $("#password").val(); let password = $("#password").val();
let password2 = $("#password2").val(); let password2 = $("#password2").val();
let regex = /^[a-zA-Z0-9_]*$/;
if (username === "" || password === "" || password2 === ""){ if (username === "" || password === "" || password2 === ""){
alert('输入不能为空!'); alert('输入不能为空!');
return false; return false;
} }
if (password.includes(' ') || password2.includes(' ')) {
alert('输入不能包含空格!');
return false;
}
if (password !== password2) { if (password !== password2) {
alert('确认密码与输入密码不一致!'); alert('确认密码与输入密码不一致!');
return false; return false;
@ -28,6 +26,11 @@ You're logged in already! <a href="/logout">Logout</a>.
alert('密码过于简单。(密码长度至少4位)'); alert('密码过于简单。(密码长度至少4位)');
return false; return false;
} }
if (!regex.test(username) || !regex.test(password)) {
alert('用户名和密码只能包含英文字母和数字!');
return false;
}
$.post("/signup", {'username': username, 'password': password}, $.post("/signup", {'username': username, 'password': password},
function (response) { function (response) {
if (response.status === '0') { if (response.status === '0') {
@ -47,7 +50,7 @@ You're logged in already! <a href="/logout">Logout</a>.
alert(response.warn); alert(response.warn);
} }
} }
) );
return false; return false;
} }
</script> </script>
@ -60,7 +63,7 @@ You're logged in already! <a href="/logout">Logout</a>.
<h1>Sign up</h1> <h1>Sign up</h1>
</section> </section>
<p><input type="username" id="username" placeholder="输入用户名" class="username"></p> <p><input type="text" id="username" placeholder="输入用户名" class="username"></p>
<p><input type="password" id="password" placeholder="输入密码" class="password"></p> <p><input type="password" id="password" placeholder="输入密码" class="password"></p>
<p><input type="password" id="password2" placeholder="确认密码" class="password" ></p> <p><input type="password" id="password2" placeholder="确认密码" class="password" ></p>
<button type="button" class="btn" onclick="signup()">注册</button> <button type="button" class="btn" onclick="signup()">注册</button>
@ -69,4 +72,3 @@ You're logged in already! <a href="/logout">Logout</a>.
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View File

@ -232,6 +232,7 @@
update(data['today_article']); update(data['today_article']);
check_pre(data['visited_articles']); check_pre(data['visited_articles']);
check_next(data['result_of_generate_article']); check_next(data['result_of_generate_article']);
toggleHighlighting();
} }
} }
}); });
@ -245,6 +246,7 @@
if(data['today_article']){ if(data['today_article']){
update(data['today_article']); update(data['today_article']);
check_pre(data['visited_articles']); check_pre(data['visited_articles']);
toggleHighlighting();
} }
} }
}); });

View File

@ -12,24 +12,5 @@ def URL():
@pytest.fixture @pytest.fixture
def driver(): def driver():
return webdriver.Edge() # follow the "End-to-end testing" section in README.md to install the web driver executable my_driver = webdriver.Chrome()
return my_driver
@pytest.fixture
def restore_sqlite_database():
'''
Automatically restore SQLite database file app/db/wordfreqapp.db
using SQL statements from app/static/wordfreqapp.sql
'''
con = sqlite3.connect('../db/wordfreqapp.db')
with con:
con.executescript('DROP TABLE IF EXISTS user;')
con.executescript('DROP TABLE IF EXISTS article;')
con.executescript(open('../static/wordfreqapp.sql', encoding='utf8').read())
con.close()
@pytest.fixture(autouse=True)
def restart_englishpal(restore_sqlite_database):
(Path(__file__).parent / '../main.py').touch()
time.sleep(1)

View File

@ -0,0 +1,39 @@
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
import time
# 初始化WebDriver
driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX)
driver.implicitly_wait(10)
# 测试注册页面输入密码包含空格的情况
def test_signup_password_with_space():
try:
driver.get("http://127.0.0.1:5000/signup")
# 输入用户名
username_elem = driver.find_element_by_name('username')
username_elem.send_keys("阿萨德")
# 输入包含空格的密码
password_elem = driver.find_element_by_name('password')
password_elem.send_keys("阿萨德阿萨德")
# 再次输入密码
password2_elem = driver.find_element_by_name('password2')
password2_elem.send_keys("阿萨德阿萨德")
# 提交注册表单
password2_elem.send_keys(Keys.RETURN)
# 等待一段时间确保页面加载完成
time.sleep(2)
# 检查是否弹出警告框
alert = driver.switch_to.alert
assert "用户名和密码只能包含英文字母和数字!" in alert.text
finally:
driver.quit()

View File

@ -0,0 +1,43 @@
import time
import pytest
import uuid
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import UnexpectedAlertPresentException, NoAlertPresentException, NoSuchElementException, \
TimeoutException
from conftest import URL
driver = webdriver.Chrome()
def test_bug555():
try:
driver.maximize_window()
base_url = "http://127.0.0.1:5000"
driver.get(base_url)
article = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'article')))
perform_actions_on_article(driver, article)
next_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'load_next_article')))
next_button.click()
print("Clicked next article button.")
prev_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'load_pre_article')))
prev_button.click()
print("Clicked previous article button.")
except (TimeoutException, NoSuchElementException) as e:
print(f"An error occurred: {e}")
finally:
driver.quit()
print("Driver closed.")
def perform_actions_on_article(driver, article):
actions = ActionChains(driver)
actions.move_to_element(article)
actions.click_and_hold()
actions.move_by_offset(450, 200)
actions.release()
actions.perform()
print("Performed actions on article.")

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB