|
| 1 | +"""Tests for the Lexile DB update script.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from unittest.mock import patch |
| 6 | + |
| 7 | +import pytest |
| 8 | + |
| 9 | +from palace.manager.scripts.lexile_db import LexileDBUpdateScript |
| 10 | +from palace.manager.service.logging.configuration import LogLevel |
| 11 | +from tests.fixtures.database import DatabaseTransactionFixture |
| 12 | +from tests.fixtures.services import ServicesFixture |
| 13 | + |
| 14 | + |
| 15 | +class TestLexileDBUpdateScript: |
| 16 | + """Tests for LexileDBUpdateScript.""" |
| 17 | + |
| 18 | + @pytest.mark.parametrize( |
| 19 | + "force", |
| 20 | + [ |
| 21 | + pytest.param(True, id="force"), |
| 22 | + pytest.param(False, id="no force"), |
| 23 | + ], |
| 24 | + ) |
| 25 | + def test_do_run( |
| 26 | + self, |
| 27 | + force: bool, |
| 28 | + db: DatabaseTransactionFixture, |
| 29 | + services_fixture: ServicesFixture, |
| 30 | + caplog: pytest.LogCaptureFixture, |
| 31 | + ) -> None: |
| 32 | + """do_run queues lexile_db_update_task with correct force flag and logs.""" |
| 33 | + caplog.set_level(LogLevel.info) |
| 34 | + with patch( |
| 35 | + "palace.manager.scripts.lexile_db.lexile_db_update_task" |
| 36 | + ) as mock_task: |
| 37 | + command_args = ["--force"] if force else [] |
| 38 | + LexileDBUpdateScript( |
| 39 | + _db=db.session, |
| 40 | + services=services_fixture.services, |
| 41 | + ).do_run(command_args) |
| 42 | + mock_task.delay.assert_called_once_with(force=force) |
| 43 | + assert "Successfully queued lexile_db_update_task" in caplog.text |
| 44 | + assert f"force={force}" in caplog.text |
0 commit comments