feat: import and export mood profiles

Add GET /api/moods/export (custom-only filter) and POST /api/moods/import with skip reporting, plus export/import controls in the recommendations panel.
This commit is contained in:
strsv committed 2026-11-07 00:47:33 +03:00
1 parent 987e52931f
commit 49a7ab9918
9 files changed
+220 -43

No files matched your search

+42
View File
@@ -445,6 +445,48 @@ class ApiTests(unittest.TestCase):
finally:
con.close()
def test_mood_export_import(self):
try:
self.post("/api/moods", {
"name": "export-one", "description": "Экспорт",
"genres": ["RPG"], "tags": {"Cozy": 1.5}})
data = self.get("/api/moods/export")
self.assertEqual(data["version"], 1)
names = {mood["name"] for mood in data["moods"]}
self.assertIn("export-one", names)
self.assertIn("dark-fantasy", names)
custom = self.get("/api/moods/export?custom=1")
custom_names = {mood["name"] for mood in custom["moods"]}
self.assertIn("export-one", custom_names)
self.assertNotIn("dark-fantasy", custom_names)
result = self.post("/api/moods/import", {"moods": [
{"name": "import-one", "description": "Импорт",
"genres": ["RPG"], "tags": {"Cozy": 1.2}},
{"name": "export-one", "description": "Обновлён",
"genres": [], "tags": {"Relaxing": 1.0}},
{"name": "dark-fantasy", "tags": {"Cozy": 1.0}},
{"name": "Bad Name", "tags": {"Cozy": 1.0}},
"not-a-dict",
]})
self.assertEqual(result["imported"], 1)
self.assertEqual(result["updated"], 1)
self.assertEqual(len(result["skipped"]), 3)
moods = {mood["name"]: mood for mood in self.get("/api/moods")["moods"]}
self.assertIn("import-one", moods)
self.assertEqual(moods["export-one"]["description"], "Обновлён")
self.assertEqual(self.post("/api/moods/import", {"not": "a list"},
expect=400)["error"], "expected list of moods")
finally:
con = db.connect(self.db_path)
try:
con.execute("DELETE FROM moods WHERE name IN ('export-one', 'import-one')")
con.commit()
finally:
con.close()
def test_recommend_unknown_mood(self):
data = self.post("/api/recommend", {"preset": "no-such-mood"}, expect=400)
self.assertEqual(data["error"], "unknown mood")