| 
									
										
										
										
											2021-12-03 09:08:45 +08:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2024-04-09 20:06:30 +08:00
										 |  |  | import sqlite3 | 
					
						
							| 
									
										
										
										
											2024-04-10 14:44:23 +08:00
										 |  |  | import time | 
					
						
							| 
									
										
										
										
											2021-12-03 09:08:45 +08:00
										 |  |  | from selenium import webdriver | 
					
						
							| 
									
										
										
										
											2024-04-21 15:31:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-10 14:44:23 +08:00
										 |  |  | from pathlib import Path | 
					
						
							| 
									
										
										
										
											2021-12-03 09:08:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | @pytest.fixture | 
					
						
							|  |  |  | def URL(): | 
					
						
							|  |  |  |     return 'http://127.0.0.1:5000' # URL of the program | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @pytest.fixture | 
					
						
							|  |  |  | def driver(): | 
					
						
							| 
									
										
										
										
											2024-04-21 15:31:39 +08:00
										 |  |  |     return webdriver.Edge()  # follow the "End-to-end testing" section in README.md to install the web driver executable | 
					
						
							| 
									
										
										
										
											2024-04-09 20:06:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-10 14:44:23 +08:00
										 |  |  | @pytest.fixture | 
					
						
							| 
									
										
										
										
											2024-04-09 20:06:30 +08:00
										 |  |  | 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() | 
					
						
							| 
									
										
										
										
											2024-04-10 14:44:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @pytest.fixture(autouse=True) | 
					
						
							|  |  |  | def restart_englishpal(restore_sqlite_database): | 
					
						
							|  |  |  |     (Path(__file__).parent / '../main.py').touch() | 
					
						
							|  |  |  |     time.sleep(1) |