-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update multiple version dependency specifiers (#454)
- Loading branch information
Showing
7 changed files
with
227 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,41 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
from typing import Dict, Generator | ||
from typing import Generator | ||
|
||
import pytest | ||
|
||
from starlette.testclient import TestClient | ||
|
||
from backend.app.admin.tests.utils.db_mysql import override_get_db | ||
from backend.app.admin.tests.utils.get_headers import get_token_headers | ||
from backend.core.conf import settings | ||
from backend.database.db_mysql import get_db | ||
from backend.main import app | ||
|
||
# 重载数据库 | ||
app.dependency_overrides[get_db] = override_get_db | ||
|
||
|
||
# Test user | ||
# Test data | ||
PYTEST_USERNAME = 'admin' | ||
PYTEST_PASSWORD = '123456' | ||
PYTEST_BASE_URL = f'http://testserver{settings.FASTAPI_API_V1_PATH}' | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def client() -> Generator: | ||
with TestClient(app) as c: | ||
with TestClient(app, base_url=PYTEST_BASE_URL) as c: | ||
yield c | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def token_headers(client: TestClient) -> Dict[str, str]: | ||
return get_token_headers(client=client, username=PYTEST_USERNAME, password=PYTEST_PASSWORD) | ||
def token_headers(client: TestClient) -> dict[str, str]: | ||
params = { | ||
'username': PYTEST_USERNAME, | ||
'password': PYTEST_PASSWORD, | ||
} | ||
response = client.post('/auth/login/swagger', params=params) | ||
response.raise_for_status() | ||
token_type = response.json()['token_type'] | ||
access_token = response.json()['access_token'] | ||
headers = {'Authorization': f'{token_type} {access_token}'} | ||
return headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.