Skip to content
Snippets Groups Projects
Select Git revision
  • 8ce04d8896e9a3531361b676d500bb49dc1fcb54
  • main default protected
  • f-prefill-read-only
  • f-recursive-data-model
  • f-yaml-parser-enums
  • dev protected
  • f-fix-paths
  • f-fix-validate-to-dict
  • f-labfolder-converter
  • f-state-machine-script
  • f-xlsx-converter-warnings-errors
  • f-rename
  • f-extra-deps
  • f-more-jsonschema-export
  • f-henrik
  • f-fix-89
  • f-trigger-advanced-user-tools
  • f-real-rename-test
  • f-linkahead-rename
  • f-register-integrationtests
  • f-fix-id
  • v0.14.0
  • v0.13.0
  • v0.12.0
  • v0.11.0
  • v0.10.0-numpy2
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.0
  • v0.6.1
  • v0.6.0
  • v0.5.0
  • v0.4.1
  • v0.4.0
  • v0.3.1
  • v0.3.0
37 results

test_read_xlsx.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    test_json.py 2.63 KiB
    #!/usr/bin/env python3
    # encoding: utf-8
    #
    # ** header v3.0
    # This file is a part of the CaosDB Project.
    #
    # Copyright (C) 2021 Indiscale GmbH <info@indiscale.com>
    # Copyright (C) 2021 Henrik tom Wörden <h.tomwoerden@indiscale.com>
    #
    # This program is free software: you can redistribute it and/or modify
    # it under the terms of the GNU Affero General Public License as
    # published by the Free Software Foundation, either version 3 of the
    # License, or (at your option) any later version.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    # GNU Affero General Public License for more details.
    #
    # You should have received a copy of the GNU Affero General Public License
    # along with this program. If not, see <https://www.gnu.org/licenses/>.
    #
    # ** end header
    #
    
    """
    test the JSON converter
    """
    import json
    import os
    
    from pytest import raises
    
    import linkahead as db
    
    from caoscrawler.converters import JSONFileConverter
    from pathlib import Path
    from caoscrawler.crawl import Crawler
    from caoscrawler.structure_elements import File, JSONFile
    from caoscrawler.scanner import load_definition, create_converter_registry, scan_structure_elements
    
    UNITTESTDIR = Path(__file__).parent
    
    
    def test_json():
        crawler_definition_path = (UNITTESTDIR / "test_directories" / "examples_json"
                                   / "jsontest_cfood.yml")
        json_file_path = UNITTESTDIR / "test_directories" / "examples_json" / "testjson.json"
    
        crawler_definition = load_definition(crawler_definition_path)
        # Load and register converter packages:
        converter_registry = create_converter_registry(crawler_definition)
    
        records = scan_structure_elements(
            JSONFile(os.path.basename(json_file_path), json_file_path),
            crawler_definition,
            converter_registry
        )
    
        rec = [r for r in records if r.name == "DEMO"]
        assert len(rec) == 1
        rec = rec[0]
        assert len(rec.parents) == 1
        assert rec.parents[0].name == "Project"
        assert rec.get_property("url") is not None
        assert rec.get_property("url").value == "https://site.de/index.php/"
        assert rec.get_property("Person") is not None
        assert isinstance(rec.get_property("Person").value, list)
        assert len(rec.get_property("Person").value) == 2
    
    
    def test_broken_validation():
        crawler_definition_path = UNITTESTDIR / "broken_cfoods" / "broken_validation_path.yml"
        with raises(FileNotFoundError) as err:
            crawler_definition = load_definition(crawler_definition_path)
    
        assert str(err.value).startswith("Couldn't find validation file")