-
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.
Add code coverage with github actions
- Loading branch information
Showing
9 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
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
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,3 +1,6 @@ | ||
log* | ||
.env | ||
__pycache__/ | ||
.coveralls.yml | ||
.coverage | ||
coverage.lcov |
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
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
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
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,57 @@ | ||
import json | ||
import logging | ||
import pathlib | ||
|
||
from migration_tools.migration_tasks.batch_poster import BatchPoster | ||
|
||
|
||
def post_marc_to_srs(*args, **kwargs): | ||
dag = kwargs["dag_run"] | ||
|
||
task_config = BatchPoster.TaskConfiguration( | ||
name="marc-to-srs-batch-poster", | ||
migration_task_type="BatchPoster", | ||
object_type="SRS", | ||
file={ | ||
"file_name": f"folio_srs_instances_{dag.run_id}_bibs-transformer.json" # noqa | ||
}, | ||
batch_size=kwargs.get("MAX_ENTITIES", 1000), | ||
) | ||
|
||
library_config = kwargs["library_config"] | ||
library_config.iteration_identifier = dag.run_id | ||
|
||
srs_batch_poster = BatchPoster( | ||
task_config, | ||
library_config, | ||
use_logging=False | ||
) | ||
|
||
srs_batch_poster.do_work() | ||
|
||
srs_batch_poster.wrap_up() | ||
|
||
logging.info("Finished posting MARC json to SRS") | ||
|
||
|
||
def replace_srs_record_type(*args, **kwargs): | ||
dag = kwargs["dag_run"] | ||
|
||
airflow = kwargs.get("airflow", "/opt/airflow") | ||
airflow_path = pathlib.Path(airflow) | ||
|
||
srs_file = ( | ||
airflow_path | ||
/ f"migration/results/folio_srs_instances_{dag.run_id}_bibs-transformer.json" # noqa | ||
) | ||
|
||
marc_recs = [] | ||
with open(srs_file) as fo: | ||
for row in fo.readlines(): | ||
srs_marc = json.loads(row) | ||
srs_marc["recordType"] = "MARC" | ||
marc_recs.append(srs_marc) | ||
|
||
with open(srs_file, "w+") as fo: | ||
for row in marc_recs: | ||
fo.write(f"{json.dumps(row)}\n") |
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,23 @@ | ||
import json | ||
|
||
from plugins.folio.marc import replace_srs_record_type | ||
from plugins.tests.test_helpers import mock_dag_run, mock_file_system # noqa | ||
|
||
|
||
def test_replace_srs_record_type(mock_dag_run, mock_file_system): # noqa | ||
dag = mock_dag_run | ||
airflow_path = mock_file_system[0] | ||
results_path = mock_file_system[3] | ||
|
||
# Mock SRS Record | ||
srs_mock_filename = ( | ||
f"folio_srs_instances_{dag.run_id}_bibs-transformer.json" # noqa | ||
) | ||
srs_mock_file = results_path / srs_mock_filename | ||
srs_mock_file.write_text("""{ "recordType": "MARC_BIB" }""") | ||
|
||
replace_srs_record_type(airflow=airflow_path, dag_run=dag) | ||
|
||
srs_json_doc = json.loads(srs_mock_file.read_text()) | ||
|
||
assert srs_json_doc["recordType"] == "MARC" |
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,5 +1,7 @@ | ||
apache-airflow | ||
argparse_prompt | ||
coverage | ||
coveralls | ||
flake8 | ||
folioclient | ||
folio-uuid | ||
|