Skip to content

Commit

Permalink
Fix issues identified while writing unit tests for Flask endpoints
Browse files Browse the repository at this point in the history
This commit fixes a couple issues that were identified while writing
unit tests for the REST API endpoints:

* `load_barman_config` was being called upon module import of
  `pg_backup_api.server_operation`. As the result of that function
  is only used when instantiating the `OperationServer` class, it
  makes more sense to call it from its `__init__` method. Unit tests
  were adjusted accordingly
* POST request to `/servers/*server_name*/operations` was returning
  a bogus message if no Barman backup corresponding to given
  `backup_id` could be found -- it was printing `None` instead of the
  given `backup_id`

References: BAR-132.

Signed-off-by: Israel Barth Rubio <israel.barth@enterprisedb.com>
  • Loading branch information
barthisrael committed Nov 21, 2023
1 parent 83b7ab5 commit ccee59e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pg_backup_api/pg_backup_api/logic/utility_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ def servers_operations_post(server_name: str,

if op_type == OperationType.RECOVERY:
try:
backup_id = request_body["backup_id"]
msg_backup_id = request_body["backup_id"]
except KeyError:
msg_400 = "Request body is missing ``backup_id``"
abort(400, description=msg_400)

backup_id = parse_backup_id(Server(server), backup_id)
backup_id = parse_backup_id(Server(server), msg_backup_id)

if not backup_id:
msg_404 = f"Backup '{backup_id}' does not exist"
msg_404 = f"Backup '{msg_backup_id}' does not exist"
abort(404, description=msg_404)

operation = RecoveryOperation(server_name)
Expand Down
4 changes: 2 additions & 2 deletions pg_backup_api/pg_backup_api/server_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
if TYPE_CHECKING: # pragma: no cover
from barman.config import Config as BarmanConfig

load_barman_config()

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
log = logging.getLogger()

Expand Down Expand Up @@ -117,6 +115,8 @@ def __init__(self, name: str) -> None:
f"No barman config found for '{name}'."
)

load_barman_config()

if TYPE_CHECKING: # pragma: no cover
assert isinstance(barman.__config__, BarmanConfig)

Expand Down

0 comments on commit ccee59e

Please sign in to comment.