Skip to content

Commit

Permalink
Test whether json.dump is call with correct indent param
Browse files Browse the repository at this point in the history
Signed-off-by: Étienne Boisseau-Sierra <[email protected]>
  • Loading branch information
EBoisseauSierra committed Feb 2, 2022
1 parent 9471ffc commit ba7b5ef
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions flask_appbuilder/tests/test_fab_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import tempfile
from unittest.mock import patch

from click.testing import CliRunner
from flask import Flask
Expand Down Expand Up @@ -146,6 +147,29 @@ def test_export_roles_filename(self):
len(glob.glob(os.path.join(tmp_dir, "roles_export_*"))), 0
)

@patch("json.dump")
def test_export_roles_indent(self, mock_json_dump):
"""Test that json.dump is called with the correct argument passed from CLI."""
with tempfile.TemporaryDirectory() as tmp_dir:
app = Flask("src_app")
app.config.from_object("flask_appbuilder.tests.config_security")
app.config[
"SQLALCHEMY_DATABASE_URI"
] = f"sqlite:///{os.path.join(tmp_dir, 'src.db')}"
db = SQLA(app)
app_builder = AppBuilder(app, db.session) # noqa: F841
cli_runner = app.test_cli_runner()

cli_runner.invoke(export_roles)
mock_json_dump.assert_called_with(indent=None)
mock_json_dump.reset_mock()

example_cli_args = ["", "foo", -1, 0, 1]
for arg in example_cli_args:
cli_runner.invoke(export_roles, [f"--indent={arg}"])
mock_json_dump.assert_called_with(indent=arg)
mock_json_dump.reset_mock()

def test_import_roles(self):
with tempfile.TemporaryDirectory() as tmp_dir:
app = Flask("dst_app")
Expand Down

0 comments on commit ba7b5ef

Please sign in to comment.