Compare commits
4 Commits
Bug585-che
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
c64af4a20a | |
|
|
6285581bb5 | |
|
|
c9bbf6b6a3 | |
|
|
68e4ba33c5 |
|
|
@ -18,7 +18,7 @@ picked from articles selected for him to read according his vocabulary level. E
|
|||
|
||||
`python3 main.py`
|
||||
|
||||
Make sure you have put the SQLite database file in the path `app/static` (see below).
|
||||
Make sure you have put the SQLite database file in the path `app/db` (see below).
|
||||
|
||||
|
||||
## Run it as a Docker container
|
||||
|
|
@ -214,5 +214,5 @@ Bug report: http://118.25.96.118/bugzilla/show_bug.cgi?id=215
|
|||
Bug report: http://118.25.96.118/bugzilla/show_bug.cgi?id=489
|
||||
|
||||
|
||||
*Last modified on 2023-01-30*
|
||||
*Last modified on 2026-03-12*
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ def get_today_article(user_word_list, visited_articles):
|
|||
text_level = text_difficulty_level(d['text'], d3)
|
||||
result_of_generate_article = "found"
|
||||
|
||||
today_article = None
|
||||
today_article = {}
|
||||
if d:
|
||||
oxford_words = load_oxford_words(oxford_words_path)
|
||||
oxford_word_count, total_words = count_oxford_words(d['text'],oxford_words)
|
||||
|
|
|
|||
|
|
@ -144,8 +144,8 @@ if __name__ == '__main__':
|
|||
运行程序
|
||||
'''
|
||||
# app.secret_key = os.urandom(16)
|
||||
# app.run(debug=False, port='6000')
|
||||
app.run(debug=True)
|
||||
app.run(debug=True, port=5000)
|
||||
# app.run(debug=True)
|
||||
# app.run(debug=True, port='6000')
|
||||
# app.run(host='0.0.0.0', debug=True, port='6000')
|
||||
# print(mod5('123'))
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
<p><a href="/login">登录</a> <a href="/signup">注册</a> <a href="/static/usr/instructions.html">使用说明</a></p >
|
||||
<p><b> {{ random_ads }}。 <a href="/signup">试试</a>吧!</b></p>
|
||||
{% endif %}
|
||||
<div class="alert alert-success" role="alert">共有文章 <span class="badge bg-success"> {{ number_of_essays }} </span> 篇,覆盖 <span class="badge bg-success"> {{ (ratio * 100) | int }}% </span> 的 Oxford5000 单词</div>
|
||||
<div class="alert alert-success" role="alert">共有文章 <span class="badge bg-success"> {{ number_of_essays }} </span> 篇,Oxford 5000 单词占比 <span class="badge bg-success"> {{ (ratio * 100) | int }}% </span> </div>
|
||||
<p>粘贴1篇文章 (English only)</p>
|
||||
<form method="post" action="/">
|
||||
<textarea name="content" id="article" rows="10" cols="120"></textarea><br/>
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@
|
|||
|
||||
<div id="text-content">
|
||||
<div id="found">
|
||||
<div class="alert alert-success" role="alert">According to your word list, your level is <span class="text-decoration-underline" id="user_level">{{ today_article["user_level"] }}</span> and we have chosen an article with a difficulty level of <span class="text-decoration-underline" id="text_level">{{ today_article["text_level"] }}</span> for you. The Oxford word coverage is <span class="text-decoration-underline" id="ratio">{{ (today_article["ratio"] * 100) | int }}%.</span></div>
|
||||
<div class="alert alert-success" role="alert">According to your word list, your level is <span class="text-decoration-underline" id="user_level">{{ today_article["user_level"] }}</span> and we have chosen an article with a difficulty level of <span class="text-decoration-underline" id="text_level">{{ today_article["text_level"] }}</span> for you. <span class="text-decoration-underline" id="ratio">{{ (today_article["ratio"] * 100) | int }}%</span> of the words in this article are in Oxford Word 5000.</div>
|
||||
<p class="text-muted" id="date">Article added on: {{ today_article["date"] }}</p><br/>
|
||||
|
||||
<button onclick="saveArticle()" >标记文章</button>
|
||||
|
|
|
|||
|
|
@ -5,30 +5,23 @@ from selenium.webdriver.common.keys import Keys
|
|||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.common.exceptions import NoSuchElementException, TimeoutException
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.edge.service import Service
|
||||
from selenium.webdriver.common.by import By
|
||||
# 测试登录页面输入密码包含空格的情况
|
||||
import unittest
|
||||
|
||||
class Test_Bug528_Tangjiao(unittest.TestCase):
|
||||
def test_login_password_with_space(self):
|
||||
URL = 'http://127.0.0.1:5000'
|
||||
service = Service(executable_path=r'D:\studey\webdrive\edge\msedgedriver.exe')
|
||||
driver = webdriver.Edge(service=service)
|
||||
|
||||
# 测试登录页面输入密码包含空格的情况
|
||||
def test_login_password_with_space(driver, URL):
|
||||
try:
|
||||
driver.get(URL+"/login")
|
||||
|
||||
# 输入用户名
|
||||
username_elem = driver.find_element(By.ID, 'username')
|
||||
username_elem = driver.find_element_by_id('username')
|
||||
username_elem.send_keys("test_user")
|
||||
|
||||
# 输入包含空格的密码
|
||||
password_elem = driver.find_element(By.ID, 'password')
|
||||
password_elem = driver.find_element_by_id('password')
|
||||
password_elem.send_keys("password with space")
|
||||
|
||||
# 提交登录表单
|
||||
elem = driver.find_element(By.ID, 'btn') # 找到提交按钮
|
||||
elem = driver.find_element_by_class_name('btn') # 找到提交按钮
|
||||
elem.click()
|
||||
|
||||
# 显式等待直到警告框出现
|
||||
|
|
@ -40,29 +33,27 @@ class Test_Bug528_Tangjiao(unittest.TestCase):
|
|||
except (NoSuchElementException, TimeoutException) as e:
|
||||
pytest.fail("页面元素未找到或超时: {}".format(e))
|
||||
|
||||
|
||||
# 测试注册页面输入密码包含空格的情况
|
||||
|
||||
def test_signup_password_with_space(self):
|
||||
URL = 'http://127.0.0.1:5000'
|
||||
service = Service(executable_path=r'D:\studey\webdrive\edge\msedgedriver.exe')
|
||||
driver = webdriver.Edge(service=service)
|
||||
def test_signup_password_with_space(driver, URL):
|
||||
try:
|
||||
driver.get(URL+"/signup")
|
||||
|
||||
# 输入用户名
|
||||
username_elem = driver.find_element(By.ID, 'username')
|
||||
username_elem = driver.find_element_by_id('username')
|
||||
username_elem.send_keys("new_user")
|
||||
|
||||
# 输入包含空格的密码
|
||||
password_elem = driver.find_element(By.ID, 'password')
|
||||
password_elem = driver.find_element_by_id('password')
|
||||
password_elem.send_keys("password with space")
|
||||
|
||||
# 再次输入密码
|
||||
password2_elem = driver.find_element(By.ID, 'password2')
|
||||
password2_elem = driver.find_element_by_id('password2')
|
||||
password2_elem.send_keys("password with space")
|
||||
|
||||
# 提交注册表单
|
||||
elem = driver.find_element(By.ID, 'btn') # 找到提交按钮
|
||||
elem = driver.find_element_by_class_name('btn') # 找到提交按钮
|
||||
elem.click()
|
||||
|
||||
# 显式等待直到警告框出现
|
||||
|
|
@ -74,54 +65,31 @@ class Test_Bug528_Tangjiao(unittest.TestCase):
|
|||
except (NoSuchElementException, TimeoutException) as e:
|
||||
pytest.fail("页面元素未找到或超时: {}".format(e))
|
||||
|
||||
|
||||
|
||||
# 测试重设密码页面输入新密码包含空格的情况
|
||||
|
||||
def test_reset_password_with_space(self):
|
||||
URL = 'http://127.0.0.1:5000'
|
||||
service = Service(executable_path=r'D:\studey\webdrive\edge\msedgedriver.exe')
|
||||
driver = webdriver.Edge(service=service)
|
||||
|
||||
def test_reset_password_with_space(driver, URL):
|
||||
try:
|
||||
# 1. 先访问登录页面
|
||||
driver.get(URL + "/login")
|
||||
driver.maximize_window()
|
||||
|
||||
# 2. 完成登录
|
||||
WebDriverWait(driver, 10).until(
|
||||
EC.presence_of_element_located((By.ID, 'username'))
|
||||
).send_keys("student6") # 替换为有效的测试用户名
|
||||
|
||||
driver.find_element(By.ID, 'password').send_keys("ad1258@#$") # 替换为有效的密码
|
||||
driver.find_element(By.ID, 'btn').click()
|
||||
|
||||
# 4. 现在访问重置密码页面
|
||||
driver.get(URL+"/reset")
|
||||
|
||||
# 5. 确保重置页面加载完成
|
||||
WebDriverWait(driver, 10).until(
|
||||
EC.presence_of_element_located((By.ID, 'old-password'))
|
||||
)
|
||||
# 输入用户名
|
||||
username_elem = driver.find_element_by_id('username')
|
||||
username_elem.send_keys("test_user")
|
||||
|
||||
# 6. 执行测试 - 输入包含空格的密码
|
||||
old_password = driver.find_element(By.ID, 'old-password')
|
||||
old_password.send_keys("ad1258@#$")
|
||||
# 输入包含空格的密码
|
||||
password_elem = driver.find_element_by_id('password')
|
||||
password_elem.send_keys("password with space")
|
||||
|
||||
# 填写其他字段(避免因其他验证失败而影响测试)
|
||||
driver.find_element(By.ID, 'new-password').send_keys("new pass")
|
||||
driver.find_element(By.ID, 're-new-password').send_keys("new pass")
|
||||
# 提交重设密码表单
|
||||
elem = driver.find_element_by_class_name('btn') # 找到提交按钮
|
||||
elem.click()
|
||||
|
||||
# 提交表单
|
||||
submit_btn = driver.find_element(By.ID, 'submit')
|
||||
submit_btn.click()
|
||||
|
||||
# 7. 验证预期结果
|
||||
# 显式等待直到警告框出现
|
||||
WebDriverWait(driver, 10).until(EC.alert_is_present())
|
||||
|
||||
# 检查是否弹出警告框
|
||||
alert = driver.switch_to.alert
|
||||
assert "输入不能包含空格!" in alert.text
|
||||
alert.accept()
|
||||
|
||||
except Exception as e:
|
||||
driver.save_screenshot("reset_error.png")
|
||||
pytest.fail(f"测试失败: {e}")
|
||||
finally:
|
||||
driver.quit()
|
||||
except (NoSuchElementException, TimeoutException) as e:
|
||||
pytest.fail("页面元素未找到或超时: {}".format(e))
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
from vocabulary import UserVocabularyLevel, ArticleVocabularyLevel
|
||||
|
||||
|
||||
def test_article_level():
|
||||
''' Boundary case test '''
|
||||
article = ArticleVocabularyLevel('')
|
||||
assert article.level == 0
|
||||
|
||||
def test_user_level():
|
||||
''' Boundary case test '''
|
||||
user = UserVocabularyLevel({})
|
||||
assert user.level == 0
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
'''
|
||||
Estimate a user's vocabulary level given his vocabulary data
|
||||
Estimate an English article's difficulty level given its content
|
||||
Preliminary design
|
||||
|
||||
Hui, 2024-09-23
|
||||
Last upated: 2024-09-25, 2024-09-30
|
||||
'''
|
||||
|
||||
import pickle
|
||||
|
||||
|
||||
def load_record(pickle_fname):
|
||||
with open(pickle_fname, 'rb') as f:
|
||||
d = pickle.load(f)
|
||||
return d
|
||||
|
||||
|
||||
class VocabularyLevelEstimator:
|
||||
_test = load_record('static\words_and_tests.p') # map a word to the sources where it appears
|
||||
|
||||
@property
|
||||
def level(self):
|
||||
total = len(self._test)
|
||||
num = 0
|
||||
for word in self.word_lst:
|
||||
num += 1
|
||||
if word in self._test:
|
||||
print(f'{word} : {self._test[word]}')
|
||||
else:
|
||||
print(f'{word}')
|
||||
if num == 0:
|
||||
return 0
|
||||
return total/num
|
||||
|
||||
|
||||
class UserVocabularyLevel(VocabularyLevelEstimator):
|
||||
def __init__(self, d):
|
||||
self.d = d
|
||||
self.word_lst = list(d.keys())
|
||||
# just look at the most recently-added words
|
||||
|
||||
|
||||
class ArticleVocabularyLevel(VocabularyLevelEstimator):
|
||||
def __init__(self, content):
|
||||
self.content = content
|
||||
self.word_lst = content.lower().split()
|
||||
# select the 10 most difficult words
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
d = load_record('frequency_zhangsan.pickle')
|
||||
print(d)
|
||||
#换行
|
||||
print('------------')
|
||||
user = UserVocabularyLevel(d)
|
||||
print(user.level) # level is a property
|
||||
print('------------')
|
||||
article = ArticleVocabularyLevel('This is an interesting article')
|
||||
print(article.level)
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue