Exemplo n.º 1
0
def test_schemas_are_valid_spec_missing(tmpdir):
    """
    GIVEN spec is missing
    WHEN schemas_are_valid is called with the spec filename
    THEN CacheError is raised.
    """
    path_tmpdir = pathlib.Path(tmpdir)
    spec_filename = "spec.json"
    spec_file = path_tmpdir / spec_filename

    with pytest.raises(exceptions.CacheError):
        cache.schemas_are_valid(str(spec_file))
Exemplo n.º 2
0
def test_schemas_are_valid_spec_not_file(tmpdir):
    """
    GIVEN spec is actually a folder
    WHEN schemas_are_valid is called with the spec filename
    THEN CacheError is raised.
    """
    path_tmpdir = pathlib.Path(tmpdir)
    spec_filename = "spec.json"
    spec_file = path_tmpdir / spec_filename
    spec_file.mkdir()

    with pytest.raises(exceptions.CacheError):
        cache.schemas_are_valid(str(spec_file))
Exemplo n.º 3
0
def test_schemas_are_valid_cache_folder(tmpdir):
    """
    GIVEN spec in a file
    WHEN schemas_are_valid is called with the spec filename
    THEN schemas_valid returns True if it is called afterwards.
    """
    path_tmpdir = pathlib.Path(tmpdir)
    spec_filename = "spec.json"
    spec_file = path_tmpdir / spec_filename
    spec_file.write_text("spec 1", encoding="utf-8")

    cache.schemas_are_valid(str(spec_file))

    assert cache.schemas_valid(str(spec_file)) is True
Exemplo n.º 4
0
def test_schemas_are_valid(tmpdir):
    """
    GIVEN spec in a file and the cache is actually a folder
    WHEN schemas_are_valid is called with the spec filename
    THEN schemas_valid returns True if it is called afterwards.
    """
    path_tmpdir = pathlib.Path(tmpdir)
    spec_filename = "spec.json"
    spec_file = path_tmpdir / spec_filename
    spec_file.write_text("spec 1", encoding="utf-8")
    cache_file = (
        path_tmpdir /
        f"__open_alchemy_{cache.calculate_hash(spec_filename)}_cache__")
    cache_file.mkdir()
    cache_sub_file = cache_file / "some.file"
    cache_sub_file.write_text("some contents")

    cache.schemas_are_valid(str(spec_file))

    assert cache.schemas_valid(str(spec_file)) is True
Exemplo n.º 5
0
def test_schemas_are_valid_cache_exists(tmpdir, cache_contents):
    """
    GIVEN spec in a file
    WHEN schemas_are_valid is called with the spec filename
    THEN schemas_valid returns True if it is called afterwards.
    """
    path_tmpdir = pathlib.Path(tmpdir)
    spec_filename = "spec.json"
    spec_file = path_tmpdir / spec_filename
    spec_file.write_text("spec 1", encoding="utf-8")
    cache_file = (
        path_tmpdir /
        f"__open_alchemy_{cache.calculate_hash(spec_filename)}_cache__")
    cache_file.write_text(
        cache_contents,
        encoding="utf-8",
    )

    cache.schemas_are_valid(str(spec_file))

    assert cache.schemas_valid(str(spec_file)) is True