Unverified Commit ae11b52d authored by David Runge's avatar David Runge
Browse files

Add CLI entrypoint for db2json

repo_management/cli.py:
Add `db2json()` which may serve as an entrypoint for a db2json script,
as it makes use of the argument parser defined in
`argparse.ArgParseFactory.db2json()` and calls
`operations.dump_db_to_json_files()` using the provided inputs.

tests/test_cli.py:
Add a unittest for `db2json()`, which patches all called methods.
The methods are tested extensively elsewhere. However, the function
should see proper integration testing via this endpoint in the future.
parent 29949913
from repo_management import argparse, operations
def db2json() -> None:
"""The entry point for the db2json script
The method calls operations.dump_db_to_json_files() which creates JSON files for each member of a provided
repository database file.
"""
args = argparse.ArgParseFactory.db2json().parse_args()
operations.dump_db_to_json_files(
input_path=args.db_file,
output_path=args.output_dir,
)
from argparse import Namespace
from mock import Mock, patch
from repo_management import cli
@patch("repo_management.operations.dump_db_to_json_files")
@patch("repo_management.argparse.ArgParseFactory")
def test_db2json(argparsefactory_mock: Mock, dump_db_to_json_files_mock: Mock) -> None:
namespace = Namespace(db_file="db_file", output_dir="output_dir")
argparsefactory_mock.db2json.return_value = Mock(parse_args=Mock(return_value=namespace))
cli.db2json()
dump_db_to_json_files_mock.assert_called_once_with(input_path=namespace.db_file, output_path=namespace.output_dir)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment