|
19 | 19 |
|
20 | 20 | """Tests for the /api/reports endpoints using example_gramps.""" |
21 | 21 |
|
| 22 | +import os |
22 | 23 | import unittest |
23 | 24 | from mimetypes import types_map |
| 25 | +from unittest.mock import patch |
24 | 26 |
|
25 | | -from gramps_webapi.const import REPORT_DEFAULTS |
| 27 | +from gramps.cli.clidbman import CLIDbManager |
| 28 | +from gramps.gen.dbstate import DbState |
26 | 29 |
|
27 | | -from . import BASE_URL, get_test_client |
| 30 | +from gramps_webapi.app import create_app |
| 31 | +from gramps_webapi.auth import add_user, user_db |
| 32 | +from gramps_webapi.const import ( |
| 33 | + ENV_CONFIG_FILE, |
| 34 | + REPORT_DEFAULTS, |
| 35 | + TEST_EMPTY_GRAMPS_AUTH_CONFIG, |
| 36 | +) |
| 37 | + |
| 38 | +from . import BASE_URL, TEST_USERS, get_test_client |
28 | 39 | from .checks import ( |
29 | 40 | check_conforms_to_schema, |
30 | 41 | check_invalid_semantics, |
@@ -257,3 +268,43 @@ def test_post_reports_report_id_file_one_of_each(self): |
257 | 268 | if rv.status_code != 200: |
258 | 269 | bad_reports.append(report["id"]) |
259 | 270 | self.assertEqual(bad_reports, []) |
| 271 | + |
| 272 | + |
| 273 | +class TestReportsEmptyDatabase(unittest.TestCase): |
| 274 | + """Test cases for the /api/reports/ endpoint with an empty database.""" |
| 275 | + |
| 276 | + @classmethod |
| 277 | + def setUpClass(cls): |
| 278 | + """Test class setup.""" |
| 279 | + cls.name = "empty2" |
| 280 | + cls.dbman = CLIDbManager(DbState()) |
| 281 | + cls.dbpath, _name = cls.dbman.create_new_db_cli(cls.name, dbid="sqlite") |
| 282 | + cls.dbman.create_new_db_cli(cls.name, dbid="sqlite") |
| 283 | + with patch.dict( |
| 284 | + "os.environ", |
| 285 | + { |
| 286 | + ENV_CONFIG_FILE: TEST_EMPTY_GRAMPS_AUTH_CONFIG, |
| 287 | + "TREE": cls.name, |
| 288 | + }, |
| 289 | + ): |
| 290 | + cls.test_app = create_app() |
| 291 | + cls.test_app.config["TESTING"] = True |
| 292 | + cls.client = cls.test_app.test_client() |
| 293 | + cls.tree = os.path.basename(cls.dbpath) |
| 294 | + with cls.test_app.app_context(): |
| 295 | + user_db.create_all() |
| 296 | + for role in TEST_USERS: |
| 297 | + add_user( |
| 298 | + name=TEST_USERS[role]["name"], |
| 299 | + password=TEST_USERS[role]["password"], |
| 300 | + role=role, |
| 301 | + ) |
| 302 | + |
| 303 | + @classmethod |
| 304 | + def tearDownClass(cls): |
| 305 | + cls.dbman.remove_database(cls.name) |
| 306 | + |
| 307 | + def test_reports_empty_db(self): |
| 308 | + """Test that importers are loaded also for a fresh db.""" |
| 309 | + rv = check_success(self, TEST_URL) |
| 310 | + assert len(rv) > 0 |
0 commit comments