Refactor test cases for improved readability and consistency
- Updated test functions in various test files to enhance code clarity by formatting long lines and improving indentation. - Adjusted assertions to use multi-line formatting for better readability. - Added new test cases for theme settings API to ensure proper functionality. - Ensured consistent use of line breaks and spacing across test files for uniformity.
This commit is contained in:
63
tests/unit/test_theme_settings.py
Normal file
63
tests/unit/test_theme_settings.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import pytest
|
||||
from sqlalchemy.orm import Session
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from main import app
|
||||
from models.theme_setting import ThemeSetting
|
||||
from services.settings import save_theme_settings, get_theme_settings
|
||||
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_save_theme_settings(db_session: Session):
|
||||
theme_data = {
|
||||
"theme_name": "dark",
|
||||
"primary_color": "#000000",
|
||||
"secondary_color": "#333333",
|
||||
"accent_color": "#ff0000",
|
||||
"background_color": "#1a1a1a",
|
||||
"text_color": "#ffffff"
|
||||
}
|
||||
|
||||
saved_setting = save_theme_settings(db_session, theme_data)
|
||||
assert str(saved_setting.theme_name) == "dark"
|
||||
assert str(saved_setting.primary_color) == "#000000"
|
||||
|
||||
|
||||
def test_get_theme_settings(db_session: Session):
|
||||
# Create a theme setting first
|
||||
theme_data = {
|
||||
"theme_name": "light",
|
||||
"primary_color": "#ffffff",
|
||||
"secondary_color": "#cccccc",
|
||||
"accent_color": "#0000ff",
|
||||
"background_color": "#f0f0f0",
|
||||
"text_color": "#000000"
|
||||
}
|
||||
save_theme_settings(db_session, theme_data)
|
||||
|
||||
settings = get_theme_settings(db_session)
|
||||
assert settings["theme_name"] == "light"
|
||||
assert settings["primary_color"] == "#ffffff"
|
||||
|
||||
|
||||
def test_theme_settings_api(api_client):
|
||||
# Test API endpoint for saving theme settings
|
||||
theme_data = {
|
||||
"theme_name": "test_theme",
|
||||
"primary_color": "#123456",
|
||||
"secondary_color": "#789abc",
|
||||
"accent_color": "#def012",
|
||||
"background_color": "#345678",
|
||||
"text_color": "#9abcde"
|
||||
}
|
||||
|
||||
response = api_client.post("/api/settings/theme", json=theme_data)
|
||||
assert response.status_code == 200
|
||||
assert response.json()["theme"]["theme_name"] == "test_theme"
|
||||
|
||||
# Test API endpoint for getting theme settings
|
||||
response = api_client.get("/api/settings/theme")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["theme_name"] == "test_theme"
|
||||
Reference in New Issue
Block a user