Beispiel #1
0
 def test_should_read_journals_and_issues(
     self, open_mock, create_output_dir_mock, read_json_file_mock
 ):
     read_json_file_mock.side_effect = [SAMPLE_JOURNALS_JSON, SAMPLE_ISSUES_JSON]
     pipeline.link_documents_bundles_with_journals(
         "~/title.json", "~/issues.json", "~/json/output.json"
     )
     self.assertEqual(2, read_json_file_mock.call_count)
def migrate_isis_parser(sargs):
    parser = argparse.ArgumentParser(description="ISIS database migration tool")
    subparsers = parser.add_subparsers(title="Commands", metavar="", dest="command")

    extract_parser = subparsers.add_parser("extract", help="Extract mst files to json")
    extract_parser.add_argument(
        "mst_file_path", metavar="file", help="Path to MST file that will be extracted"
    )
    extract_parser.add_argument("--output", required=True, help="The output file path")

    import_parser = subparsers.add_parser(
        "import",
        parents=[mongodb_parser(sargs)],
        help="Process JSON files then import into Kernel database",
    )
    import_parser.add_argument(
        "import_file",
        metavar="file",
        help="JSON file path that contains mst extraction result, e.g: collection-title.json",
    )
    import_parser.add_argument(
        "--type",
        help="Type of JSON file that will load into Kernel database",
        choices=["journal", "issue", "documents-bundles-link"],
        required=True,
    )

    link_parser = subparsers.add_parser(
        "link",
        help="Generate JSON file of journals' ids and their issues linked by ISSN",
    )
    link_parser.add_argument(
        "issues",
        help="JSON file path that contains mst extraction result, e.g: ~/json/collection-issues.json",
    )
    link_parser.add_argument("--output", required=True, help="The output file path")

    args = parser.parse_args(sargs)

    if args.command == "extract":
        extract_isis.create_output_dir(args.output)
        extract_isis.run(args.mst_file_path, args.output)
    elif args.command == "import":
        mongo = ds_adapters.MongoDB(uri=args.uri, dbname=args.db)
        Session = ds_adapters.Session.partial(mongo)

        if args.type == "journal":
            pipeline.import_journals(args.import_file, session=Session())
        elif args.type == "issue":
            pipeline.import_issues(args.import_file, session=Session())
        elif args.type == "documents-bundles-link":
            pipeline.import_documents_bundles_link_with_journal(
                args.import_file, session=Session()
            )
    elif args.command == "link":
        pipeline.link_documents_bundles_with_journals(args.issues, args.output)
    else:
        parser.print_help()
Beispiel #3
0
    def test_should_create_output_folder(
        self, open_mock, create_output_dir_mock, read_json_file_mock
    ):

        read_json_file_mock.return_value = []
        pipeline.link_documents_bundles_with_journals(
            "~/title.json", "~/issues.json", "~/json/output.json"
        )
        create_output_dir_mock.return_value = None
        create_output_dir_mock.assert_called_once()
Beispiel #4
0
    def test_should_write_output_file(
        self, open_mock, create_output_dir_mock, read_json_file_mock
    ):
        read_json_file_mock.side_effect = [SAMPLE_JOURNALS_JSON, SAMPLE_ISSUES_JSON]
        open_mock.side_effect = mock.mock_open()

        pipeline.link_documents_bundles_with_journals(
            "~/title.json", "~/issues.json", "~/json/output.json"
        )

        open_mock.assert_called_once_with("~/json/output.json", "w")
        open_mock = open_mock()
        open_mock.write.assert_called_once()
        self.assertIn("0001-3714", str(open_mock.write.call_args))