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
Beispiel #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"]
Beispiel #3
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"]