49 lines
1.2 KiB
Python
49 lines
1.2 KiB
Python
import os
|
|
import pytest
|
|
from selenium import webdriver
|
|
|
|
@pytest.fixture
|
|
def restore_database():
|
|
''' Restore the database.
|
|
It is useful for making sure that each end-to-end test
|
|
starts with the same database.
|
|
Benefit: we can reproduce the same test result.
|
|
'''
|
|
|
|
PASSWORD = '' # root password
|
|
DB_NAME = 'lrr' # database name used for LRR
|
|
|
|
# commands used to import data to DB_NAME
|
|
cmds = [
|
|
f'mysql -u root -p{PASSWORD} -e "DROP DATABASE IF EXISTS {DB_NAME};"',
|
|
f'mysql -u root -p{PASSWORD} -e "CREATE DATABASE {DB_NAME};"',
|
|
f'mysql -u root -p{PASSWORD} -e "GRANT ALL PRIVILEGES ON {DB_NAME}.* TO lrr@localhost WITH GRANT OPTION;"',
|
|
f'mysql -u root -p{PASSWORD} {DB_NAME} < C:\\xampp\\htdocs\\LRR\\lrr_database.sql'] #make sure th link of the database is ok
|
|
|
|
try:
|
|
for command in cmds:
|
|
os.system(command)
|
|
except Exception as e:
|
|
print(f"Error restoring database: {e}")
|
|
|
|
return None
|
|
@pytest.fixture
|
|
def url():
|
|
return 'http://localhost/LRR/' # URL of LRR
|
|
|
|
|
|
@pytest.fixture
|
|
def driver():
|
|
return webdriver.Chrome()
|
|
|
|
|
|
@pytest.fixture
|
|
def admin_username():
|
|
return 'admin@qq.com'
|
|
|
|
|
|
@pytest.fixture
|
|
def admin_password():
|
|
return '123'
|
|
|