-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/pdct 1397 Add skeleton for GCF collection mapping (#5)
- Loading branch information
Showing
7 changed files
with
74 additions
and
16 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,57 @@ | ||
import sys | ||
from typing import Any, Optional | ||
|
||
import click | ||
|
||
from gcf_data_mapper.parsers.collection import collection | ||
|
||
|
||
@click.command() | ||
@click.option("--debug/--no-debug", default=False) | ||
@click.version_option("0.1.0", "--version", "-v", help="Show the version and exit.") | ||
def wrangle_json(): | ||
"""Simple program that wrangles GCF data into bulk import format.""" | ||
def entrypoint(debug: bool): | ||
"""Simple program that wrangles GCF data into bulk import format. | ||
:param bool debug: Whether debug mode is on. | ||
""" | ||
click.echo("🚀 Starting the GCF data mapping process.") | ||
|
||
try: | ||
collection() | ||
wrangle_to_json(debug) | ||
except Exception as e: | ||
click.echo(f"❌ Failed to map GCF data to expected JSON. Error: {e}.") | ||
sys.exit(1) | ||
|
||
click.echo("✅ Finished mapping GCF data.") | ||
|
||
click.echo() | ||
click.echo("🚀 Dumping GCF data to output file") | ||
dump_output() | ||
click.echo("✅ Finished dumping mapped GCF data.") | ||
|
||
|
||
def collection(): | ||
"""Map the GCF collection info to new structure. | ||
def wrangle_to_json(debug) -> dict[str, list[Optional[dict[str, Any]]]]: | ||
"""Put the mapped GCF data into a dictionary ready for dumping. | ||
Collection information is not currently available for GCF data, so | ||
we will leave this function as not implemented for now. | ||
The output of this function will get dumped as JSON to the output | ||
file. | ||
:param bool debug: Whether debug mode is on. | ||
:return dict[str, list[Optional[dict[str, Any]]]]: The GCF data | ||
mapped to the Document-Family-Collection-Event entity it | ||
corresponds to. | ||
""" | ||
return { | ||
"collections": collection(debug), | ||
"families": [], | ||
"documents": [], | ||
"events": [], | ||
} | ||
|
||
|
||
def dump_output(): | ||
pass | ||
|
||
|
||
if __name__ == "__main__": | ||
wrangle_json() | ||
entrypoint() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from typing import Any, Optional | ||
|
||
import click | ||
|
||
|
||
def collection(debug: bool) -> list[Optional[dict[str, Any]]]: | ||
"""Map the GCF collection info to new structure. | ||
Collection information is not currently available for GCF data, so | ||
we will leave this function as not implemented for now. | ||
:param bool debug: Whether debug mode is on. | ||
:return list[Optional[dict[str, Any]]]: A list of GCF families in | ||
the 'destination' format described in the GCF Data Mapper Google | ||
Sheet. | ||
""" | ||
if debug: | ||
click.echo("📝 Wrangling GCF collection data.") | ||
|
||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "gcf-data-mapper" | ||
version = "0.1.1" | ||
version = "0.1.2" | ||
description = "A CLI tool to wrangle GCF data into format recognised by the bulk-import tool." | ||
authors = ["CPR-dev-team <[email protected]>"] | ||
license = "Apache-2.0" | ||
|
17 changes: 10 additions & 7 deletions
17
tests/unit_tests/test_cli.py → tests/integration_tests/test_cli.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
import pytest | ||
from click.testing import CliRunner | ||
|
||
from gcf_data_mapper.cli import wrangle_json | ||
from gcf_data_mapper.cli import entrypoint | ||
|
||
|
||
def test_version(): | ||
runner = CliRunner() | ||
result = runner.invoke(wrangle_json, ["--version"]) | ||
result = runner.invoke(entrypoint, ["--version"]) | ||
assert result.exit_code == 0 | ||
assert "version" in result.output.strip() | ||
|
||
|
||
@pytest.mark.skip() | ||
def test_wrangle_json_fail(): | ||
def test_entrypoint_fail(): | ||
runner = CliRunner() | ||
result = runner.invoke(wrangle_json) | ||
result = runner.invoke(entrypoint) | ||
assert result.exit_code == 1 | ||
assert "Failed to map GCF data to expected JSON" in result.output.strip() | ||
|
||
|
||
def test_wrangle_json_success(): | ||
def test_entrypoint_success(): | ||
runner = CliRunner() | ||
result = runner.invoke(wrangle_json) | ||
result = runner.invoke(entrypoint) | ||
assert result.exit_code == 0 | ||
assert "Finished mapping GCF data." in result.output.strip() | ||
assert all( | ||
item in result.output.strip() | ||
for item in ["Finished mapping GCF data", "Finished dumping mapped GCF data"] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import pytest | ||
|
||
from gcf_data_mapper.parsers.collection import collection | ||
|
||
|
||
@pytest.mark.parametrize("debug", [True, False]) | ||
def test_returns_empty(debug: bool): | ||
collection_data = collection(debug) | ||
assert collection_data == [] |