Beispiel #1
0
def test_delete_python_file(tmpdir):
    """Test to remove unwanted files."""
    target_path = tmpdir.strpath + '/collective.sample'
    package_path = target_path + '/src/collective/sample'
    views_path = package_path + '/views/'
    os.makedirs(target_path)
    os.makedirs(package_path)
    os.makedirs(views_path)
    file_name = u'configure.zcml.example'
    file_path = views_path + file_name
    open(file_path, 'a').close()
    file_name = u'myview.py'
    file_path = views_path + file_name
    open(file_path, 'a').close()
    configurator = Configurator(
        template='bobtemplates.plone:view',
        target_directory='collective.sample',
        bobconfig={
            'non_interactive': True,
        },
        variables={
            'view_name': 'myview',
            'view_python_class': False,
            'view_python_file_name': 'myview',
            'view_template': True,
            'package_folder': package_path,
        },
    )
    view._delete_unwanted_files(configurator)
    if os.path.isfile(file_path):
        pytest.raises(ValidationError)
Beispiel #2
0
def test_file_names(tmpdir):
    """Test files names of template and Python class file."""
    target_path = tmpdir.strpath + '/collective.sample'
    package_path = target_path + '/src/collective/sample'
    views_path = package_path + '/views/'
    os.makedirs(target_path)
    os.makedirs(package_path)
    os.makedirs(views_path)
    python_file_name = u'my_view.py'
    python_file_path = views_path + python_file_name
    open(python_file_path, 'a').close()
    template_file_name = u'my-view.pt'
    template_file_path = views_path + template_file_name
    open(template_file_path, 'a').close()
    configurator = Configurator(
        template='bobtemplates.plone:view',
        target_directory='collective.sample',
        bobconfig={
            'non_interactive': True,
        },
        variables={
            'view_python_class': True,
            'view_name_normalized': 'my_view',
            'view_template': True,
            'view_template_name': 'my-view',
            'view_name_normalized': 'my_view',
            'view_python_file_name': 'my_view',
            'package_folder': package_path,
        },
    )
    view._delete_unwanted_files(configurator)
    if not os.path.isfile(template_file_path):
        pytest.raises(ValidationError)

    if not os.path.isfile(python_file_path):
        pytest.raises(ValidationError)