def test_load_schema_json():
    # given
    config = {
        "schema_dir": "tap_test_data_generator/schemas",
        "metadata_dir": "tap_test_data_generator/metadatas",
        "object_repository_dir": "tap_test_data_generator/object-repositories",
        "static_input_dir": "",
        "record_number": 100,
        "apply_record_number_on_pairwise": True,
        "data_locale_list": ["en_US", "fr_FR"]
    }
    catalog = discover(config)
    stream = catalog.get_stream("sample")
    # when
    schema_json = load_schema_json(config, stream)
    # then
    assert schema_json is not None
    assert "$schema" in schema_json
    assert "http://json-schema.org/draft-07/schema" == schema_json["$schema"]
    assert "type" in schema_json
    assert "object" == schema_json["type"]
    assert "properties" in schema_json
    assert "checked" in schema_json["properties"]
    assert "type" in schema_json["properties"]["checked"]
    assert "boolean" == schema_json["properties"]["checked"]["type"]
예제 #2
0
def test_load_definitions():
    # given
    config = {
        "schema_dir": "tap_test_data_generator/schemas",
        "metadata_dir": "tap_test_data_generator/metadatas",
        "object_repository_dir": "tap_test_data_generator/object-repositories",
        "static_input_dir": "",
        "record_number": 100,
        "apply_record_number_on_pairwise": True,
        "data_locale_list": ["en_US", "fr_FR"]
    }
    catalog = discover(config)
    stream = catalog.get_stream("sample")
    schema_json = load_schema_json(config, stream)
    # when
    definitions = load_definitions(schema_json, config)
    # then
    assert definitions is not None
    assert "http://example.com/example.json/#" in definitions
    assert "$id" in definitions["http://example.com/example.json/#"]
    assert "http://example.com/example.json/#" == definitions["http://example.com/example.json/#"]["$id"]
    assert "type" in definitions["http://example.com/example.json/#"]
    assert "object" == definitions["http://example.com/example.json/#"]["type"]
    assert "required" in definitions["http://example.com/example.json/#"]
    assert ['checked', 'dimensions', 'id', 'name', 'color', 'price', 'tags', 'hour'] == \
           definitions["http://example.com/example.json/#"]["required"]
예제 #3
0
def test_discover():
    config = {
        "schema_dir": "tap_test_data_generator/schemas",
        "metadata_dir": "tap_test_data_generator/metadatas",
        "object_repository_dir": "tap_test_data_generator/object-repositories",
        "static_input_dir": "",
        "record_number": 100,
        "apply_record_number_on_pairwise": True,
        "data_locale_list": ["en_US", "fr_FR"]
    }
    catalog = discover(config)
    assert catalog is not None
    catalog_dict = catalog.to_dict()
    assert "streams" in catalog_dict

    item_number = 0
    for stream in catalog_dict["streams"]:
        item_number += 1
        assert "tap_stream_id" in stream
        # test the "sample stream"
        if "sample" == stream["tap_stream_id"]:
            assert "schema" in stream
            assert "properties" in stream["schema"]
            assert "checked" in stream["schema"]["properties"]
            assert "type" in stream["schema"]["properties"]["checked"]
            assert "boolean" == stream["schema"]["properties"]["checked"][
                "type"]
    # test item number
    assert item_number is 3
def test_generate_dictionary_no_pairs():
    # given
    config = {
        "schema_dir": "tap_test_data_generator/schemas",
        "metadata_dir": "tap_test_data_generator/metadatas",
        "object_repository_dir": "tap_test_data_generator/object-repositories",
        "static_input_dir": "",
        "record_number": 100,
        "apply_record_number_on_pairwise": True,
        "data_locale_list": ["en_US", "fr_FR"]
    }
    object_repositories = load_repositories(config)
    catalog = discover(config)
    stream = catalog.get_stream("sample")
    schema_json = load_schema_json(config, stream)
    definitions = load_definitions(schema_json, config)
    faker_factory = Faker()
    # when
    generated_dict = data_generator.generate_dictionary(
        None, schema_json, {}, faker_factory, object_repositories, None,
        definitions, 5)
    # then
    assert generated_dict is not None
    assert "checked" in generated_dict
    assert "dimensions" in generated_dict
    assert "id" in generated_dict
    assert "color" in generated_dict
    assert "price" in generated_dict
    assert "tags" in generated_dict
    assert "hour" in generated_dict
예제 #5
0
def test_load_definitions_not_JSON():
    # given
    config = {
        "schema_dir": "tap_test_data_generator/wrong_schemas",
        "metadata_dir": "tap_test_data_generator/metadatas",
        "object_repository_dir": "tap_test_data_generator/object-repositories",
        "static_input_dir": "",
        "record_number": 100,
        "apply_record_number_on_pairwise": True,
        "data_locale_list": ["en_US", "fr_FR"]
    }
    catalog = discover(config)
    stream = catalog.get_stream("sample")
    schema_json = load_schema_json(config, stream)
    # when
    definitions = load_definitions(schema_json, config)
    # then
    assert definitions is not None
def test_extract_value_lists():
    # given
    config = {
        "schema_dir": "tap_test_data_generator/schemas",
        "metadata_dir": "tap_test_data_generator/metadatas",
        "object_repository_dir": "tap_test_data_generator/object-repositories",
        "static_input_dir": "",
        "record_number": 100,
        "apply_record_number_on_pairwise": True,
        "data_locale_list": ["en_US", "fr_FR"]
    }
    object_repositories = load_repositories(config)
    catalog = discover(config)
    stream = catalog.get_stream("sample")
    schema_json = load_schema_json(config, stream)
    definitions = load_definitions(schema_json, config)
    # when
    value_lists = data_generator.extract_value_lists(None, schema_json,
                                                     object_repositories,
                                                     definitions)
    # then
    assert value_lists is not None
    assert "checked" in value_lists
    assert [True, False] == value_lists["checked"]
    assert "dimensions" in value_lists
    assert [{
        'width': 5,
        'height': 10
    }, {
        'width': 10,
        'height': 20
    }, {
        'width': 20,
        'height': 40
    }, None] == value_lists["dimensions"]
    assert "color" in value_lists
    assert ['green', 'yellow', 'red'] == value_lists["color"]