modify conftest & add testcase
This commit is contained in:
@@ -15,7 +15,7 @@ engine = create_engine(SQLALCHEMY_DATABASE_URI,echo=True)
|
||||
|
||||
test_session_maker = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
@pytest.fixture(scope="session")
|
||||
def test_db():
|
||||
connection = engine.connect()
|
||||
transaction = connection.begin()
|
||||
@@ -25,7 +25,7 @@ def test_db():
|
||||
transaction.rollback()
|
||||
connection.close()
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
@pytest.fixture(scope="session")
|
||||
def test_client(test_db):
|
||||
def get_test_db():
|
||||
try:
|
||||
@@ -56,9 +56,24 @@ def test_user(test_db):
|
||||
dicUser["password"] = password
|
||||
return dicUser
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def test_admin(test_db):
|
||||
password ="admin"
|
||||
@pytest.fixture(scope="session")
|
||||
def password():
|
||||
return "password"
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def user(password):
|
||||
user = models.User(
|
||||
email = "user@test.com",
|
||||
first_name = "user",
|
||||
last_name = "abc",
|
||||
hashed_password = security.get_password_hash(password),
|
||||
is_active = True,
|
||||
is_superuser = False
|
||||
)
|
||||
return user
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def admin(password):
|
||||
user = models.User(
|
||||
email = "admin@test.com",
|
||||
first_name = "admin",
|
||||
@@ -67,12 +82,23 @@ def test_admin(test_db):
|
||||
is_active = True,
|
||||
is_superuser = True
|
||||
)
|
||||
return user
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def login_user(test_db,test_client,user,password):
|
||||
test_db.add(user)
|
||||
test_db.commit()
|
||||
test_db.refresh(user)
|
||||
dicUser = user.__dict__
|
||||
dicUser["password"] = password
|
||||
return dicUser
|
||||
response = test_client.post("/api/token", data={"username": user.email, "password":password })
|
||||
return response.json()["access_token"]
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def login_admin(test_db,test_client,admin,password):
|
||||
test_db.add(admin)
|
||||
test_db.commit()
|
||||
test_db.refresh(admin)
|
||||
response = test_client.post("/api/token", data={"username": admin.email, "password":password })
|
||||
return response.json()["access_token"]
|
||||
|
||||
# @pytest.fixture
|
||||
# def test_password() -> str:
|
||||
|
||||
Reference in New Issue
Block a user