tests Package

tests Package

Tests.

diecutter.tests.demo_server()

Return (running) WebTest’s StopableWSGIServer for demo.

diecutter.tests.demo_settings(**settings)
diecutter.tests.demo_template_dir()

Return absolute path to diecutter’s demo template dir.

diecutter.tests.webtest_server(application)

Return (running) WebTest’s StopableWSGIServer for application.

contextextractors Module

Tests around diecutter.contextextractors.

class diecutter.tests.contextextractors.ExtractContextTestCase(methodName='runTest')

Bases: unittest.case.TestCase

Test diecutter.contextextractors.extract_context().

extractor_factory(output)

Return callable that takes a request and returns output.

request_factory(extractors={}, content_type='')

Return request with extractors setting and content_type.

test_mapping()

extract_context() uses extractor matching content-type.

test_no_mapping()

extract_context() raises exception if content-type isn’t supported.

class diecutter.tests.contextextractors.GetContextExtractorsTestCase(methodName='runTest')

Bases: unittest.case.TestCase

Test contextextractors.get_context_extractors().

request_factory(settings={})

Return mock request instance.

test_custom_configuration()

get_context_extractors() reads request.registry.settings.

test_default_configuration()

get_context_extractors() with no settings returns default ones.

class diecutter.tests.contextextractors.IniTestCase(methodName='runTest')

Bases: unittest.case.TestCase

Test diecutter.contextextractors.extract_ini_context.

request_factory(data={})

Return mock request instance.

test_config_parser()

extract_ini_context() accepts standard ConfigParser input.

test_empty()

extract_ini_context() with empty data returns empty context.

test_globals()

extract_ini_context() accepts input with no sections.

test_parsing_error()

extract_ini_context() raises DataParsingError in case of error.

class diecutter.tests.contextextractors.JsonTestCase(methodName='runTest')

Bases: unittest.case.TestCase

Test diecutter.contextextractors.extract_json_context.

request_factory(data={})

Return mock request instance.

test_copy()

extract_post_request() returns copy of request’s json_body.

test_data()

extract_post_request() returns request.json_body data.

class diecutter.tests.contextextractors.PostTestCase(methodName='runTest')

Bases: unittest.case.TestCase

Test diecutter.contextextractors.extract_post_context.

request_factory(data={})

Return mock request instance.

test_copy()

extract_post_request() returns copy of request’s data.

test_data()

extract_post_request() returns request.post data.

test_multiple_values()

extract_post_request() handles lists.

functional Module

Functional tests: run test server and make requests on it.

class diecutter.tests.functional.FunctionalTestCase(methodName='runTest')

Bases: unittest.case.TestCase

setUp()

Run test server with temporary settings.

tearDown()

Cleanup temporary template dir.

test_get_directory()

GET a directory resource returns directory listing.

test_get_file()

GET a file resource returns file contents.

test_get_file_404()

GET a file resource that doesn’t exist returns HTTP 404.

test_post_directory_targz()

POST context for directory returns TAR.GZ file content.

test_post_directory_zip()

POST context for directory with accept header returns ZIP file.

test_post_file()

POST context for template returns rendered content.

test_put_file()

PUT a file as attachment writes file in templates directory.

test_put_file_subdirs()

PUT a file in subdirectories creates those directories.

test_version()

GET on root displays “hello” and version number as JSON.

github Module

resources Module

Tests around diecutter.resources.

class diecutter.tests.resources.DirResourceTestCase(methodName='runTest')

Bases: unittest.case.TestCase

Test diecutter.resources.DirResource.

test_content_type()

DirResource.content_type is ‘application/zip’.

test_exists_dir()

DirResource.exists is True if path points a directory.

test_exists_false()

DirResource.exists is False if dir doesn’t exist at path.

test_exists_file()

DirResource.exists is False if path points a file.

test_has_tree_template()

DirResource.has_tree_template() checks if .diecutter-tree exists.

test_no_trailing_slash()

DirResource with no trailing slash uses dirname as prefix.

test_read_empty()

DirResource.read() empty dir returns empty string.

test_read_nested()

DirResource.read() recurses nested files and directories.

test_read_one_flat()

DirResource.read() one file returns one filename.

test_read_two_flat()

DirResource.read() two files returns two filenames.

test_render()

DirResource.render() returns an iterable of rendered templates.

test_render_dynamic_tree()

DirResource.render_tree() uses .diecutter-tree template.

test_render_dynamic_tree_relative_paths()

Raises exception if .diecutter-tree contains some non relative path.

Warning

This is a security test!

Since dynamic tree templates can be defined by user, we have to check templates path. We don’t want users to be able to render arbitrary locations on the filesystem.

test_render_template_error()
test_render_tree()

DirResource.render_tree() recurses nested files and directories.

test_trailing_slash()

DirResource with trailing slash uses dirname as prefix.

class diecutter.tests.resources.FileResourceTestCase(methodName='runTest')

Bases: unittest.case.TestCase

Test diecutter.resources.FileResource.

test_content_type()

FileResource.content_type is ‘text/plain’.

test_exists_dir()

FileResource.exists is False if path points a directory.

test_exists_false()

FileResource.exists is False if file doesn’t exist at path.

test_exists_file()

FileResource.exists is True if path points a file.

test_read_empty()

FileResource.read() empty file returns empty string.

test_read_utf8()

FileResource.read() decodes UTF-8 files.

test_render()

FileResource.render() generates rendered template against context.

It returns an iteratable or generator.

test_render_error()

FileResource.render() raises TemplateError in case of fail.

class diecutter.tests.resources.ResourceTestCase(methodName='runTest')

Bases: unittest.case.TestCase

Test diecutter.resources.Resource.

test_content_type()

Resource.content_type property must be overriden by subclasses.

test_exists()

Resource.exists property must be overriden by subclasses.

test_init()

Resource constructor accepts optional path and engine.

test_read()

Resource.read() must be overriden by subclasses.

test_render()

Resource.render() must be overriden by subclasses.

test_render_filename()

Resource.render_filename() renders filename against context.