示例#1
0
def test__check_get_schematic_dirname(test_flaskerize_args, tmp_path):
    tmp_pkg_path = os.path.join(tmp_path, "some/pkg")
    os.makedirs(tmp_pkg_path)
    fz = Flaskerize(test_flaskerize_args)

    with pytest.raises(ValueError):
        fz._check_get_schematic_dirname(tmp_pkg_path)
示例#2
0
def test__split_pkg_schematic_only_grabs_last_delim(test_flaskerize_args,
                                                    tmp_path):
    fz = Flaskerize(test_flaskerize_args)
    pkg, schematic = fz._split_pkg_schematic(
        "path/to/:my:/schematic:schematic")
    assert pkg == "path/to/:my:/schematic"
    assert schematic == "schematic"
示例#3
0
def test__check_validate_package(test_flaskerize_args, tmp_path):
    tmp_app_path = os.path.join(tmp_path, "test.py")
    fz = Flaskerize(test_flaskerize_args)

    with pytest.raises(ModuleNotFoundError):
        fz._check_validate_package(
            os.path.join(tmp_path, "pkg that does not exist"))
示例#4
0
def test__split_pkg_schematic_works_with_full_path(test_flaskerize_args,
                                                   tmp_path):
    tmp_app_path = os.path.join(tmp_path, "test.py")
    fz = Flaskerize(test_flaskerize_args)
    pkg, schematic = fz._split_pkg_schematic("path/to/schematic:schematic")
    assert pkg == "path/to/schematic"
    assert schematic == "schematic"
示例#5
0
def test__check_get_schematic_dirname_doesnt_append_if_already_schematics(
        test_flaskerize_args, tmp_path):
    tmp_pkg_path = os.path.join(tmp_path, "some/pkg/schematics")
    os.makedirs(tmp_pkg_path)
    fz = Flaskerize(test_flaskerize_args)

    dirname = fz._check_get_schematic_dirname(tmp_pkg_path)

    expected = tmp_pkg_path
    assert dirname == expected
示例#6
0
def test_bundle_calls_does_not_call_attach_w_dry_run(tmp_path):
    with patch.object(Flaskerize, "attach") as mock:
        fz = Flaskerize(
            "fz bundle --from test/build/ --to app:create_app --dry-run".split(
            ))

        mock.assert_not_called()
示例#7
0
def test_schematic_from_Flaskerize(tmp_path):
    from flaskerize.parser import Flaskerize

    expected = """#!/usr/bin/env python

from setuptools import setup, find_packages

setup(
    name="test",
    version="0.1.0",
    description="Project built by Flaskerize",
    author="AJ",
    author_email="*****@*****.**",
    url="https://github.com/apryor6/flaskerize",
    packages=find_packages(),
    install_requires=['thingy>0.3.0', 'widget>=2.4.3', 'doodad>4.1.0'],
)"""
    from_dir = str(tmp_path)
    name = "test"
    COMMAND = f"""fz generate setup {name} --from-dir {from_dir} --install-requires thingy>0.3.0 widget>=2.4.3 doodad>4.1.0 --author AJ --author-email [email protected]"""
    result = Flaskerize(COMMAND.split())

    outfile = os.path.join(tmp_path, "setup.py")
    assert os.path.isfile(outfile)
    with open(outfile, "r") as fid:
        content = fid.read()
    assert content == expected
示例#8
0
def test_with_full_path(tmp_path):
    import os

    from flaskerize.parser import Flaskerize

    schematic_dir = os.path.join(tmp_path, "schematics")
    schematic_path = os.path.join(schematic_dir, "doodad/")
    schema_filename = os.path.join(schematic_path, "schema.json")
    schematic_files_path = os.path.join(schematic_path, "files/")
    template_filename = os.path.join(schematic_files_path,
                                     "test_file.txt.template")
    os.makedirs(schematic_path)
    os.makedirs(schematic_files_path)
    SCHEMA_CONTENTS = """{"options": []}"""
    with open(schema_filename, "w") as fid:
        fid.write(SCHEMA_CONTENTS)
    CONTENTS = "{{ secret }}"
    with open(template_filename, "w") as fid:
        fid.write(CONTENTS)

    outdir = os.path.join(tmp_path, "test/")
    fz = Flaskerize(
        f"fz generate {tmp_path}:doodad name --from-dir {outdir}".split())

    assert os.path.isfile(os.path.join(tmp_path, "test/test_file.txt"))
示例#9
0
def test__check_render_schematic(test_flaskerize_args, tmp_path):
    tmp_app_path = os.path.join(tmp_path)
    fz = Flaskerize(test_flaskerize_args)
    mock = fz.render_schematic = MagicMock()
    result = fz._check_render_schematic(
        pkg_schematic="test",
        render_dirname="test",
        src_path=str(tmp_path),
        name="test",
        args=[],
        full_schematic_path="some_path",
        dry_run=True,
    )
    mock.assert_called_with(
        "some_path",
        render_dirname="test",
        src_path=str(tmp_path),
        name="test",
        dry_run=True,
        args=[],
    )
示例#10
0
def test_schematic_from_Flaskerize(tmp_path):
    from flaskerize.parser import Flaskerize

    assert Flaskerize(
        f"fz generate schematic --from-dir {tmp_path} test_schematic".split())
示例#11
0
def test_bundle_calls_attach(tmp_path):
    with patch("flaskerize.attach.attach") as mock:
        fz = Flaskerize(
            "fz bundle --from test/build/ --to app:create_app".split())
        mock.assert_called_once()
示例#12
0
def test__split_pkg_schematic(test_flaskerize_args, tmp_path):
    with pytest.raises(ValueError):
        tmp_app_path = os.path.join(tmp_path, "test.py")
        fz = Flaskerize(test_flaskerize_args)
        pkg, schematic = fz._split_pkg_schematic(":schematic")
示例#13
0
def test__split_pkg_schematic_works_with_full_path(test_flaskerize_args,
                                                   tmp_path):
    fz = Flaskerize(test_flaskerize_args)
    pkg, schematic = fz._split_pkg_schematic("path/to/schematic:schematic")
    assert pkg == "path/to/schematic"
    assert schematic == "schematic"
示例#14
0
def test__split_pkg_schematic_works_with_pkg(test_flaskerize_args, tmp_path):
    fz = Flaskerize(test_flaskerize_args)
    pkg, schematic = fz._split_pkg_schematic("my_pkg:schematic")
    assert pkg == "my_pkg"
    assert schematic == "schematic"
示例#15
0
def test__split_pkg_schematic(test_flaskerize_args, tmp_path):
    with pytest.raises(ValueError):
        fz = Flaskerize(test_flaskerize_args)
        pkg, schematic = fz._split_pkg_schematic(":schematic")