Esempio n. 1
0
    def test_archived_path_correction_2(self):
        """ Given a doc with another alternate form of the archived_path key, confirm correction. """

        mmi = MetadataMongoIngester()
        doc = {"archiveFolderPath": "some_path"}
        doc = mmi._MetadataMongoIngester__correct_archived_path_key(doc)
        assert "archived_path" in doc
    def test_set_bad_schema_truncated(self):
        """ Given an incorrectly truncated schema file, confirm failure. """

        schema_filename = os.path.join(schemas_dir,
                                       "bad_gt-schema_truncated.json")
        val = MetadataMongoIngester().set_schema(schema_filename)
        assert val.startswith("Error: could not set schema")
Esempio n. 3
0
    def test_bad_config_bad_format(self):
        """ Given a poorly formatted config file, confirm failure. """

        config_filename = os.path.join(configs_dir, "bad_config_format.cfg")
        val = MetadataMongoIngester().open_connection(
            config_filename=config_filename)
        assert val.startswith("Error: cannot read config file")
Esempio n. 4
0
    def test_bad_config_no_mongodb_section(self):
        """ Given a config file missing a mongodb section, confirm failure. """

        config_filename = os.path.join(configs_dir,
                                       "bad_config_no_mongodb_section.cfg")
        val = MetadataMongoIngester().open_connection(
            config_filename=config_filename)
        assert val.startswith("Error: no mongodb section in config")
Esempio n. 5
0
    def test_good_config_bad_secrets_no_password(self):
        """ Given a secrets file with no password, confirm failure. """

        config_filename = os.path.join(
            configs_dir, "good_config_bad_secrets_no_password.cfg")
        val = MetadataMongoIngester().open_connection(
            config_filename=config_filename)
        assert val.startswith("Error: no password in secrets file")
Esempio n. 6
0
    def test_bad_config_no_secrets_filename(self):
        """ Given a config file missing a secrets section, confirm failure. """

        config_filename = os.path.join(configs_dir,
                                       "bad_config_no_secrets_filename.cfg")
        val = MetadataMongoIngester().open_connection(
            config_filename=config_filename)
        assert val.startswith("Error: no filename key in secrets section")
Esempio n. 7
0
    def test_bad_config_no_index_keys(self):
        """ Given a config file with a mongodb section missing index keys, confirm failure. """

        config_filename = os.path.join(configs_dir,
                                       "bad_config_no_index_keys.cfg")
        val = MetadataMongoIngester().open_connection(
            config_filename=config_filename)
        assert val.startswith("Error: no index_keys in mongodb section")
    def test_set_bad_schema_wrong_data_type(self):
        """ Given a schema file with a wrong data type, confirm failure. """

        schema_filename = os.path.join(schemas_dir,
                                       "bad_gt-schema_wrong_data_type.json")
        val = MetadataMongoIngester().set_schema(schema_filename)
        # TBD: This test does not work.
        assert val.startswith("Error: could not set schema")
    def test_good_doc_file_validates_with_good_schema(self):
        """ Given a good schema and a good document file, confirm successful validation. """

        schema_filename = os.path.join(schemas_dir, "good_gt-schema.json")
        mmi = MetadataMongoIngester()
        mmi.set_schema(schema_filename)
        doc_filename = os.path.join(test_docs_dir, "good_gt_metadata.json")
        val = mmi.validate(doc_filename)
        assert val == None
    def test_bad_doc_file_fails_validation_with_good_schema(self):
        """ Given a good schema and a bad document missing a "PI" field, confirm failed validation. """

        schema_filename = os.path.join(schemas_dir, "good_gt-schema.json")
        mmi = MetadataMongoIngester()
        mmi.set_schema(schema_filename)
        doc_filename = os.path.join(test_docs_dir,
                                    "bad_gt_metadata_missing_PI.json")
        val = mmi.validate(doc_filename)
        assert val.startswith("Error: document validation failed")
Esempio n. 11
0
    def test_bad_doc_no_archived_path_fails(self):
        """ Given a bad document missing an archived path, confirm failed ingestion. """

        config_filename = os.path.join(configs_dir,
                                       "good_config_good_secrets.cfg")
        mmi = MetadataMongoIngester()
        mmi.open_connection(config_filename)
        doc_filename = os.path.join(
            test_docs_dir, "bad_gt_metadata_missing_archived_path.json")
        val = mmi.ingest_document(doc_filename)
        assert val.startswith("Error: no archived_path key")
Esempio n. 12
0
    def test_bad_doc_file_ingests_without_schema(self):
        """ Given a bad document (missing a PI) but no schema, confirm successful ingestion. """

        config_filename = os.path.join(configs_dir,
                                       "good_config_good_secrets.cfg")
        mmi = MetadataMongoIngester()
        mmi.open_connection(config_filename)
        doc_filename = os.path.join(test_docs_dir,
                                    "bad_gt_metadata_missing_PI.json")
        val = mmi.ingest_document(doc_filename)
        assert val == None or val.startswith("Duplicate key")
    def test_good_doc_dict_validates_with_good_schema(self):
        """ Given a good schema and a good document loaded as a dict, confirm successful validation. """

        schema_filename = os.path.join(schemas_dir, "good_gt-schema.json")
        mmi = MetadataMongoIngester()
        mmi.set_schema(schema_filename)
        doc_filename = os.path.join(test_docs_dir, "good_gt_metadata.json")
        with open(doc_filename, 'r') as f:
            doc = json.load(f)
        val = mmi.validate(doc)
        assert val == None
    def test_set_and_unset_schema(self):
        """ Test that we can set a schema and unset it. """

        schema_filename = os.path.join(schemas_dir, "good_gt-schema.json")
        mmi = MetadataMongoIngester()
        mmi.set_schema(schema_filename)
        assert mmi.is_schema_set() == True
        mmi.set_schema()  # Passing no schema file clears the schema
        assert mmi.is_schema_set() == False
Esempio n. 15
0
    def test_good_config_good_secrets(self):
        """ Given a good config file and a good secrets file, confirm success. """

        config_filename = os.path.join(configs_dir,
                                       "good_config_good_secrets.cfg")
        val = MetadataMongoIngester().open_connection(
            config_filename=config_filename)
        assert val == None
    def test_bad_doc_file_passes_validation_with_unset_schema(self):
        """ Given a bad document missing a "PI" field, set then unset schema, and confirm successful validation. """

        schema_filename = os.path.join(schemas_dir, "good_gt-schema.json")
        mmi = MetadataMongoIngester()
        mmi.set_schema(schema_filename)
        mmi.set_schema()
        doc_filename = os.path.join(test_docs_dir,
                                    "bad_gt_metadata_missing_PI.json")
        val = mmi.validate(doc_filename)
        assert val == None
Esempio n. 17
0
    def test_good_doc_file_ingests_with_schema(self):
        """ Given a good schema and a good document as a file, confirm successful ingestion. """

        config_filename = os.path.join(configs_dir,
                                       "good_config_good_secrets.cfg")
        schema_filename = os.path.join(schemas_dir, "good_gt-schema.json")
        mmi = MetadataMongoIngester()
        mmi.open_connection(config_filename)
        mmi.set_schema(schema_filename)
        doc_filename = os.path.join(test_docs_dir, "good_gt_metadata.json")
        val = mmi.ingest_document(doc_filename)
        assert val == None or val.startswith("Duplicate key")
    def test_set_good_schema(self):
        """ Given a correct schema file, confirm success. """

        schema_filename = os.path.join(schemas_dir, "good_gt-schema.json")
        val = MetadataMongoIngester().set_schema(schema_filename)
        assert val == None