Skip to content

Commit

Permalink
Feature/pdct 1397 Add skeleton for GCF collection mapping (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
katybaulch authored Aug 27, 2024
2 parents 95bfbdd + 74e13d1 commit a2c1413
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 16 deletions.
Empty file added __init__.py
Empty file.
42 changes: 34 additions & 8 deletions gcf_data_mapper/cli.py
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.
20 changes: 20 additions & 0 deletions gcf_data_mapper/parsers/collection.py
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 []
2 changes: 1 addition & 1 deletion pyproject.toml
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"
Expand Down
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"]
)
9 changes: 9 additions & 0 deletions tests/unit_tests/parsers/collection/test_collection.py
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 == []

0 comments on commit a2c1413

Please sign in to comment.