Merge pull request #3387 from mmerickel/src-folder-refactor
refactor pyramid tests into a tests folder and package into a src folder
7 files deleted
5 files added
7 files modified
296 files renamed
New file |
| | |
| | | [run] |
| | | source = |
| | | pyramid |
| | | tests |
| | | omit = |
| | | src/pyramid/scaffolds/tests.py |
| | | |
| | | [paths] |
| | | source = |
| | | src/pyramid |
| | | */site-packages/pyramid |
| | | |
| | | [report] |
| | | show_missing = true |
| | | precision = 2 |
| | |
| | | dependencies, start a server, and hit a URL on the server, can be run like |
| | | so: |
| | | |
| | | $ ./scaffoldtests.sh |
| | | |
| | | Alternatively: |
| | | |
| | | $ tox -e{py27,py34,py35,pyt36,py37,pypy}-scaffolds |
| | | $ tox -e{py27,py34,py35,py36,py37,pypy}-scaffolds |
| | | |
| | | |
| | | Test Coverage |
| | | ------------- |
| | | |
| | | - The codebase *must* have 100% test statement coverage after each commit. You |
| | | can test coverage via `./coverage.sh` (which itself just executes `tox |
| | | -epy2-cover,py3-cover,coverage`). |
| | | can test coverage via `tox -epy2-cover,py3-cover,coverage`. |
| | | |
| | | |
| | | Documentation Coverage and Building HTML Documentation |
| | |
| | | changed to reflect the bug fix, ideally in the same commit that fixes the bug |
| | | or adds the feature. To build and review docs, use the following steps. |
| | | |
| | | 1. In the main Pyramid checkout directory, run `./builddocs.sh` (which just |
| | | turns around and runs `tox -e docs`): |
| | | 1. In the main Pyramid checkout directory, run `tox -e docs`: |
| | | |
| | | $ ./builddocs.sh |
| | | $ tox -e docs |
| | | |
| | | 2. Open the `docs/_build/html/index.html` file to see the resulting HTML |
| | | rendering. |
| | |
| | | graft pyramid |
| | | graft src/pyramid |
| | | graft docs |
| | | prune docs/_build |
| | | graft tests |
| | | |
| | | include README.rst |
| | | include CHANGES.rst HISTORY.rst BFG_HISTORY.rst |
| | | include CONTRIBUTORS.txt LICENSE.txt COPYRIGHT.txt |
| | | |
| | | include contributing.md RELEASING.txt |
| | | include tox.ini appveyor.yml .travis.yml rtd.txt |
| | | include .coveragerc tox.ini appveyor.yml .travis.yml rtd.txt |
| | | graft .github |
| | | |
| | | include HACKING.txt hacking-tox.ini |
| | | include builddocs.sh coverage.sh scaffoldtests.sh |
| | | include TODO.txt |
| | | |
| | | global-exclude __pycache__ *.py[cod] |
| | |
| | | - Make sure all scaffold tests pass (CPython 2.7, 3.4, 3.5, 3.6, and 3.7, and |
| | | PyPy on UNIX; this doesn't work on Windows): |
| | | |
| | | $ ./scaffoldtests.sh |
| | | $ tox -e{py27,py34,py35,py36,py37,pypy}-scaffolds |
| | | |
| | | - For each ``pyramid-cookiecutter-*``, make a new branch off "master" with the |
| | | same name to align with the new Pyramid release branch name. |
| | |
| | | |
| | | - Change setup.py version to the release version number. |
| | | |
| | | - Make sure PyPI long description renders (requires ``readme_renderer`` |
| | | installed into your Python):: |
| | | - Make sure PyPI long description renders:: |
| | | |
| | | $ python setup.py check -r -s -m |
| | | $ tox -e lint |
| | | |
| | | - Create a release tag. |
| | | |
| | | - Make sure your Python has ``setuptools-git``, ``twine``, and ``wheel`` |
| | | installed and release to PyPI:: |
| | | $ git tag X.X |
| | | |
| | | $ python setup.py sdist bdist_wheel |
| | | - Build the sdist and wheel. |
| | | |
| | | $ tox -e build |
| | | |
| | | - Upload the artifacts to PyPI: |
| | | |
| | | $ twine upload dist/pyramid-X.X-* |
| | | |
| | | - Configure RTD to publish the new release version of the docs. |
| | |
| | | TOXENV: "py36" |
| | | - PYTHON: "C:\\Python35" |
| | | TOXENV: "py35" |
| | | - PYTHON: "C:\\Python34" |
| | | TOXENV: "py34" |
| | | - PYTHON: "C:\\Python27" |
| | | TOXENV: "py27" |
| | | |
| | |
| | | zip_ok = false |
| | | |
| | | [nosetests] |
| | | match=^test |
| | | where=pyramid |
| | | nocapture=1 |
| | | match = ^test |
| | | tests = tests |
| | | nocapture = 1 |
| | | |
| | | [aliases] |
| | | dev = develop easy_install pyramid[testing] |
| | |
| | | *.egg-info/* |
| | | ignore-default-rules = true |
| | | ignore-bad-ideas = |
| | | pyramid/tests/pkgs/localeapp/* |
| | | tests/pkgs/localeapp/* |
| | |
| | | author_email="pylons-discuss@googlegroups.com", |
| | | url="https://trypyramid.com", |
| | | license="BSD-derived (http://www.repoze.org/LICENSE.txt)", |
| | | packages=find_packages(), |
| | | packages=find_packages('src', exclude=['tests']), |
| | | package_dir={'': 'src'}, |
| | | include_package_data=True, |
| | | zip_safe=False, |
| | | python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*', |
| | |
| | | 'docs': docs_extras, |
| | | }, |
| | | tests_require=tests_require, |
| | | test_suite="pyramid.tests", |
| | | test_suite="tests", |
| | | entry_points="""\ |
| | | [pyramid.scaffold] |
| | | starter=pyramid.scaffolds:StarterProjectTemplate |
New file |
| | |
| | | [app:myapp] |
| | | use = call:tests.test_paster:make_dummyapp |
| | | |
| | | foo = %(bar)s |
File was renamed from pyramid/tests/pkgs/conflictapp/__init__.py |
| | |
| | | config.set_authentication_policy(AuthTktAuthenticationPolicy( |
| | | 'seekri1t', hashalg='sha512')) |
| | | config.set_authorization_policy(ACLAuthorizationPolicy()) |
| | | config.include('pyramid.tests.pkgs.conflictapp.included') |
| | | config.include('tests.pkgs.conflictapp.included') |
File was renamed from pyramid/tests/pkgs/defpermbugapp/__init__.py |
| | |
| | | from pyramid.authentication import AuthTktAuthenticationPolicy |
| | | authn_policy = AuthTktAuthenticationPolicy('seekt1t', hashalg='sha512') |
| | | authz_policy = ACLAuthorizationPolicy() |
| | | config.scan('pyramid.tests.pkgs.defpermbugapp') |
| | | config.scan('tests.pkgs.defpermbugapp') |
| | | config._set_authentication_policy(authn_policy) |
| | | config._set_authorization_policy(authz_policy) |
| | | config.set_default_permission('private') |
File was renamed from pyramid/tests/pkgs/eventonly/__init__.py |
| | |
| | | |
| | | def includeme(config): |
| | | config.add_subscriber_predicate('yup', Yup) |
| | | config.scan('pyramid.tests.pkgs.eventonly') |
| | | config.scan('tests.pkgs.eventonly') |
| | | |
File was renamed from pyramid/tests/pkgs/forbiddenview/__init__.py |
| | |
| | | config.set_default_permission('a') |
| | | config.add_route('foo', '/foo') |
| | | config.add_route('bar', '/bar') |
| | | config.scan('pyramid.tests.pkgs.forbiddenview') |
| | | config.scan('tests.pkgs.forbiddenview') |
| | | |
File was renamed from pyramid/tests/pkgs/includeapp1/root.py |
| | |
| | | |
| | | def configure(config): |
| | | config.add_view(aview) |
| | | config.include('pyramid.tests.pkgs.includeapp1.two.configure') |
| | | config.include('tests.pkgs.includeapp1.two.configure') |
| | | config.commit() |
| | | |
File was renamed from pyramid/tests/pkgs/includeapp1/three.py |
| | |
| | | |
| | | def configure(config): |
| | | config.add_view(aview, name='three') |
| | | config.include('pyramid.tests.pkgs.includeapp1.two.configure') # should not cycle |
| | | config.include('tests.pkgs.includeapp1.two.configure') # should not cycle |
| | | config.add_view(aview) # will be overridden by root when resolved |
| | | |
File was renamed from pyramid/tests/pkgs/includeapp1/two.py |
| | |
| | | |
| | | def configure(config): |
| | | config.add_view(aview, name='two') |
| | | config.include('pyramid.tests.pkgs.includeapp1.three.configure') |
| | | config.include('tests.pkgs.includeapp1.three.configure') |
| | | config.add_view(aview) # will be overridden by root when resolved |
File was renamed from pyramid/tests/pkgs/notfoundview/__init__.py |
| | |
| | | config.add_route('foo2', '/foo/') |
| | | config.add_route('bar', '/bar/') |
| | | config.add_route('baz', '/baz') |
| | | config.scan('pyramid.tests.pkgs.notfoundview') |
| | | config.scan('tests.pkgs.notfoundview') |
| | | |
New file |
| | |
| | | def includeme(config): |
| | | config.add_static_view('/', 'tests:fixtures') |
| | | |
New file |
| | |
| | | def includeme(config): |
| | | config.add_static_view('/static', 'tests:fixtures') |
| | | config.include(includeme2, route_prefix='/prefix') |
| | | |
| | | def includeme2(config): |
| | | config.add_static_view('/static', 'tests:fixtures/static') |
| | | |
File was renamed from pyramid/tests/pkgs/staticpermapp/__init__.py |
| | |
| | | authz_policy = ACLAuthorizationPolicy() |
| | | config._set_authentication_policy(authn_policy) |
| | | config._set_authorization_policy(authz_policy) |
| | | config.add_static_view('allowed', 'pyramid.tests:fixtures/static/') |
| | | config.add_static_view('protected', 'pyramid.tests:fixtures/static/', |
| | | config.add_static_view('allowed', 'tests:fixtures/static/') |
| | | config.add_static_view('protected', 'tests:fixtures/static/', |
| | | permission='view') |
| | | config.add_static_view('factory_protected', |
| | | 'pyramid.tests:fixtures/static/', |
| | | 'tests:fixtures/static/', |
| | | permission='view', |
| | | factory=LocalRootFactory) |
New file |
| | |
| | | def includeme(config): |
| | | config.scan('tests.pkgs.viewdecoratorapp') |
| | | |
File was renamed from pyramid/tests/test_asset.py |
| | |
| | | self.assertEqual(package_name, None) |
| | | |
| | | def test_rel_spec(self): |
| | | pkg = 'pyramid.tests' |
| | | pkg = 'tests' |
| | | path = 'test_asset.py' |
| | | package_name, filename = self._callFUT(path, pkg) |
| | | self.assertEqual(package_name, 'pyramid.tests') |
| | | self.assertEqual(package_name, 'tests') |
| | | self.assertEqual(filename, 'test_asset.py') |
| | | |
| | | def test_abs_spec(self): |
| | | pkg = 'pyramid.tests' |
| | | pkg = 'tests' |
| | | path = 'pyramid.nottests:test_asset.py' |
| | | package_name, filename = self._callFUT(path, pkg) |
| | | self.assertEqual(package_name, 'pyramid.nottests') |
| | |
| | | self.assertEqual(filename, 'test_asset.py') |
| | | |
| | | def test_package_name_is_package_object(self): |
| | | import pyramid.tests |
| | | pkg = pyramid.tests |
| | | import tests |
| | | pkg = tests |
| | | path = 'test_asset.py' |
| | | package_name, filename = self._callFUT(path, pkg) |
| | | self.assertEqual(package_name, 'pyramid.tests') |
| | | self.assertEqual(package_name, 'tests') |
| | | self.assertEqual(filename, 'test_asset.py') |
| | | |
| | | |
| | |
| | | self.assertEqual(result, '/abc') |
| | | |
| | | def test_pkgrelative(self): |
| | | result = self._callFUT('abc', 'pyramid.tests') |
| | | result = self._callFUT('abc', 'tests') |
| | | self.assertEqual(result, os.path.join(here, 'abc')) |
| | | |
| | | class Test_asset_spec_from_abspath(unittest.TestCase): |
| | |
| | | |
| | | def test_abspath_startswith_package_path(self): |
| | | abspath = os.path.join(here, 'fixtureapp') |
| | | pkg = DummyPackage('pyramid.tests') |
| | | pkg = DummyPackage('tests') |
| | | pkg.__file__ = 'file' |
| | | result = self._callFUT(abspath, pkg) |
| | | self.assertEqual(result, 'pyramid:fixtureapp') |
| | | self.assertEqual(result, 'tests:fixtureapp') |
| | | |
| | | def test_abspath_doesnt_startwith_package_path(self): |
| | | pkg = DummyPackage('pyramid.tests') |
| | | pkg = DummyPackage('tests') |
| | | result = self._callFUT(here, pkg) |
| | | self.assertEqual(result, here) |
| | | |
File was renamed from pyramid/tests/test_authentication.py |
| | |
| | | self.assertEqual(len(self.messages), 1) |
| | | self.assertEqual( |
| | | self.messages[0], |
| | | 'pyramid.tests.test_authentication.MyAuthenticationPolicy.' |
| | | 'tests.test_authentication.MyAuthenticationPolicy.' |
| | | 'authenticated_userid: call to unauthenticated_userid returned ' |
| | | 'None; returning None') |
| | | |
| | |
| | | self.assertEqual(len(self.messages), 1) |
| | | self.assertEqual( |
| | | self.messages[0], |
| | | "pyramid.tests.test_authentication.MyAuthenticationPolicy." |
| | | "tests.test_authentication.MyAuthenticationPolicy." |
| | | "authenticated_userid: there was no groupfinder callback; " |
| | | "returning 'fred'") |
| | | |
| | |
| | | self.assertEqual(len(self.messages), 1) |
| | | self.assertEqual( |
| | | self.messages[0], |
| | | 'pyramid.tests.test_authentication.MyAuthenticationPolicy.' |
| | | 'tests.test_authentication.MyAuthenticationPolicy.' |
| | | 'authenticated_userid: groupfinder callback returned None; ' |
| | | 'returning None') |
| | | |
| | |
| | | self.assertEqual(len(self.messages), 1) |
| | | self.assertEqual( |
| | | self.messages[0], |
| | | "pyramid.tests.test_authentication.MyAuthenticationPolicy." |
| | | "tests.test_authentication.MyAuthenticationPolicy." |
| | | "authenticated_userid: groupfinder callback returned []; " |
| | | "returning 'fred'") |
| | | |
| | |
| | | self.assertEqual(len(self.messages), 1) |
| | | self.assertEqual( |
| | | self.messages[0], |
| | | "pyramid.tests.test_authentication.MyAuthenticationPolicy." |
| | | "tests.test_authentication.MyAuthenticationPolicy." |
| | | "authenticated_userid: use of userid 'system.Authenticated' is " |
| | | "disallowed by any built-in Pyramid security policy, returning " |
| | | "None") |
| | |
| | | self.assertEqual(len(self.messages), 1) |
| | | self.assertEqual( |
| | | self.messages[0], |
| | | "pyramid.tests.test_authentication.MyAuthenticationPolicy." |
| | | "tests.test_authentication.MyAuthenticationPolicy." |
| | | "authenticated_userid: use of userid 'system.Everyone' is " |
| | | "disallowed by any built-in Pyramid security policy, returning " |
| | | "None") |
| | |
| | | self.assertEqual(len(self.messages), 1) |
| | | self.assertEqual( |
| | | self.messages[0], |
| | | "pyramid.tests.test_authentication.MyAuthenticationPolicy." |
| | | "tests.test_authentication.MyAuthenticationPolicy." |
| | | "effective_principals: unauthenticated_userid returned None; " |
| | | "returning ['system.Everyone']") |
| | | |
| | |
| | | self.assertEqual(len(self.messages), 2) |
| | | self.assertEqual( |
| | | self.messages[0], |
| | | 'pyramid.tests.test_authentication.MyAuthenticationPolicy.' |
| | | 'tests.test_authentication.MyAuthenticationPolicy.' |
| | | 'effective_principals: groupfinder callback is None, so groups ' |
| | | 'is []') |
| | | self.assertEqual( |
| | | self.messages[1], |
| | | "pyramid.tests.test_authentication.MyAuthenticationPolicy." |
| | | "tests.test_authentication.MyAuthenticationPolicy." |
| | | "effective_principals: returning effective principals: " |
| | | "['system.Everyone', 'system.Authenticated', 'fred']") |
| | | |
| | |
| | | self.assertEqual(len(self.messages), 2) |
| | | self.assertEqual( |
| | | self.messages[0], |
| | | 'pyramid.tests.test_authentication.MyAuthenticationPolicy.' |
| | | 'tests.test_authentication.MyAuthenticationPolicy.' |
| | | 'effective_principals: groupfinder callback returned None as ' |
| | | 'groups') |
| | | self.assertEqual( |
| | | self.messages[1], |
| | | "pyramid.tests.test_authentication.MyAuthenticationPolicy." |
| | | "tests.test_authentication.MyAuthenticationPolicy." |
| | | "effective_principals: returning effective principals: " |
| | | "['system.Everyone']") |
| | | |
| | |
| | | self.assertEqual(len(self.messages), 2) |
| | | self.assertEqual( |
| | | self.messages[0], |
| | | 'pyramid.tests.test_authentication.MyAuthenticationPolicy.' |
| | | 'tests.test_authentication.MyAuthenticationPolicy.' |
| | | 'effective_principals: groupfinder callback returned [] as groups') |
| | | self.assertEqual( |
| | | self.messages[1], |
| | | "pyramid.tests.test_authentication.MyAuthenticationPolicy." |
| | | "tests.test_authentication.MyAuthenticationPolicy." |
| | | "effective_principals: returning effective principals: " |
| | | "['system.Everyone', 'system.Authenticated', 'fred']") |
| | | |
| | |
| | | self.assertEqual(len(self.messages), 1) |
| | | self.assertEqual( |
| | | self.messages[0], |
| | | "pyramid.tests.test_authentication.MyAuthenticationPolicy." |
| | | "tests.test_authentication.MyAuthenticationPolicy." |
| | | "effective_principals: unauthenticated_userid returned disallowed " |
| | | "'system.Authenticated'; returning ['system.Everyone'] as if it " |
| | | "was None") |
| | |
| | | self.assertEqual(len(self.messages), 1) |
| | | self.assertEqual( |
| | | self.messages[0], |
| | | "pyramid.tests.test_authentication.MyAuthenticationPolicy." |
| | | "tests.test_authentication.MyAuthenticationPolicy." |
| | | "effective_principals: unauthenticated_userid returned disallowed " |
| | | "'system.Everyone'; returning ['system.Everyone'] as if it " |
| | | "was None") |
File was renamed from pyramid/tests/test_config/test_adapters.py |
| | |
| | | import unittest |
| | | |
| | | from pyramid.compat import PY2 |
| | | from pyramid.tests.test_config import IDummy |
| | | from . import IDummy |
| | | |
| | | class AdaptersConfiguratorMixinTests(unittest.TestCase): |
| | | def _makeOne(self, *arg, **kw): |
| | |
| | | self.assertEqual(len(L), 1) |
| | | |
| | | def test_add_subscriber_dottednames(self): |
| | | import pyramid.tests.test_config |
| | | import tests.test_config |
| | | from pyramid.interfaces import INewRequest |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_subscriber('pyramid.tests.test_config', |
| | | config.add_subscriber('tests.test_config', |
| | | 'pyramid.interfaces.INewRequest') |
| | | handlers = list(config.registry.registeredHandlers()) |
| | | self.assertEqual(len(handlers), 1) |
| | | handler = handlers[0] |
| | | self.assertEqual(handler.handler, pyramid.tests.test_config) |
| | | self.assertEqual(handler.handler, tests.test_config) |
| | | self.assertEqual(handler.required, (INewRequest,)) |
| | | |
| | | def test_add_object_event_subscriber(self): |
| | |
| | | from pyramid.interfaces import ITraverser |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_traverser( |
| | | 'pyramid.tests.test_config.test_adapters.DummyTraverser', |
| | | 'pyramid.tests.test_config.test_adapters.DummyIface') |
| | | 'tests.test_config.test_adapters.DummyTraverser', |
| | | 'tests.test_config.test_adapters.DummyIface') |
| | | iface = DummyIface() |
| | | traverser = config.registry.getAdapter(iface, ITraverser) |
| | | self.assertEqual(traverser.__class__, DummyTraverser) |
| | |
| | | from pyramid.interfaces import IResourceURL |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_resource_url_adapter( |
| | | 'pyramid.tests.test_config.test_adapters.DummyResourceURL', |
| | | 'pyramid.tests.test_config.test_adapters.DummyIface', |
| | | 'tests.test_config.test_adapters.DummyResourceURL', |
| | | 'tests.test_config.test_adapters.DummyIface', |
| | | ) |
| | | iface = DummyIface() |
| | | adapter = config.registry.getMultiAdapter((iface, iface), |
| | |
| | | self.assertEqual( |
| | | intr.title, |
| | | "resource url adapter for resource iface " |
| | | "<class 'pyramid.tests.test_config.test_adapters.DummyIface'>" |
| | | "<class 'tests.test_config.test_adapters.DummyIface'>" |
| | | ) |
| | | self.assertEqual(intr['adapter'], DummyResourceURL) |
| | | self.assertEqual(intr['resource_iface'], DummyIface) |
File was renamed from pyramid/tests/test_config/test_assets.py |
| | |
| | | config = self._makeOne() |
| | | self.assertRaises(ConfigurationError, config.override_asset, |
| | | 'a:foo/', |
| | | 'pyramid.tests.test_config.pkgs.asset:foo.pt') |
| | | 'tests.test_config.pkgs.asset:foo.pt') |
| | | |
| | | def test_override_asset_file_with_directory(self): |
| | | from pyramid.exceptions import ConfigurationError |
| | | config = self._makeOne() |
| | | self.assertRaises(ConfigurationError, config.override_asset, |
| | | 'a:foo.pt', |
| | | 'pyramid.tests.test_config.pkgs.asset:templates/') |
| | | 'tests.test_config.pkgs.asset:templates/') |
| | | |
| | | def test_override_asset_file_with_package(self): |
| | | from pyramid.exceptions import ConfigurationError |
| | | config = self._makeOne() |
| | | self.assertRaises(ConfigurationError, config.override_asset, |
| | | 'a:foo.pt', |
| | | 'pyramid.tests.test_config.pkgs.asset') |
| | | 'tests.test_config.pkgs.asset') |
| | | |
| | | def test_override_asset_file_with_file(self): |
| | | from pyramid.config.assets import PackageAssetSource |
| | | config = self._makeOne(autocommit=True) |
| | | override = DummyUnderOverride() |
| | | config.override_asset( |
| | | 'pyramid.tests.test_config.pkgs.asset:templates/foo.pt', |
| | | 'pyramid.tests.test_config.pkgs.asset.subpackage:templates/bar.pt', |
| | | 'tests.test_config.pkgs.asset:templates/foo.pt', |
| | | 'tests.test_config.pkgs.asset.subpackage:templates/bar.pt', |
| | | _override=override) |
| | | from pyramid.tests.test_config.pkgs import asset |
| | | from pyramid.tests.test_config.pkgs.asset import subpackage |
| | | from tests.test_config.pkgs import asset |
| | | from tests.test_config.pkgs.asset import subpackage |
| | | self.assertEqual(override.package, asset) |
| | | self.assertEqual(override.path, 'templates/foo.pt') |
| | | source = override.source |
| | |
| | | config = self._makeOne(autocommit=True) |
| | | override = DummyUnderOverride() |
| | | config.override_asset( |
| | | 'pyramid.tests.test_config.pkgs.asset', |
| | | 'pyramid.tests.test_config.pkgs.asset.subpackage', |
| | | 'tests.test_config.pkgs.asset', |
| | | 'tests.test_config.pkgs.asset.subpackage', |
| | | _override=override) |
| | | from pyramid.tests.test_config.pkgs import asset |
| | | from pyramid.tests.test_config.pkgs.asset import subpackage |
| | | from tests.test_config.pkgs import asset |
| | | from tests.test_config.pkgs.asset import subpackage |
| | | self.assertEqual(override.package, asset) |
| | | self.assertEqual(override.path, '') |
| | | source = override.source |
| | |
| | | config = self._makeOne(autocommit=True) |
| | | override = DummyUnderOverride() |
| | | config.override_asset( |
| | | 'pyramid.tests.test_config.pkgs.asset:templates/', |
| | | 'pyramid.tests.test_config.pkgs.asset.subpackage:templates/', |
| | | 'tests.test_config.pkgs.asset:templates/', |
| | | 'tests.test_config.pkgs.asset.subpackage:templates/', |
| | | _override=override) |
| | | from pyramid.tests.test_config.pkgs import asset |
| | | from pyramid.tests.test_config.pkgs.asset import subpackage |
| | | from tests.test_config.pkgs import asset |
| | | from tests.test_config.pkgs.asset import subpackage |
| | | self.assertEqual(override.package, asset) |
| | | self.assertEqual(override.path, 'templates/') |
| | | source = override.source |
| | |
| | | config = self._makeOne(autocommit=True) |
| | | override = DummyUnderOverride() |
| | | config.override_asset( |
| | | 'pyramid.tests.test_config.pkgs.asset:templates/', |
| | | 'pyramid.tests.test_config.pkgs.asset.subpackage', |
| | | 'tests.test_config.pkgs.asset:templates/', |
| | | 'tests.test_config.pkgs.asset.subpackage', |
| | | _override=override) |
| | | from pyramid.tests.test_config.pkgs import asset |
| | | from pyramid.tests.test_config.pkgs.asset import subpackage |
| | | from tests.test_config.pkgs import asset |
| | | from tests.test_config.pkgs.asset import subpackage |
| | | self.assertEqual(override.package, asset) |
| | | self.assertEqual(override.path, 'templates/') |
| | | source = override.source |
| | |
| | | config = self._makeOne(autocommit=True) |
| | | override = DummyUnderOverride() |
| | | config.override_asset( |
| | | 'pyramid.tests.test_config.pkgs.asset', |
| | | 'pyramid.tests.test_config.pkgs.asset.subpackage:templates/', |
| | | 'tests.test_config.pkgs.asset', |
| | | 'tests.test_config.pkgs.asset.subpackage:templates/', |
| | | _override=override) |
| | | from pyramid.tests.test_config.pkgs import asset |
| | | from pyramid.tests.test_config.pkgs.asset import subpackage |
| | | from tests.test_config.pkgs import asset |
| | | from tests.test_config.pkgs.asset import subpackage |
| | | self.assertEqual(override.package, asset) |
| | | self.assertEqual(override.path, '') |
| | | source = override.source |
| | |
| | | abspath = os.path.join(here, 'pkgs', 'asset', 'subpackage', |
| | | 'templates', 'bar.pt') |
| | | config.override_asset( |
| | | 'pyramid.tests.test_config.pkgs.asset:templates/foo.pt', |
| | | 'tests.test_config.pkgs.asset:templates/foo.pt', |
| | | abspath, |
| | | _override=override) |
| | | from pyramid.tests.test_config.pkgs import asset |
| | | from tests.test_config.pkgs import asset |
| | | self.assertEqual(override.package, asset) |
| | | self.assertEqual(override.path, 'templates/foo.pt') |
| | | source = override.source |
| | |
| | | override = DummyUnderOverride() |
| | | abspath = os.path.join(here, 'pkgs', 'asset', 'subpackage', 'templates') |
| | | config.override_asset( |
| | | 'pyramid.tests.test_config.pkgs.asset:templates/', |
| | | 'tests.test_config.pkgs.asset:templates/', |
| | | abspath, |
| | | _override=override) |
| | | from pyramid.tests.test_config.pkgs import asset |
| | | from tests.test_config.pkgs import asset |
| | | self.assertEqual(override.package, asset) |
| | | self.assertEqual(override.path, 'templates/') |
| | | source = override.source |
| | |
| | | override = DummyUnderOverride() |
| | | abspath = os.path.join(here, 'pkgs', 'asset', 'subpackage', 'templates') |
| | | config.override_asset( |
| | | 'pyramid.tests.test_config.pkgs.asset', |
| | | 'tests.test_config.pkgs.asset', |
| | | abspath, |
| | | _override=override) |
| | | from pyramid.tests.test_config.pkgs import asset |
| | | from tests.test_config.pkgs import asset |
| | | self.assertEqual(override.package, asset) |
| | | self.assertEqual(override.path, '') |
| | | source = override.source |
| | |
| | | klass = self._getTargetClass() |
| | | return klass(module) |
| | | |
| | | def _registerOverrides(self, overrides, name='pyramid.tests.test_config'): |
| | | def _registerOverrides(self, overrides, name='tests.test_config'): |
| | | from pyramid.interfaces import IPackageOverrides |
| | | from pyramid.threadlocal import get_current_registry |
| | | reg = get_current_registry() |
| | |
| | | |
| | | def test_get_resource_filename_no_overrides(self): |
| | | resource_name = 'test_assets.py' |
| | | import pyramid.tests.test_config |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | import tests.test_config |
| | | provider = self._makeOne(tests.test_config) |
| | | expected = os.path.join(here, resource_name) |
| | | result = provider.get_resource_filename(None, resource_name) |
| | | self.assertEqual(result, expected) |
| | | |
| | | def test_get_resource_stream_no_overrides(self): |
| | | resource_name = 'test_assets.py' |
| | | import pyramid.tests.test_config |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | import tests.test_config |
| | | provider = self._makeOne(tests.test_config) |
| | | with provider.get_resource_stream(None, resource_name) as result: |
| | | _assertBody(result.read(), os.path.join(here, resource_name)) |
| | | |
| | | def test_get_resource_string_no_overrides(self): |
| | | resource_name = 'test_assets.py' |
| | | import pyramid.tests.test_config |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | import tests.test_config |
| | | provider = self._makeOne(tests.test_config) |
| | | result = provider.get_resource_string(None, resource_name) |
| | | _assertBody(result, os.path.join(here, resource_name)) |
| | | |
| | | def test_has_resource_no_overrides(self): |
| | | resource_name = 'test_assets.py' |
| | | import pyramid.tests.test_config |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | import tests.test_config |
| | | provider = self._makeOne(tests.test_config) |
| | | result = provider.has_resource(resource_name) |
| | | self.assertEqual(result, True) |
| | | |
| | | def test_resource_isdir_no_overrides(self): |
| | | file_resource_name = 'test_assets.py' |
| | | directory_resource_name = 'files' |
| | | import pyramid.tests.test_config |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | import tests.test_config |
| | | provider = self._makeOne(tests.test_config) |
| | | result = provider.resource_isdir(file_resource_name) |
| | | self.assertEqual(result, False) |
| | | result = provider.resource_isdir(directory_resource_name) |
| | |
| | | |
| | | def test_resource_listdir_no_overrides(self): |
| | | resource_name = 'files' |
| | | import pyramid.tests.test_config |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | import tests.test_config |
| | | provider = self._makeOne(tests.test_config) |
| | | result = provider.resource_listdir(resource_name) |
| | | self.assertTrue(result) |
| | | |
| | |
| | | overrides = DummyOverrides(None) |
| | | self._registerOverrides(overrides) |
| | | resource_name = 'test_assets.py' |
| | | import pyramid.tests.test_config |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | import tests.test_config |
| | | provider = self._makeOne(tests.test_config) |
| | | expected = os.path.join(here, resource_name) |
| | | result = provider.get_resource_filename(None, resource_name) |
| | | self.assertEqual(result, expected) |
| | |
| | | overrides = DummyOverrides(None) |
| | | self._registerOverrides(overrides) |
| | | resource_name = 'test_assets.py' |
| | | import pyramid.tests.test_config |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | import tests.test_config |
| | | provider = self._makeOne(tests.test_config) |
| | | with provider.get_resource_stream(None, resource_name) as result: |
| | | _assertBody(result.read(), os.path.join(here, resource_name)) |
| | | |
| | |
| | | overrides = DummyOverrides(None) |
| | | self._registerOverrides(overrides) |
| | | resource_name = 'test_assets.py' |
| | | import pyramid.tests.test_config |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | import tests.test_config |
| | | provider = self._makeOne(tests.test_config) |
| | | result = provider.get_resource_string(None, resource_name) |
| | | _assertBody(result, os.path.join(here, resource_name)) |
| | | |
| | |
| | | overrides = DummyOverrides(None) |
| | | self._registerOverrides(overrides) |
| | | resource_name = 'test_assets.py' |
| | | import pyramid.tests.test_config |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | import tests.test_config |
| | | provider = self._makeOne(tests.test_config) |
| | | result = provider.has_resource(resource_name) |
| | | self.assertEqual(result, True) |
| | | |
| | |
| | | overrides = DummyOverrides(None) |
| | | self._registerOverrides(overrides) |
| | | resource_name = 'files' |
| | | import pyramid.tests.test_config |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | import tests.test_config |
| | | provider = self._makeOne(tests.test_config) |
| | | result = provider.resource_isdir(resource_name) |
| | | self.assertEqual(result, True) |
| | | |
| | |
| | | overrides = DummyOverrides(None) |
| | | self._registerOverrides(overrides) |
| | | resource_name = 'files' |
| | | import pyramid.tests.test_config |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | import tests.test_config |
| | | provider = self._makeOne(tests.test_config) |
| | | result = provider.resource_listdir(resource_name) |
| | | self.assertTrue(result) |
| | | |
| | | def test_get_resource_filename_override_returns_value(self): |
| | | overrides = DummyOverrides('value') |
| | | import pyramid.tests.test_config |
| | | import tests.test_config |
| | | self._registerOverrides(overrides) |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | provider = self._makeOne(tests.test_config) |
| | | result = provider.get_resource_filename(None, 'test_assets.py') |
| | | self.assertEqual(result, 'value') |
| | | |
| | | def test_get_resource_stream_override_returns_value(self): |
| | | from io import BytesIO |
| | | overrides = DummyOverrides(BytesIO(b'value')) |
| | | import pyramid.tests.test_config |
| | | import tests.test_config |
| | | self._registerOverrides(overrides) |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | provider = self._makeOne(tests.test_config) |
| | | with provider.get_resource_stream(None, 'test_assets.py') as stream: |
| | | self.assertEqual(stream.getvalue(), b'value') |
| | | |
| | | def test_get_resource_string_override_returns_value(self): |
| | | overrides = DummyOverrides('value') |
| | | import pyramid.tests.test_config |
| | | import tests.test_config |
| | | self._registerOverrides(overrides) |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | provider = self._makeOne(tests.test_config) |
| | | result = provider.get_resource_string(None, 'test_assets.py') |
| | | self.assertEqual(result, 'value') |
| | | |
| | | def test_has_resource_override_returns_True(self): |
| | | overrides = DummyOverrides(True) |
| | | import pyramid.tests.test_config |
| | | import tests.test_config |
| | | self._registerOverrides(overrides) |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | provider = self._makeOne(tests.test_config) |
| | | result = provider.has_resource('test_assets.py') |
| | | self.assertEqual(result, True) |
| | | |
| | | def test_resource_isdir_override_returns_False(self): |
| | | overrides = DummyOverrides(False) |
| | | import pyramid.tests.test_config |
| | | import tests.test_config |
| | | self._registerOverrides(overrides) |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | provider = self._makeOne(tests.test_config) |
| | | result = provider.resource_isdir('files') |
| | | self.assertEqual(result, False) |
| | | |
| | | def test_resource_listdir_override_returns_values(self): |
| | | overrides = DummyOverrides(['a']) |
| | | import pyramid.tests.test_config |
| | | import tests.test_config |
| | | self._registerOverrides(overrides) |
| | | provider = self._makeOne(pyramid.tests.test_config) |
| | | provider = self._makeOne(tests.test_config) |
| | | result = provider.resource_listdir('files') |
| | | self.assertEqual(result, ['a']) |
| | | |
| | |
| | | from pyramid.config.assets import PackageAssetSource |
| | | return PackageAssetSource |
| | | |
| | | def _makeOne(self, prefix, package='pyramid.tests.test_config'): |
| | | def _makeOne(self, prefix, package='tests.test_config'): |
| | | klass = self._getTargetClass() |
| | | return klass(package, prefix) |
| | | |
File was renamed from pyramid/tests/test_config/test_factories.py |
| | |
| | | import unittest |
| | | |
| | | from pyramid.tests.test_config import dummyfactory |
| | | from . import dummyfactory |
| | | |
| | | class TestFactoriesMixin(unittest.TestCase): |
| | | def _makeOne(self, *arg, **kw): |
| | |
| | | from pyramid.interfaces import IRequestFactory |
| | | config = self._makeOne(autocommit=True) |
| | | config.set_request_factory( |
| | | 'pyramid.tests.test_config.dummyfactory') |
| | | 'tests.test_config.dummyfactory') |
| | | self.assertEqual(config.registry.getUtility(IRequestFactory), |
| | | dummyfactory) |
| | | |
| | |
| | | from pyramid.interfaces import IResponseFactory |
| | | config = self._makeOne(autocommit=True) |
| | | config.set_response_factory( |
| | | 'pyramid.tests.test_config.dummyfactory') |
| | | 'tests.test_config.dummyfactory') |
| | | self.assertEqual(config.registry.getUtility(IResponseFactory), |
| | | dummyfactory) |
| | | |
| | |
| | | def test_set_root_factory_dottedname(self): |
| | | from pyramid.interfaces import IRootFactory |
| | | config = self._makeOne() |
| | | config.set_root_factory('pyramid.tests.test_config.dummyfactory') |
| | | config.set_root_factory('tests.test_config.dummyfactory') |
| | | self.assertEqual(config.registry.queryUtility(IRootFactory), None) |
| | | config.commit() |
| | | self.assertEqual(config.registry.getUtility(IRootFactory), dummyfactory) |
| | |
| | | def test_set_session_factory_dottedname(self): |
| | | from pyramid.interfaces import ISessionFactory |
| | | config = self._makeOne() |
| | | config.set_session_factory('pyramid.tests.test_config.dummyfactory') |
| | | config.set_session_factory('tests.test_config.dummyfactory') |
| | | self.assertEqual(config.registry.queryUtility(ISessionFactory), None) |
| | | config.commit() |
| | | self.assertEqual(config.registry.getUtility(ISessionFactory), |
File was renamed from pyramid/tests/test_config/test_i18n.py |
| | |
| | | import os |
| | | import unittest |
| | | |
| | | from pyramid.tests.test_config import dummyfactory |
| | | from . import dummyfactory |
| | | |
| | | here = os.path.dirname(__file__) |
| | | locale = os.path.abspath( |
| | |
| | | from pyramid.interfaces import ILocaleNegotiator |
| | | config = self._makeOne(autocommit=True) |
| | | config.set_locale_negotiator( |
| | | 'pyramid.tests.test_config.dummyfactory') |
| | | 'tests.test_config.dummyfactory') |
| | | self.assertEqual(config.registry.getUtility(ILocaleNegotiator), |
| | | dummyfactory) |
| | | |
| | |
| | | def test_add_translation_dirs_asset_spec(self): |
| | | from pyramid.interfaces import ITranslationDirectories |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_translation_dirs('pyramid.tests.pkgs.localeapp:locale') |
| | | config.add_translation_dirs('tests.pkgs.localeapp:locale') |
| | | self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
| | | [locale]) |
| | | |
| | |
| | | config = self._makeOne(autocommit=True) |
| | | directories = ['abc'] |
| | | config.registry.registerUtility(directories, ITranslationDirectories) |
| | | config.add_translation_dirs('pyramid.tests.pkgs.localeapp:locale') |
| | | config.add_translation_dirs('tests.pkgs.localeapp:locale') |
| | | result = config.registry.getUtility(ITranslationDirectories) |
| | | self.assertEqual(result, [locale, 'abc']) |
| | | |
| | | def test_add_translation_dirs_multiple_specs(self): |
| | | from pyramid.interfaces import ITranslationDirectories |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_translation_dirs('pyramid.tests.pkgs.localeapp:locale', |
| | | 'pyramid.tests.pkgs.localeapp:locale2') |
| | | config.add_translation_dirs('tests.pkgs.localeapp:locale', |
| | | 'tests.pkgs.localeapp:locale2') |
| | | self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
| | | [locale, locale2]) |
| | | |
| | | def test_add_translation_dirs_multiple_specs_multiple_calls(self): |
| | | from pyramid.interfaces import ITranslationDirectories |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_translation_dirs('pyramid.tests.pkgs.localeapp:locale', |
| | | 'pyramid.tests.pkgs.localeapp:locale2') |
| | | config.add_translation_dirs('pyramid.tests.pkgs.localeapp:locale3') |
| | | config.add_translation_dirs('tests.pkgs.localeapp:locale', |
| | | 'tests.pkgs.localeapp:locale2') |
| | | config.add_translation_dirs('tests.pkgs.localeapp:locale3') |
| | | self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
| | | [locale3, locale, locale2]) |
| | | |
| | | def test_add_translation_dirs_override_multiple_specs_multiple_calls(self): |
| | | from pyramid.interfaces import ITranslationDirectories |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_translation_dirs('pyramid.tests.pkgs.localeapp:locale', |
| | | 'pyramid.tests.pkgs.localeapp:locale2') |
| | | config.add_translation_dirs('pyramid.tests.pkgs.localeapp:locale3', |
| | | config.add_translation_dirs('tests.pkgs.localeapp:locale', |
| | | 'tests.pkgs.localeapp:locale2') |
| | | config.add_translation_dirs('tests.pkgs.localeapp:locale3', |
| | | override=True) |
| | | self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
| | | [locale, locale2, locale3]) |
| | |
| | | from pyramid.interfaces import ITranslationDirectories |
| | | config = self._makeOne(autocommit=True) |
| | | with self.assertRaises(TypeError): |
| | | config.add_translation_dirs('pyramid.tests.pkgs.localeapp:locale', |
| | | config.add_translation_dirs('tests.pkgs.localeapp:locale', |
| | | foo=1) |
| | | |
| | | def test_add_translation_dirs_abspath(self): |
| | |
| | | def test_add_translation_dirs_uses_override_out_of_order(self): |
| | | from pyramid.interfaces import ITranslationDirectories |
| | | config = self._makeOne() |
| | | config.add_translation_dirs('pyramid.tests.pkgs.localeapp:locale') |
| | | config.override_asset('pyramid.tests.pkgs.localeapp:locale/', |
| | | 'pyramid.tests.pkgs.localeapp:locale2/') |
| | | config.add_translation_dirs('tests.pkgs.localeapp:locale') |
| | | config.override_asset('tests.pkgs.localeapp:locale/', |
| | | 'tests.pkgs.localeapp:locale2/') |
| | | config.commit() |
| | | self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
| | | [locale2]) |
| | |
| | | def test_add_translation_dirs_doesnt_use_override_w_autocommit(self): |
| | | from pyramid.interfaces import ITranslationDirectories |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_translation_dirs('pyramid.tests.pkgs.localeapp:locale') |
| | | config.override_asset('pyramid.tests.pkgs.localeapp:locale/', |
| | | 'pyramid.tests.pkgs.localeapp:locale2/') |
| | | config.add_translation_dirs('tests.pkgs.localeapp:locale') |
| | | config.override_asset('tests.pkgs.localeapp:locale/', |
| | | 'tests.pkgs.localeapp:locale2/') |
| | | self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
| | | [locale]) |
| | | |
| | | def test_add_translation_dirs_uses_override_w_autocommit(self): |
| | | from pyramid.interfaces import ITranslationDirectories |
| | | config = self._makeOne(autocommit=True) |
| | | config.override_asset('pyramid.tests.pkgs.localeapp:locale/', |
| | | 'pyramid.tests.pkgs.localeapp:locale2/') |
| | | config.add_translation_dirs('pyramid.tests.pkgs.localeapp:locale') |
| | | config.override_asset('tests.pkgs.localeapp:locale/', |
| | | 'tests.pkgs.localeapp:locale2/') |
| | | config.add_translation_dirs('tests.pkgs.localeapp:locale') |
| | | self.assertEqual(config.registry.getUtility(ITranslationDirectories), |
| | | [locale2]) |
File was renamed from pyramid/tests/test_config/test_init.py |
| | |
| | | from pyramid.compat import im_func |
| | | from pyramid.testing import skip_on |
| | | |
| | | from pyramid.tests.test_config import dummy_tween_factory |
| | | from pyramid.tests.test_config import dummy_include |
| | | from pyramid.tests.test_config import dummy_extend |
| | | from pyramid.tests.test_config import dummy_extend2 |
| | | from pyramid.tests.test_config import IDummy |
| | | from pyramid.tests.test_config import DummyContext |
| | | from . import dummy_tween_factory |
| | | from . import dummy_include |
| | | from . import dummy_extend |
| | | from . import dummy_extend2 |
| | | from . import IDummy |
| | | from . import DummyContext |
| | | |
| | | from pyramid.exceptions import ConfigurationExecutionError |
| | | from pyramid.exceptions import ConfigurationConflictError |
| | |
| | | from pyramid.config import Configurator |
| | | from pyramid.interfaces import IRendererFactory |
| | | config = Configurator() |
| | | this_pkg = sys.modules['pyramid.tests.test_config'] |
| | | this_pkg = sys.modules['tests.test_config'] |
| | | self.assertTrue(config.registry.getUtility(ISettings)) |
| | | self.assertEqual(config.package, this_pkg) |
| | | config.commit() |
| | |
| | | from pyramid.interfaces import IDebugLogger |
| | | config = self._makeOne() |
| | | logger = config.registry.getUtility(IDebugLogger) |
| | | self.assertEqual(logger.name, 'pyramid.tests.test_config') |
| | | self.assertEqual(logger.name, 'tests.test_config') |
| | | |
| | | def test_ctor_noreg_debug_logger_non_None(self): |
| | | from pyramid.interfaces import IDebugLogger |
| | |
| | | self.assertEqual(result, response) |
| | | |
| | | def test_with_package_module(self): |
| | | from pyramid.tests.test_config import test_init |
| | | import pyramid.tests |
| | | from . import test_init |
| | | config = self._makeOne() |
| | | newconfig = config.with_package(test_init) |
| | | self.assertEqual(newconfig.package, pyramid.tests.test_config) |
| | | import tests.test_config |
| | | self.assertEqual(newconfig.package, tests.test_config) |
| | | |
| | | def test_with_package_package(self): |
| | | import pyramid.tests.test_config |
| | | from tests import test_config |
| | | config = self._makeOne() |
| | | newconfig = config.with_package(pyramid.tests.test_config) |
| | | self.assertEqual(newconfig.package, pyramid.tests.test_config) |
| | | newconfig = config.with_package(test_config) |
| | | self.assertEqual(newconfig.package, test_config) |
| | | |
| | | def test_with_package(self): |
| | | import pyramid.tests |
| | | import tests |
| | | config = self._makeOne() |
| | | config.basepath = 'basepath' |
| | | config.info = 'info' |
| | | config.includepath = ('spec',) |
| | | config.autocommit = True |
| | | config.route_prefix = 'prefix' |
| | | newconfig = config.with_package(pyramid.tests) |
| | | self.assertEqual(newconfig.package, pyramid.tests) |
| | | newconfig = config.with_package(tests) |
| | | self.assertEqual(newconfig.package, tests) |
| | | self.assertEqual(newconfig.registry, config.registry) |
| | | self.assertEqual(newconfig.autocommit, True) |
| | | self.assertEqual(newconfig.route_prefix, 'prefix') |
| | |
| | | self.assertEqual(newconfig.includepath, ('spec',)) |
| | | |
| | | def test_maybe_dotted_string_success(self): |
| | | import pyramid.tests.test_config |
| | | import tests.test_config |
| | | config = self._makeOne() |
| | | result = config.maybe_dotted('pyramid.tests.test_config') |
| | | self.assertEqual(result, pyramid.tests.test_config) |
| | | result = config.maybe_dotted('tests.test_config') |
| | | self.assertEqual(result, tests.test_config) |
| | | |
| | | def test_maybe_dotted_string_fail(self): |
| | | config = self._makeOne() |
| | | self.assertRaises(ImportError, config.maybe_dotted, 'cant.be.found') |
| | | |
| | | def test_maybe_dotted_notstring_success(self): |
| | | import pyramid.tests.test_config |
| | | import tests.test_config |
| | | config = self._makeOne() |
| | | result = config.maybe_dotted(pyramid.tests.test_config) |
| | | self.assertEqual(result, pyramid.tests.test_config) |
| | | result = config.maybe_dotted(tests.test_config) |
| | | self.assertEqual(result, tests.test_config) |
| | | |
| | | def test_absolute_asset_spec_already_absolute(self): |
| | | import pyramid.tests.test_config |
| | | config = self._makeOne(package=pyramid.tests.test_config) |
| | | import tests.test_config |
| | | config = self._makeOne(package=tests.test_config) |
| | | result = config.absolute_asset_spec('already:absolute') |
| | | self.assertEqual(result, 'already:absolute') |
| | | |
| | | def test_absolute_asset_spec_notastring(self): |
| | | import pyramid.tests.test_config |
| | | config = self._makeOne(package=pyramid.tests.test_config) |
| | | import tests.test_config |
| | | config = self._makeOne(package=tests.test_config) |
| | | result = config.absolute_asset_spec(None) |
| | | self.assertEqual(result, None) |
| | | |
| | | def test_absolute_asset_spec_relative(self): |
| | | import pyramid.tests.test_config |
| | | config = self._makeOne(package=pyramid.tests.test_config) |
| | | import tests.test_config |
| | | config = self._makeOne(package=tests.test_config) |
| | | result = config.absolute_asset_spec('files') |
| | | self.assertEqual(result, 'pyramid.tests.test_config:files') |
| | | self.assertEqual(result, 'tests.test_config:files') |
| | | |
| | | def test__fix_registry_has_listeners(self): |
| | | reg = DummyRegistry() |
| | |
| | | config = self._makeOne(reg) |
| | | config.setup_registry() |
| | | logger = reg.getUtility(IDebugLogger) |
| | | self.assertEqual(logger.name, 'pyramid.tests.test_config') |
| | | self.assertEqual(logger.name, 'tests.test_config') |
| | | |
| | | def test_setup_registry_debug_logger_non_None(self): |
| | | from pyramid.registry import Registry |
| | |
| | | from pyramid.interfaces import IAuthenticationPolicy |
| | | reg = Registry() |
| | | config = self._makeOne(reg) |
| | | config.setup_registry(authentication_policy='pyramid.tests.test_config') |
| | | config.setup_registry(authentication_policy='tests.test_config') |
| | | config.commit() |
| | | result = reg.getUtility(IAuthenticationPolicy) |
| | | import pyramid.tests.test_config |
| | | self.assertEqual(result, pyramid.tests.test_config) |
| | | import tests.test_config |
| | | self.assertEqual(result, tests.test_config) |
| | | |
| | | def test_setup_registry_authorization_policy_dottedname(self): |
| | | from pyramid.registry import Registry |
| | |
| | | config = self._makeOne(reg) |
| | | dummy = object() |
| | | config.setup_registry(authentication_policy=dummy, |
| | | authorization_policy='pyramid.tests.test_config') |
| | | authorization_policy='tests.test_config') |
| | | config.commit() |
| | | result = reg.getUtility(IAuthorizationPolicy) |
| | | import pyramid.tests.test_config |
| | | self.assertEqual(result, pyramid.tests.test_config) |
| | | import tests.test_config |
| | | self.assertEqual(result, tests.test_config) |
| | | |
| | | def test_setup_registry_authorization_policy_only(self): |
| | | from pyramid.registry import Registry |
| | |
| | | from pyramid.interfaces import IRootFactory |
| | | reg = Registry() |
| | | config = self._makeOne(reg) |
| | | import pyramid.tests.test_config |
| | | config.setup_registry(root_factory='pyramid.tests.test_config') |
| | | import tests.test_config |
| | | config.setup_registry(root_factory='tests.test_config') |
| | | self.assertEqual(reg.queryUtility(IRootFactory), None) |
| | | config.commit() |
| | | self.assertEqual(reg.getUtility(IRootFactory), |
| | | pyramid.tests.test_config) |
| | | self.assertEqual(reg.getUtility(IRootFactory), tests.test_config) |
| | | |
| | | def test_setup_registry_locale_negotiator_dottedname(self): |
| | | from pyramid.registry import Registry |
| | | from pyramid.interfaces import ILocaleNegotiator |
| | | reg = Registry() |
| | | config = self._makeOne(reg) |
| | | import pyramid.tests.test_config |
| | | config.setup_registry(locale_negotiator='pyramid.tests.test_config') |
| | | import tests.test_config |
| | | config.setup_registry(locale_negotiator='tests.test_config') |
| | | self.assertEqual(reg.queryUtility(ILocaleNegotiator), None) |
| | | config.commit() |
| | | utility = reg.getUtility(ILocaleNegotiator) |
| | | self.assertEqual(utility, pyramid.tests.test_config) |
| | | self.assertEqual(utility, tests.test_config) |
| | | |
| | | def test_setup_registry_locale_negotiator(self): |
| | | from pyramid.registry import Registry |
| | |
| | | from pyramid.interfaces import IRequestFactory |
| | | reg = Registry() |
| | | config = self._makeOne(reg) |
| | | import pyramid.tests.test_config |
| | | config.setup_registry(request_factory='pyramid.tests.test_config') |
| | | import tests.test_config |
| | | config.setup_registry(request_factory='tests.test_config') |
| | | self.assertEqual(reg.queryUtility(IRequestFactory), None) |
| | | config.commit() |
| | | utility = reg.getUtility(IRequestFactory) |
| | | self.assertEqual(utility, pyramid.tests.test_config) |
| | | self.assertEqual(utility, tests.test_config) |
| | | |
| | | def test_setup_registry_alternate_renderers(self): |
| | | from pyramid.registry import Registry |
| | |
| | | config = self._makeOne(reg) |
| | | settings = { |
| | | 'pyramid.includes': |
| | | """pyramid.tests.test_config.dummy_include |
| | | pyramid.tests.test_config.dummy_include2""", |
| | | """tests.test_config.dummy_include |
| | | tests.test_config.dummy_include2""", |
| | | } |
| | | config.setup_registry(settings=settings) |
| | | self.assertTrue(reg.included) |
| | |
| | | config = self._makeOne(reg) |
| | | settings = { |
| | | 'pyramid.includes': |
| | | """pyramid.tests.test_config.dummy_include pyramid.tests.test_config.dummy_include2""", |
| | | """tests.test_config.dummy_include tests.test_config.dummy_include2""", |
| | | } |
| | | config.setup_registry(settings=settings) |
| | | self.assertTrue(reg.included) |
| | |
| | | config = self._makeOne(reg) |
| | | settings = { |
| | | 'pyramid.tweens': |
| | | 'pyramid.tests.test_config.dummy_tween_factory' |
| | | 'tests.test_config.dummy_tween_factory' |
| | | } |
| | | config.setup_registry(settings=settings) |
| | | config.commit() |
| | | tweens = config.registry.getUtility(ITweens) |
| | | self.assertEqual( |
| | | tweens.explicit, |
| | | [('pyramid.tests.test_config.dummy_tween_factory', |
| | | [('tests.test_config.dummy_tween_factory', |
| | | dummy_tween_factory)]) |
| | | |
| | | def test_introspector_decorator(self): |
| | |
| | | pyramid.config.global_registries.empty() |
| | | |
| | | def test_include_with_dotted_name(self): |
| | | from pyramid.tests import test_config |
| | | from tests import test_config |
| | | config = self._makeOne() |
| | | config.include('pyramid.tests.test_config.dummy_include') |
| | | config.include('tests.test_config.dummy_include') |
| | | after = config.action_state |
| | | actions = after.actions |
| | | self.assertEqual(len(actions), 1) |
| | |
| | | self.assertEqual(action['args'], test_config) |
| | | |
| | | def test_include_with_python_callable(self): |
| | | from pyramid.tests import test_config |
| | | from tests import test_config |
| | | config = self._makeOne() |
| | | config.include(dummy_include) |
| | | after = config.action_state |
| | |
| | | self.assertEqual(action['args'], test_config) |
| | | |
| | | def test_include_with_module_defaults_to_includeme(self): |
| | | from pyramid.tests import test_config |
| | | from tests import test_config |
| | | config = self._makeOne() |
| | | config.include('pyramid.tests.test_config') |
| | | config.include('tests.test_config') |
| | | after = config.action_state |
| | | actions = after.actions |
| | | self.assertEqual(len(actions), 1) |
| | |
| | | def test_include_with_module_defaults_to_includeme_missing(self): |
| | | from pyramid.exceptions import ConfigurationError |
| | | config = self._makeOne() |
| | | self.assertRaises(ConfigurationError, config.include, 'pyramid.tests') |
| | | self.assertRaises(ConfigurationError, config.include, 'tests') |
| | | |
| | | def test_include_with_route_prefix(self): |
| | | root_config = self._makeOne(autocommit=True) |
| | |
| | | return None |
| | | config.inspect = DummyInspect() |
| | | try: |
| | | config.include('pyramid.tests.test_config.dummy_include') |
| | | config.include('tests.test_config.dummy_include') |
| | | except ConfigurationError as e: |
| | | self.assertEqual( |
| | | e.args[0], |
| | | "No source file for module 'pyramid.tests.test_config' (.py " |
| | | "No source file for module 'tests.test_config' (.py " |
| | | "file must exist, refusing to use orphan .pyc or .pyo file).") |
| | | else: # pragma: no cover |
| | | raise AssertionError |
| | | |
| | | def test_include_constant_root_package(self): |
| | | from pyramid import tests |
| | | from pyramid.tests import test_config |
| | | import tests |
| | | from tests import test_config |
| | | config = self._makeOne(root_package=tests) |
| | | results = {} |
| | | def include(config): |
| | |
| | | self.assertEqual(results['package'], test_config) |
| | | |
| | | def test_include_threadlocals_active(self): |
| | | from pyramid.tests import test_config |
| | | from pyramid.threadlocal import get_current_registry |
| | | from tests import test_config |
| | | stack = [] |
| | | def include(config): |
| | | stack.append(get_current_registry()) |
| | |
| | | from zope.interface import alsoProvides |
| | | from pyramid.interfaces import IRequest |
| | | from pyramid.view import render_view_to_response |
| | | import pyramid.tests.test_config.pkgs.scannable as package |
| | | import tests.test_config.pkgs.scannable as package |
| | | config = self._makeOne(autocommit=True) |
| | | config.scan(package) |
| | | |
| | |
| | | from zope.interface import alsoProvides |
| | | from pyramid.interfaces import IRequest |
| | | from pyramid.view import render_view_to_response |
| | | import pyramid.tests.test_config.pkgs.scannable as package |
| | | import tests.test_config.pkgs.scannable as package |
| | | config = self._makeOne(autocommit=True) |
| | | config.scan(package, |
| | | ignore='pyramid.tests.test_config.pkgs.scannable.another') |
| | | ignore='tests.test_config.pkgs.scannable.another') |
| | | |
| | | ctx = DummyContext() |
| | | req = DummyRequest() |
| | |
| | | from pyramid.interfaces import IRequest |
| | | from pyramid.view import render_view_to_response |
| | | config = self._makeOne(autocommit=True) |
| | | config.scan('pyramid.tests.test_config.pkgs.scannable') |
| | | config.scan('tests.test_config.pkgs.scannable') |
| | | |
| | | ctx = DummyContext() |
| | | req = DummyRequest() |
| | |
| | | |
| | | def test_scan_integration_with_extra_kw(self): |
| | | config = self._makeOne(autocommit=True) |
| | | config.scan('pyramid.tests.test_config.pkgs.scanextrakw', a=1) |
| | | config.scan('tests.test_config.pkgs.scanextrakw', a=1) |
| | | self.assertEqual(config.a, 1) |
| | | |
| | | def test_scan_integration_with_onerror(self): |
| | |
| | | sys.path.remove(path) |
| | | |
| | | def test_scan_integration_conflict(self): |
| | | from pyramid.tests.test_config.pkgs import selfscan |
| | | from tests.test_config.pkgs import selfscan |
| | | from pyramid.config import Configurator |
| | | c = Configurator() |
| | | c.scan(selfscan) |
| | |
| | | self.config = Configurator() |
| | | |
| | | def test_extend_with_dotted_name(self): |
| | | from pyramid.tests import test_config |
| | | from tests import test_config |
| | | config = self.config |
| | | config.add_directive( |
| | | 'dummy_extend', 'pyramid.tests.test_config.dummy_extend') |
| | | 'dummy_extend', 'tests.test_config.dummy_extend') |
| | | self.assertTrue(hasattr(config, 'dummy_extend')) |
| | | config.dummy_extend('discrim') |
| | | after = config.action_state |
| | |
| | | self.assertEqual(action['args'], test_config) |
| | | |
| | | def test_add_directive_with_partial(self): |
| | | from pyramid.tests import test_config |
| | | from tests import test_config |
| | | config = self.config |
| | | config.add_directive( |
| | | 'dummy_partial', 'pyramid.tests.test_config.dummy_partial') |
| | | 'dummy_partial', 'tests.test_config.dummy_partial') |
| | | self.assertTrue(hasattr(config, 'dummy_partial')) |
| | | config.dummy_partial() |
| | | after = config.action_state |
| | |
| | | self.assertEqual(action['args'], test_config) |
| | | |
| | | def test_add_directive_with_custom_callable(self): |
| | | from pyramid.tests import test_config |
| | | from tests import test_config |
| | | config = self.config |
| | | config.add_directive( |
| | | 'dummy_callable', 'pyramid.tests.test_config.dummy_callable') |
| | | 'dummy_callable', 'tests.test_config.dummy_callable') |
| | | self.assertTrue(hasattr(config, 'dummy_callable')) |
| | | config.dummy_callable('discrim') |
| | | after = config.action_state |
| | |
| | | self.assertEqual(action['args'], test_config) |
| | | |
| | | def test_extend_with_python_callable(self): |
| | | from pyramid.tests import test_config |
| | | from tests import test_config |
| | | config = self.config |
| | | config.add_directive( |
| | | 'dummy_extend', dummy_extend) |
| | |
| | | def test_directive_persists_across_configurator_creations(self): |
| | | config = self.config |
| | | config.add_directive('dummy_extend', dummy_extend) |
| | | config2 = config.with_package('pyramid.tests') |
| | | config2 = config.with_package('tests') |
| | | config2.dummy_extend('discrim') |
| | | after = config2.action_state |
| | | actions = after.actions |
| | |
| | | config._add_predicate( |
| | | 'route', |
| | | 'testing', |
| | | 'pyramid.tests.test_config.test_init.DummyPredicate' |
| | | 'tests.test_config.test_init.DummyPredicate' |
| | | ) |
| | | |
| | | class TestActionState(unittest.TestCase): |
| | |
| | | self.assertEqual(c.actions, []) |
| | | |
| | | def test_action_simple(self): |
| | | from pyramid.tests.test_config import dummyfactory as f |
| | | from . import dummyfactory as f |
| | | c = self._makeOne() |
| | | c.actions = [] |
| | | c.action(1, f, (1,), {'x':1}) |
| | |
| | | return resolveConflicts(actions) |
| | | |
| | | def test_it_success_tuples(self): |
| | | from pyramid.tests.test_config import dummyfactory as f |
| | | from . import dummyfactory as f |
| | | result = self._callFUT([ |
| | | (None, f), |
| | | (1, f, (1,), {}, (), 'first'), |
| | |
| | | ) |
| | | |
| | | def test_it_success_dicts(self): |
| | | from pyramid.tests.test_config import dummyfactory as f |
| | | from . import dummyfactory as f |
| | | result = self._callFUT([ |
| | | (None, f), |
| | | (1, f, (1,), {}, (), 'first'), |
| | |
| | | ) |
| | | |
| | | def test_it_conflict(self): |
| | | from pyramid.tests.test_config import dummyfactory as f |
| | | from . import dummyfactory as f |
| | | result = self._callFUT([ |
| | | (None, f), |
| | | (1, f, (2,), {}, ('x',), 'eek'), # will conflict |
| | |
| | | self.assertRaises(ConfigurationConflictError, list, result) |
| | | |
| | | def test_it_with_actions_grouped_by_order(self): |
| | | from pyramid.tests.test_config import dummyfactory as f |
| | | from . import dummyfactory as f |
| | | result = self._callFUT([ |
| | | (None, f), # X |
| | | (1, f, (1,), {}, (), 'third', 10), # X |
| | |
| | | ) |
| | | |
| | | def test_override_success_across_orders(self): |
| | | from pyramid.tests.test_config import dummyfactory as f |
| | | from . import dummyfactory as f |
| | | result = self._callFUT([ |
| | | (1, f, (2,), {}, ('x',), 'eek', 0), |
| | | (1, f, (3,), {}, ('x', 'y'), 'ack', 10), |
| | |
| | | ]) |
| | | |
| | | def test_conflicts_across_orders(self): |
| | | from pyramid.tests.test_config import dummyfactory as f |
| | | from . import dummyfactory as f |
| | | result = self._callFUT([ |
| | | (1, f, (2,), {}, ('x', 'y'), 'eek', 0), |
| | | (1, f, (3,), {}, ('x'), 'ack', 10), |
File was renamed from pyramid/tests/test_config/test_rendering.py |
| | |
| | | def test_add_renderer_dottedname_factory(self): |
| | | from pyramid.interfaces import IRendererFactory |
| | | config = self._makeOne(autocommit=True) |
| | | import pyramid.tests.test_config |
| | | config.add_renderer('name', 'pyramid.tests.test_config') |
| | | import tests.test_config |
| | | config.add_renderer('name', 'tests.test_config') |
| | | self.assertEqual(config.registry.getUtility(IRendererFactory, 'name'), |
| | | pyramid.tests.test_config) |
| | | tests.test_config) |
| | | |
File was renamed from pyramid/tests/test_config/test_routes.py |
| | |
| | | import unittest |
| | | |
| | | from pyramid.tests.test_config import dummyfactory |
| | | from pyramid.tests.test_config import DummyContext |
| | | from . import dummyfactory |
| | | from . import DummyContext |
| | | from pyramid.compat import text_ |
| | | |
| | | class RoutesConfiguratorMixinTests(unittest.TestCase): |
| | |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_route( |
| | | 'name', 'path', |
| | | factory='pyramid.tests.test_config.dummyfactory') |
| | | factory='tests.test_config.dummyfactory') |
| | | route = self._assertRoute(config, 'name', 'path') |
| | | self.assertEqual(route.factory, dummyfactory) |
| | | |
File was renamed from pyramid/tests/test_config/test_testing.py |
| | |
| | | |
| | | from pyramid.compat import text_ |
| | | from pyramid.security import AuthenticationAPIMixin, AuthorizationAPIMixin |
| | | from pyramid.tests.test_config import IDummy |
| | | from . import IDummy |
| | | |
| | | class TestingConfiguratorMixinTests(unittest.TestCase): |
| | | def _makeOne(self, *arg, **kw): |
| | |
| | | def test_testing_add_subscriber_dottedname(self): |
| | | config = self._makeOne(autocommit=True) |
| | | L = config.testing_add_subscriber( |
| | | 'pyramid.tests.test_config.test_init.IDummy') |
| | | 'tests.test_config.test_init.IDummy') |
| | | event = DummyEvent() |
| | | config.registry.notify(event) |
| | | self.assertEqual(len(L), 1) |
File was renamed from pyramid/tests/test_config/test_tweens.py |
| | |
| | | import unittest |
| | | |
| | | from pyramid.tests.test_config import dummy_tween_factory |
| | | from pyramid.tests.test_config import dummy_tween_factory2 |
| | | from . import dummy_tween_factory |
| | | from . import dummy_tween_factory2 |
| | | |
| | | from pyramid.exceptions import ConfigurationConflictError |
| | | |
| | |
| | | def factory2(handler, registry): return handler |
| | | config = self._makeOne() |
| | | config.add_tween( |
| | | 'pyramid.tests.test_config.dummy_tween_factory') |
| | | 'tests.test_config.dummy_tween_factory') |
| | | config.add_tween( |
| | | 'pyramid.tests.test_config.dummy_tween_factory2') |
| | | 'tests.test_config.dummy_tween_factory2') |
| | | config.commit() |
| | | tweens = config.registry.queryUtility(ITweens) |
| | | implicit = tweens.implicit() |
| | | self.assertEqual( |
| | | implicit, |
| | | [ |
| | | ('pyramid.tests.test_config.dummy_tween_factory2', |
| | | ('tests.test_config.dummy_tween_factory2', |
| | | dummy_tween_factory2), |
| | | ('pyramid.tests.test_config.dummy_tween_factory', |
| | | ('tests.test_config.dummy_tween_factory', |
| | | dummy_tween_factory), |
| | | ('pyramid.tweens.excview_tween_factory', |
| | | excview_tween_factory), |
| | |
| | | from pyramid.tweens import MAIN |
| | | config = self._makeOne() |
| | | config.add_tween( |
| | | 'pyramid.tests.test_config.dummy_tween_factory', |
| | | 'tests.test_config.dummy_tween_factory', |
| | | over=MAIN) |
| | | config.add_tween( |
| | | 'pyramid.tests.test_config.dummy_tween_factory2', |
| | | 'tests.test_config.dummy_tween_factory2', |
| | | over=MAIN, |
| | | under='pyramid.tests.test_config.dummy_tween_factory') |
| | | under='tests.test_config.dummy_tween_factory') |
| | | config.commit() |
| | | tweens = config.registry.queryUtility(ITweens) |
| | | implicit = tweens.implicit() |
| | |
| | | implicit, |
| | | [ |
| | | ('pyramid.tweens.excview_tween_factory', excview_tween_factory), |
| | | ('pyramid.tests.test_config.dummy_tween_factory', |
| | | ('tests.test_config.dummy_tween_factory', |
| | | dummy_tween_factory), |
| | | ('pyramid.tests.test_config.dummy_tween_factory2', |
| | | ('tests.test_config.dummy_tween_factory2', |
| | | dummy_tween_factory2), |
| | | ]) |
| | | |
| | |
| | | config = self._makeOne() |
| | | self.assertRaises( |
| | | ConfigurationError, config.add_tween, |
| | | 'pyramid.tests.test_config.dummy_tween_factory', |
| | | 'tests.test_config.dummy_tween_factory', |
| | | under=False) |
| | | |
| | | def test_add_tweens_names_with_over_nonstringoriter(self): |
| | |
| | | config = self._makeOne() |
| | | self.assertRaises( |
| | | ConfigurationError, config.add_tween, |
| | | 'pyramid.tests.test_config.dummy_tween_factory', |
| | | 'tests.test_config.dummy_tween_factory', |
| | | over=False) |
| | | |
| | | def test_add_tween_dottedname(self): |
| | | from pyramid.interfaces import ITweens |
| | | from pyramid.tweens import excview_tween_factory |
| | | config = self._makeOne() |
| | | config.add_tween('pyramid.tests.test_config.dummy_tween_factory') |
| | | config.add_tween('tests.test_config.dummy_tween_factory') |
| | | config.commit() |
| | | tweens = config.registry.queryUtility(ITweens) |
| | | self.assertEqual( |
| | | tweens.implicit(), |
| | | [ |
| | | ('pyramid.tests.test_config.dummy_tween_factory', |
| | | ('tests.test_config.dummy_tween_factory', |
| | | dummy_tween_factory), |
| | | ('pyramid.tweens.excview_tween_factory', |
| | | excview_tween_factory), |
| | |
| | | |
| | | def test_add_tween_unsuitable(self): |
| | | from pyramid.exceptions import ConfigurationError |
| | | import pyramid.tests.test_config |
| | | import tests.test_config |
| | | config = self._makeOne() |
| | | self.assertRaises(ConfigurationError, config.add_tween, |
| | | pyramid.tests.test_config) |
| | | tests.test_config) |
| | | |
| | | def test_add_tween_name_ingress(self): |
| | | from pyramid.exceptions import ConfigurationError |
| | |
| | | |
| | | def test_add_tweens_conflict(self): |
| | | config = self._makeOne() |
| | | config.add_tween('pyramid.tests.test_config.dummy_tween_factory') |
| | | config.add_tween('pyramid.tests.test_config.dummy_tween_factory') |
| | | config.add_tween('tests.test_config.dummy_tween_factory') |
| | | config.add_tween('tests.test_config.dummy_tween_factory') |
| | | self.assertRaises(ConfigurationConflictError, config.commit) |
| | | |
| | | def test_add_tween_over_ingress(self): |
| | |
| | | self.assertRaises( |
| | | ConfigurationError, |
| | | config.add_tween, |
| | | 'pyramid.tests.test_config.dummy_tween_factory', |
| | | 'tests.test_config.dummy_tween_factory', |
| | | over=INGRESS) |
| | | |
| | | def test_add_tween_over_ingress_iterable(self): |
| | |
| | | self.assertRaises( |
| | | ConfigurationError, |
| | | config.add_tween, |
| | | 'pyramid.tests.test_config.dummy_tween_factory', |
| | | 'tests.test_config.dummy_tween_factory', |
| | | over=('a', INGRESS)) |
| | | |
| | | def test_add_tween_under_main(self): |
| | |
| | | self.assertRaises( |
| | | ConfigurationError, |
| | | config.add_tween, |
| | | 'pyramid.tests.test_config.dummy_tween_factory', |
| | | 'tests.test_config.dummy_tween_factory', |
| | | under=MAIN) |
| | | |
| | | def test_add_tween_under_main_iterable(self): |
| | |
| | | self.assertRaises( |
| | | ConfigurationError, |
| | | config.add_tween, |
| | | 'pyramid.tests.test_config.dummy_tween_factory', |
| | | 'tests.test_config.dummy_tween_factory', |
| | | under=('a', MAIN)) |
| | | |
| | | class TestTweens(unittest.TestCase): |
File was renamed from pyramid/tests/test_config/test_views.py |
| | |
| | | import unittest |
| | | from pyramid import testing |
| | | |
| | | from pyramid.tests.test_config import IDummy |
| | | from . import IDummy |
| | | |
| | | from pyramid.tests.test_config import dummy_view |
| | | from . import dummy_view |
| | | |
| | | from pyramid.compat import ( |
| | | im_func, |
| | |
| | | def test_add_view_view_callable_dottedname(self): |
| | | from pyramid.renderers import null_renderer |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_view(view='pyramid.tests.test_config.dummy_view', |
| | | config.add_view(view='tests.test_config.dummy_view', |
| | | renderer=null_renderer) |
| | | wrapper = self._getViewCallable(config) |
| | | self.assertEqual(wrapper(None, None), 'OK') |
| | |
| | | from pyramid.renderers import null_renderer |
| | | view = lambda *arg: 'OK' |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_view(context='pyramid.tests.test_config.IDummy', |
| | | config.add_view(context='tests.test_config.IDummy', |
| | | view=view, renderer=null_renderer) |
| | | wrapper = self._getViewCallable(config, IDummy) |
| | | self.assertEqual(wrapper, view) |
| | |
| | | from pyramid.renderers import null_renderer |
| | | view = lambda *arg: 'OK' |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_view(for_='pyramid.tests.test_config.IDummy', |
| | | config.add_view(for_='tests.test_config.IDummy', |
| | | view=view, renderer=null_renderer) |
| | | wrapper = self._getViewCallable(config, IDummy) |
| | | self.assertEqual(wrapper, view) |
| | |
| | | ) |
| | | |
| | | def test_add_view_with_template_renderer(self): |
| | | from pyramid.tests import test_config |
| | | from tests import test_config |
| | | from pyramid.interfaces import ISettings |
| | | class view(object): |
| | | def __init__(self, context, request): |
| | |
| | | return {'a':'1'} |
| | | config = self._makeOne(autocommit=True) |
| | | renderer = self._registerRenderer(config) |
| | | fixture = 'pyramid.tests.test_config:files/minimal.txt' |
| | | fixture = 'tests.test_config:files/minimal.txt' |
| | | config.introspection = False |
| | | config.add_view(view=view, renderer=fixture) |
| | | wrapper = self._getViewCallable(config) |
| | |
| | | self.assertEqual(result.body, b'moo') |
| | | |
| | | def test_add_view_with_template_renderer_no_callable(self): |
| | | from pyramid.tests import test_config |
| | | from tests import test_config |
| | | from pyramid.interfaces import ISettings |
| | | config = self._makeOne(autocommit=True) |
| | | renderer = self._registerRenderer(config) |
| | | fixture = 'pyramid.tests.test_config:files/minimal.txt' |
| | | fixture = 'tests.test_config:files/minimal.txt' |
| | | config.introspection = False |
| | | config.add_view(view=None, renderer=fixture) |
| | | wrapper = self._getViewCallable(config) |
| | |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_view( |
| | | view=view, |
| | | containment='pyramid.tests.test_config.IDummy', |
| | | containment='tests.test_config.IDummy', |
| | | renderer=null_renderer) |
| | | wrapper = self._getViewCallable(config) |
| | | context = DummyContext() |
| | |
| | | from zope.interface import directlyProvides |
| | | class view(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | def __init__(self, request): |
| | | pass |
| | |
| | | from zope.interface import directlyProvides |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_view( |
| | | view='pyramid.tests.test_config.test_views.DummyViewDefaultsClass', |
| | | view='tests.test_config.test_views.DummyViewDefaultsClass', |
| | | renderer=null_renderer) |
| | | wrapper = self._getViewCallable(config) |
| | | context = DummyContext() |
| | |
| | | from zope.interface import directlyProvides |
| | | config = self._makeOne(autocommit=True) |
| | | config.add_view( |
| | | 'pyramid.tests.test_config.test_views.DummyViewDefaultsClass', |
| | | 'tests.test_config.test_views.DummyViewDefaultsClass', |
| | | renderer=null_renderer) |
| | | wrapper = self._getViewCallable(config) |
| | | context = DummyContext() |
| | |
| | | from pyramid.renderers import null_renderer |
| | | class view(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | class view2(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IFactory' |
| | | 'containment':'tests.test_config.IFactory' |
| | | } |
| | | config = self._makeOne(autocommit=False) |
| | | config.add_view( |
| | |
| | | from pyramid.renderers import null_renderer |
| | | class view(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | class view2(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | config = self._makeOne(autocommit=False) |
| | | config.add_view( |
| | |
| | | from zope.interface import implementedBy |
| | | class view(object): |
| | | __view_defaults__ = { |
| | | 'containment': 'pyramid.tests.test_config.IDummy' |
| | | 'containment': 'tests.test_config.IDummy' |
| | | } |
| | | def __init__(self, request): |
| | | pass |
| | |
| | | from pyramid.renderers import null_renderer |
| | | config = self._makeOne() |
| | | result = config.derive_view( |
| | | 'pyramid.tests.test_config.dummy_view', |
| | | 'tests.test_config.dummy_view', |
| | | renderer=null_renderer) |
| | | self.assertFalse(result is dummy_view) |
| | | self.assertEqual(result(None, None), 'OK') |
| | |
| | | config = self._makeOne(autocommit=True) |
| | | config.registry.registerUtility(info, IStaticURLInfo) |
| | | config.add_static_view('static', |
| | | 'pyramid.tests.test_config:files') |
| | | 'tests.test_config:files') |
| | | self.assertEqual( |
| | | info.added, |
| | | [(config, 'static', 'pyramid.tests.test_config:files', {})]) |
| | | [(config, 'static', 'tests.test_config:files', {})]) |
| | | |
| | | def test_add_static_view_package_here_relative(self): |
| | | from pyramid.interfaces import IStaticURLInfo |
| | |
| | | config.add_static_view('static', 'files') |
| | | self.assertEqual( |
| | | info.added, |
| | | [(config, 'static', 'pyramid.tests.test_config:files', {})]) |
| | | [(config, 'static', 'tests.test_config:files', {})]) |
| | | |
| | | def test_add_static_view_absolute(self): |
| | | import os |
| | |
| | | from zope.interface import implementedBy |
| | | class view(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | def __init__(self, request): |
| | | pass |
| | |
| | | from zope.interface import implementedBy |
| | | class view(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | def __init__(self, request): |
| | | pass |
| | |
| | | def test_set_view_mapper_dottedname(self): |
| | | from pyramid.interfaces import IViewMapperFactory |
| | | config = self._makeOne(autocommit=True) |
| | | config.set_view_mapper('pyramid.tests.test_config') |
| | | config.set_view_mapper('tests.test_config') |
| | | result = config.registry.getUtility(IViewMapperFactory) |
| | | from pyramid.tests import test_config |
| | | from tests import test_config |
| | | self.assertEqual(result, test_config) |
| | | |
| | | def test_add_normal_and_exception_view_intr_derived_callable(self): |
| | |
| | | request = testing.DummyRequest() |
| | | config.add_static_view('static', 'path') |
| | | config.override_asset( |
| | | 'pyramid.tests.test_config:path/', |
| | | 'pyramid.tests.test_config:other_path/') |
| | | 'tests.test_config:path/', |
| | | 'tests.test_config:other_path/') |
| | | def cb(val): |
| | | def cb_(request, subpath, kw): |
| | | kw['_query'] = {'x': val} |
| | |
| | | def view(): pass |
| | | result = self._callFUT(view) |
| | | self.assertEqual(result, |
| | | 'function pyramid.tests.test_config.test_views.view') |
| | | 'function tests.test_config.test_views.view') |
| | | |
| | | class Test_viewdefaults(unittest.TestCase): |
| | | def _makeOne(self, wrapped): |
| | |
| | | |
| | | class DummyViewDefaultsClass(object): |
| | | __view_defaults__ = { |
| | | 'containment':'pyramid.tests.test_config.IDummy' |
| | | 'containment':'tests.test_config.IDummy' |
| | | } |
| | | def __init__(self, request): |
| | | pass |
File was renamed from pyramid/tests/test_csrf.py |
| | |
| | | self.config.set_default_csrf_options(require_csrf=False) |
| | | |
| | | def _callFUT(self, *args, **kwargs): |
| | | from ..csrf import check_csrf_token |
| | | from pyramid.csrf import check_csrf_token |
| | | return check_csrf_token(*args, **kwargs) |
| | | |
| | | def test_success_token(self): |
| | |
| | | self.config = testing.setUp() |
| | | |
| | | def _callFUT(self, *args, **kwargs): |
| | | from ..csrf import check_csrf_token |
| | | from pyramid.csrf import check_csrf_token |
| | | return check_csrf_token(*args, **kwargs) |
| | | |
| | | def test_success_token(self): |
| | |
| | | |
| | | class Test_check_csrf_origin(unittest.TestCase): |
| | | def _callFUT(self, *args, **kwargs): |
| | | from ..csrf import check_csrf_origin |
| | | from pyramid.csrf import check_csrf_origin |
| | | return check_csrf_origin(*args, **kwargs) |
| | | |
| | | def test_success_with_http(self): |
File was renamed from pyramid/tests/test_integration.py |
| | |
| | | from pyramid.interfaces import IView |
| | | from pyramid.interfaces import IViewClassifier |
| | | from pyramid.config import Configurator |
| | | from pyramid.tests import test_integration |
| | | from . import test_integration |
| | | config = Configurator() |
| | | config.scan(test_integration) |
| | | config.commit() |
| | |
| | | self.testapp.get('/%2F/test_integration.py', status=404) |
| | | |
| | | class TestEventOnlySubscribers(IntegrationBase, unittest.TestCase): |
| | | package = 'pyramid.tests.pkgs.eventonly' |
| | | package = 'tests.pkgs.eventonly' |
| | | |
| | | def test_sendfoo(self): |
| | | res = self.testapp.get('/sendfoo', status=200) |
| | |
| | | [b'foobar', b'foobar2', b'foobaryup', b'foobaryup2']) |
| | | |
| | | class TestStaticAppUsingAbsPath(StaticAppBase, unittest.TestCase): |
| | | package = 'pyramid.tests.pkgs.static_abspath' |
| | | package = 'tests.pkgs.static_abspath' |
| | | |
| | | class TestStaticAppUsingAssetSpec(StaticAppBase, unittest.TestCase): |
| | | package = 'pyramid.tests.pkgs.static_assetspec' |
| | | package = 'tests.pkgs.static_assetspec' |
| | | |
| | | class TestStaticAppNoSubpath(unittest.TestCase): |
| | | staticapp = static_view(os.path.join(here, 'fixtures'), use_subpath=False) |
| | |
| | | _assertBody(result.body, os.path.join(here, 'fixtures/minimal.txt')) |
| | | |
| | | class TestStaticAppWithRoutePrefix(IntegrationBase, unittest.TestCase): |
| | | package = 'pyramid.tests.pkgs.static_routeprefix' |
| | | package = 'tests.pkgs.static_routeprefix' |
| | | |
| | | def test_includelevel1(self): |
| | | res = self.testapp.get('/static/minimal.txt', status=200) |
| | |
| | | |
| | | |
| | | class TestFixtureApp(IntegrationBase, unittest.TestCase): |
| | | package = 'pyramid.tests.pkgs.fixtureapp' |
| | | package = 'tests.pkgs.fixtureapp' |
| | | def test_another(self): |
| | | res = self.testapp.get('/another.html', status=200) |
| | | self.assertEqual(res.body, b'fixture') |
| | |
| | | self.testapp.get('/protected.html', status=403) |
| | | |
| | | class TestStaticPermApp(IntegrationBase, unittest.TestCase): |
| | | package = 'pyramid.tests.pkgs.staticpermapp' |
| | | root_factory = 'pyramid.tests.pkgs.staticpermapp:RootFactory' |
| | | package = 'tests.pkgs.staticpermapp' |
| | | root_factory = 'tests.pkgs.staticpermapp:RootFactory' |
| | | def test_allowed(self): |
| | | result = self.testapp.get('/allowed/index.html', status=200) |
| | | _assertBody(result.body, |
| | |
| | | class TestCCBug(IntegrationBase, unittest.TestCase): |
| | | # "unordered" as reported in IRC by author of |
| | | # http://labs.creativecommons.org/2010/01/13/cc-engine-and-web-non-frameworks/ |
| | | package = 'pyramid.tests.pkgs.ccbugapp' |
| | | package = 'tests.pkgs.ccbugapp' |
| | | def test_rdf(self): |
| | | res = self.testapp.get('/licenses/1/v1/rdf', status=200) |
| | | self.assertEqual(res.body, b'rdf') |
| | |
| | | # make sure views registered for a route "win" over views registered |
| | | # without one, even though the context of the non-route view may |
| | | # be more specific than the route view. |
| | | package = 'pyramid.tests.pkgs.hybridapp' |
| | | package = 'tests.pkgs.hybridapp' |
| | | def test_root(self): |
| | | res = self.testapp.get('/', status=200) |
| | | self.assertEqual(res.body, b'global') |
| | |
| | | |
| | | class TestRestBugApp(IntegrationBase, unittest.TestCase): |
| | | # test bug reported by delijati 2010/2/3 (http://pastebin.com/d4cc15515) |
| | | package = 'pyramid.tests.pkgs.restbugapp' |
| | | package = 'tests.pkgs.restbugapp' |
| | | def test_it(self): |
| | | res = self.testapp.get('/pet', status=200) |
| | | self.assertEqual(res.body, b'gotten') |
| | | |
| | | class TestForbiddenAppHasResult(IntegrationBase, unittest.TestCase): |
| | | # test that forbidden exception has ACLDenied result attached |
| | | package = 'pyramid.tests.pkgs.forbiddenapp' |
| | | package = 'tests.pkgs.forbiddenapp' |
| | | def test_it(self): |
| | | res = self.testapp.get('/x', status=403) |
| | | message, result = [x.strip() for x in res.body.split(b'\n')] |
| | |
| | | result.endswith(b"for principals ['system.Everyone']")) |
| | | |
| | | class TestViewDecoratorApp(IntegrationBase, unittest.TestCase): |
| | | package = 'pyramid.tests.pkgs.viewdecoratorapp' |
| | | package = 'tests.pkgs.viewdecoratorapp' |
| | | |
| | | def test_first(self): |
| | | res = self.testapp.get('/first', status=200) |
| | |
| | | self.assertTrue(b'OK2' in res.body) |
| | | |
| | | class TestNotFoundView(IntegrationBase, unittest.TestCase): |
| | | package = 'pyramid.tests.pkgs.notfoundview' |
| | | package = 'tests.pkgs.notfoundview' |
| | | |
| | | def test_it(self): |
| | | res = self.testapp.get('/wontbefound', status=200) |
| | |
| | | self.assertTrue(b'baz_notfound' in res.body) |
| | | |
| | | class TestForbiddenView(IntegrationBase, unittest.TestCase): |
| | | package = 'pyramid.tests.pkgs.forbiddenview' |
| | | package = 'tests.pkgs.forbiddenview' |
| | | |
| | | def test_it(self): |
| | | res = self.testapp.get('/foo', status=200) |
| | |
| | | |
| | | class TestViewPermissionBug(IntegrationBase, unittest.TestCase): |
| | | # view_execution_permitted bug as reported by Shane at http://lists.repoze.org/pipermail/repoze-dev/2010-October/003603.html |
| | | package = 'pyramid.tests.pkgs.permbugapp' |
| | | package = 'tests.pkgs.permbugapp' |
| | | def test_test(self): |
| | | res = self.testapp.get('/test', status=200) |
| | | self.assertTrue(b'ACLDenied' in res.body) |
| | |
| | | |
| | | class TestDefaultViewPermissionBug(IntegrationBase, unittest.TestCase): |
| | | # default_view_permission bug as reported by Wiggy at http://lists.repoze.org/pipermail/repoze-dev/2010-October/003602.html |
| | | package = 'pyramid.tests.pkgs.defpermbugapp' |
| | | package = 'tests.pkgs.defpermbugapp' |
| | | def test_x(self): |
| | | res = self.testapp.get('/x', status=403) |
| | | self.assertTrue(b'failed permission check' in res.body) |
| | |
| | | res = self.testapp.get('/z', status=200) |
| | | self.assertTrue(b'public' in res.body) |
| | | |
| | | from pyramid.tests.pkgs.exceptionviewapp.models import \ |
| | | AnException, NotAnException |
| | | from .pkgs.exceptionviewapp.models import AnException, NotAnException |
| | | excroot = {'anexception':AnException(), |
| | | 'notanexception':NotAnException()} |
| | | |
| | | class TestExceptionViewsApp(IntegrationBase, unittest.TestCase): |
| | | package = 'pyramid.tests.pkgs.exceptionviewapp' |
| | | package = 'tests.pkgs.exceptionviewapp' |
| | | root_factory = lambda *arg: excroot |
| | | def test_root(self): |
| | | res = self.testapp.get('/', status=200) |
| | |
| | | self.assertTrue(b'caught' in res.body) |
| | | |
| | | class TestConflictApp(unittest.TestCase): |
| | | package = 'pyramid.tests.pkgs.conflictapp' |
| | | package = 'tests.pkgs.conflictapp' |
| | | def _makeConfig(self): |
| | | from pyramid.config import Configurator |
| | | config = Configurator() |
| | |
| | | def setUp(self): |
| | | from pyramid.config import Configurator |
| | | config = Configurator() |
| | | from pyramid.tests.pkgs.includeapp1.root import configure |
| | | from .pkgs.includeapp1.root import configure |
| | | configure(config) |
| | | app = config.make_wsgi_app() |
| | | self.testapp = TestApp(app) |
| | |
| | | |
| | | class SelfScanAppTest(unittest.TestCase): |
| | | def setUp(self): |
| | | from pyramid.tests.test_config.pkgs.selfscan import main |
| | | from .test_config.pkgs.selfscan import main |
| | | config = main() |
| | | app = config.make_wsgi_app() |
| | | self.testapp = TestApp(app) |
| | |
| | | |
| | | class WSGIApp2AppTest(unittest.TestCase): |
| | | def setUp(self): |
| | | from pyramid.tests.pkgs.wsgiapp2app import main |
| | | from .pkgs.wsgiapp2app import main |
| | | config = main() |
| | | app = config.make_wsgi_app() |
| | | self.testapp = TestApp(app) |
| | |
| | | |
| | | class SubrequestAppTest(unittest.TestCase): |
| | | def setUp(self): |
| | | from pyramid.tests.pkgs.subrequestapp import main |
| | | from .pkgs.subrequestapp import main |
| | | config = main() |
| | | app = config.make_wsgi_app() |
| | | self.testapp = TestApp(app) |
| | |
| | | self.assertTrue(b'Value error raised' in res.body) |
| | | |
| | | class RendererScanAppTest(IntegrationBase, unittest.TestCase): |
| | | package = 'pyramid.tests.pkgs.rendererscanapp' |
| | | package = 'tests.pkgs.rendererscanapp' |
| | | def test_root(self): |
| | | res = self.testapp.get('/one', status=200) |
| | | self.assertTrue(b'One!' in res.body) |
| | |
| | | self.assertTrue(b'Two!' in res.body) |
| | | |
| | | def test_rescan(self): |
| | | self.config.scan('pyramid.tests.pkgs.rendererscanapp') |
| | | self.config.scan('tests.pkgs.rendererscanapp') |
| | | app = self.config.make_wsgi_app() |
| | | testapp = TestApp(app) |
| | | res = testapp.get('/one', status=200) |
File was renamed from pyramid/tests/test_paster.py |
| | |
| | | import os |
| | | import unittest |
| | | from pyramid.tests.test_scripts.dummy import DummyLoader |
| | | from .test_scripts.dummy import DummyLoader |
| | | |
| | | here = os.path.dirname(__file__) |
| | | |
File was renamed from pyramid/tests/test_path.py |
| | |
| | | |
| | | class TestCallerPath(unittest.TestCase): |
| | | def tearDown(self): |
| | | from pyramid.tests import test_path |
| | | from . import test_path |
| | | if hasattr(test_path, '__abspath__'): |
| | | del test_path.__abspath__ |
| | | |
| | |
| | | |
| | | def test_memoization_has_abspath(self): |
| | | import os |
| | | from pyramid.tests import test_path |
| | | from . import test_path |
| | | test_path.__abspath__ = '/foo/bar' |
| | | result = self._callFUT('a/b/c') |
| | | self.assertEqual(result, os.path.join('/foo/bar', 'a/b/c')) |
| | | |
| | | def test_memoization_success(self): |
| | | import os |
| | | from pyramid.tests import test_path |
| | | from . import test_path |
| | | result = self._callFUT('a/b/c') |
| | | self.assertEqual(result, os.path.join(here, 'a/b/c')) |
| | | self.assertEqual(test_path.__abspath__, here) |
| | |
| | | return caller_module(*arg, **kw) |
| | | |
| | | def test_it_level_1(self): |
| | | from pyramid.tests import test_path |
| | | from . import test_path |
| | | result = self._callFUT(1) |
| | | self.assertEqual(result, test_path) |
| | | |
| | | def test_it_level_2(self): |
| | | from pyramid.tests import test_path |
| | | from . import test_path |
| | | result = self._callFUT(2) |
| | | self.assertEqual(result, test_path) |
| | | |
| | | def test_it_level_3(self): |
| | | from pyramid.tests import test_path |
| | | from . import test_path |
| | | result = self._callFUT(3) |
| | | self.assertNotEqual(result, test_path) |
| | | |
| | |
| | | return caller_package(*arg, **kw) |
| | | |
| | | def test_it_level_1(self): |
| | | from pyramid import tests |
| | | import tests |
| | | result = self._callFUT(1) |
| | | self.assertEqual(result, tests) |
| | | |
| | | def test_it_level_2(self): |
| | | from pyramid import tests |
| | | import tests |
| | | result = self._callFUT(2) |
| | | self.assertEqual(result, tests) |
| | | |
| | |
| | | self.assertEqual(result, unittest) |
| | | |
| | | def test_it_package(self): |
| | | import pyramid.tests |
| | | import tests |
| | | def dummy_caller_module(*arg): |
| | | return pyramid.tests |
| | | return tests |
| | | result = self._callFUT(1, caller_module=dummy_caller_module) |
| | | self.assertEqual(result, pyramid.tests) |
| | | self.assertEqual(result, tests) |
| | | |
| | | class TestPackagePath(unittest.TestCase): |
| | | def _callFUT(self, package): |
| | |
| | | return package_path(package) |
| | | |
| | | def test_it_package(self): |
| | | from pyramid import tests |
| | | import tests |
| | | package = DummyPackageOrModule(tests) |
| | | result = self._callFUT(package) |
| | | self.assertEqual(result, package.package_path) |
| | | |
| | | def test_it_module(self): |
| | | from pyramid.tests import test_path |
| | | from . import test_path |
| | | module = DummyPackageOrModule(test_path) |
| | | result = self._callFUT(module) |
| | | self.assertEqual(result, module.package_path) |
| | | |
| | | def test_memoization_success(self): |
| | | from pyramid.tests import test_path |
| | | from . import test_path |
| | | module = DummyPackageOrModule(test_path) |
| | | self._callFUT(module) |
| | | self.assertEqual(module.__abspath__, module.package_path) |
| | | |
| | | def test_memoization_fail(self): |
| | | from pyramid.tests import test_path |
| | | from . import test_path |
| | | module = DummyPackageOrModule(test_path, raise_exc=TypeError) |
| | | result = self._callFUT(module) |
| | | self.assertFalse(hasattr(module, '__abspath__')) |
| | |
| | | return package_of(package) |
| | | |
| | | def test_it_package(self): |
| | | from pyramid import tests |
| | | import tests |
| | | package = DummyPackageOrModule(tests) |
| | | result = self._callFUT(package) |
| | | self.assertEqual(result, tests) |
| | | |
| | | def test_it_module(self): |
| | | import pyramid.tests.test_path |
| | | from pyramid import tests |
| | | package = DummyPackageOrModule(pyramid.tests.test_path) |
| | | import tests.test_path |
| | | import tests |
| | | package = DummyPackageOrModule(tests.test_path) |
| | | result = self._callFUT(package) |
| | | self.assertEqual(result, tests) |
| | | |
| | |
| | | return package_name(package) |
| | | |
| | | def test_it_package(self): |
| | | from pyramid import tests |
| | | import tests |
| | | package = DummyPackageOrModule(tests) |
| | | result = self._callFUT(package) |
| | | self.assertEqual(result, 'pyramid.tests') |
| | | self.assertEqual(result, 'tests') |
| | | |
| | | def test_it_namespace_package(self): |
| | | from pyramid import tests |
| | | import tests |
| | | package = DummyNamespacePackage(tests) |
| | | result = self._callFUT(package) |
| | | self.assertEqual(result, 'pyramid.tests') |
| | | self.assertEqual(result, 'tests') |
| | | |
| | | def test_it_module(self): |
| | | from pyramid.tests import test_path |
| | | from . import test_path |
| | | module = DummyPackageOrModule(test_path) |
| | | result = self._callFUT(module) |
| | | self.assertEqual(result, 'pyramid.tests') |
| | | self.assertEqual(result, 'tests') |
| | | |
| | | def test_it_None(self): |
| | | result = self._callFUT(None) |
| | |
| | | return self._getTargetClass()(package) |
| | | |
| | | def test_get_package_caller_package(self): |
| | | import pyramid.tests |
| | | import tests |
| | | from pyramid.path import CALLER_PACKAGE |
| | | self.assertEqual(self._makeOne(CALLER_PACKAGE).get_package(), |
| | | pyramid.tests) |
| | | tests) |
| | | |
| | | def test_get_package_name_caller_package(self): |
| | | from pyramid.path import CALLER_PACKAGE |
| | | self.assertEqual(self._makeOne(CALLER_PACKAGE).get_package_name(), |
| | | 'pyramid.tests') |
| | | 'tests') |
| | | |
| | | def test_get_package_string(self): |
| | | import pyramid.tests |
| | | self.assertEqual(self._makeOne('pyramid.tests').get_package(), |
| | | pyramid.tests) |
| | | import tests |
| | | self.assertEqual(self._makeOne('tests').get_package(), |
| | | tests) |
| | | |
| | | def test_get_package_name_string(self): |
| | | self.assertEqual(self._makeOne('pyramid.tests').get_package_name(), |
| | | 'pyramid.tests') |
| | | self.assertEqual(self._makeOne('tests').get_package_name(), |
| | | 'tests') |
| | | |
| | | class TestAssetResolver(unittest.TestCase): |
| | | def _getTargetClass(self): |
| | | from pyramid.path import AssetResolver |
| | | return AssetResolver |
| | | |
| | | def _makeOne(self, package='pyramid.tests'): |
| | | def _makeOne(self, package='tests'): |
| | | return self._getTargetClass()(package) |
| | | |
| | | def test_ctor_as_package(self): |
| | | import sys |
| | | tests = sys.modules['pyramid.tests'] |
| | | tests = sys.modules['tests'] |
| | | inst = self._makeOne(tests) |
| | | self.assertEqual(inst.package, tests) |
| | | |
| | | def test_ctor_as_str(self): |
| | | import sys |
| | | tests = sys.modules['pyramid.tests'] |
| | | inst = self._makeOne('pyramid.tests') |
| | | tests = sys.modules['tests'] |
| | | inst = self._makeOne('tests') |
| | | self.assertEqual(inst.package, tests) |
| | | |
| | | def test_resolve_abspath(self): |
| | |
| | | def test_resolve_absspec(self): |
| | | from pyramid.path import PkgResourcesAssetDescriptor |
| | | inst = self._makeOne(None) |
| | | r = inst.resolve('pyramid.tests:test_asset.py') |
| | | r = inst.resolve('tests:test_asset.py') |
| | | self.assertEqual(r.__class__, PkgResourcesAssetDescriptor) |
| | | self.assertTrue(r.exists()) |
| | | |
| | | def test_resolve_relspec_with_pkg(self): |
| | | from pyramid.path import PkgResourcesAssetDescriptor |
| | | inst = self._makeOne('pyramid.tests') |
| | | inst = self._makeOne('tests') |
| | | r = inst.resolve('test_asset.py') |
| | | self.assertEqual(r.__class__, PkgResourcesAssetDescriptor) |
| | | self.assertTrue(r.exists()) |
| | |
| | | from pyramid.path import PkgResourcesAssetDescriptor |
| | | return PkgResourcesAssetDescriptor |
| | | |
| | | def _makeOne(self, pkg='pyramid.tests', path='test_asset.py'): |
| | | def _makeOne(self, pkg='tests', path='test_asset.py'): |
| | | return self._getTargetClass()(pkg, path) |
| | | |
| | | def test_class_conforms_to_IAssetDescriptor(self): |
| | |
| | | |
| | | def test_absspec(self): |
| | | inst = self._makeOne() |
| | | self.assertEqual(inst.absspec(), 'pyramid.tests:test_asset.py') |
| | | self.assertEqual(inst.absspec(), 'tests:test_asset.py') |
| | | |
| | | def test_abspath(self): |
| | | inst = self._makeOne() |
| | |
| | | inst.pkg_resources.resource_stream = lambda x, y: '%s:%s' % (x, y) |
| | | s = inst.stream() |
| | | self.assertEqual(s, |
| | | '%s:%s' % ('pyramid.tests', 'test_asset.py')) |
| | | '%s:%s' % ('tests', 'test_asset.py')) |
| | | |
| | | def test_isdir(self): |
| | | inst = self._makeOne() |
| | | inst.pkg_resources = DummyPkgResource() |
| | | inst.pkg_resources.resource_isdir = lambda x, y: '%s:%s' % (x, y) |
| | | self.assertEqual(inst.isdir(), |
| | | '%s:%s' % ('pyramid.tests', 'test_asset.py')) |
| | | '%s:%s' % ('tests', 'test_asset.py')) |
| | | |
| | | def test_listdir(self): |
| | | inst = self._makeOne() |
| | | inst.pkg_resources = DummyPkgResource() |
| | | inst.pkg_resources.resource_listdir = lambda x, y: '%s:%s' % (x, y) |
| | | self.assertEqual(inst.listdir(), |
| | | '%s:%s' % ('pyramid.tests', 'test_asset.py')) |
| | | '%s:%s' % ('tests', 'test_asset.py')) |
| | | |
| | | def test_exists(self): |
| | | inst = self._makeOne() |
| | | inst.pkg_resources = DummyPkgResource() |
| | | inst.pkg_resources.resource_exists = lambda x, y: '%s:%s' % (x, y) |
| | | self.assertEqual(inst.exists(), |
| | | '%s:%s' % ('pyramid.tests', 'test_asset.py')) |
| | | '%s:%s' % ('tests', 'test_asset.py')) |
| | | |
| | | class TestFSAssetDescriptor(unittest.TestCase): |
| | | def _getTargetClass(self): |
| | |
| | | def test_zope_dottedname_style_resolve_absolute(self): |
| | | typ = self._makeOne() |
| | | result = typ._zope_dottedname_style( |
| | | 'pyramid.tests.test_path.TestDottedNameResolver', None) |
| | | 'tests.test_path.TestDottedNameResolver', None) |
| | | self.assertEqual(result, self.__class__) |
| | | |
| | | def test_zope_dottedname_style_irrresolveable_absolute(self): |
| | |
| | | 'pyramid.test_path.nonexisting_name', None) |
| | | |
| | | def test__zope_dottedname_style_resolve_relative(self): |
| | | import pyramid.tests |
| | | import tests |
| | | typ = self._makeOne() |
| | | result = typ._zope_dottedname_style( |
| | | '.test_path.TestDottedNameResolver', pyramid.tests) |
| | | '.test_path.TestDottedNameResolver', tests) |
| | | self.assertEqual(result, self.__class__) |
| | | |
| | | def test__zope_dottedname_style_resolve_relative_leading_dots(self): |
| | | import pyramid.tests.test_path |
| | | import tests.test_path |
| | | typ = self._makeOne() |
| | | result = typ._zope_dottedname_style( |
| | | '..tests.test_path.TestDottedNameResolver', pyramid.tests) |
| | | '..tests.test_path.TestDottedNameResolver', tests) |
| | | self.assertEqual(result, self.__class__) |
| | | |
| | | def test__zope_dottedname_style_resolve_relative_is_dot(self): |
| | | import pyramid.tests |
| | | import tests |
| | | typ = self._makeOne() |
| | | result = typ._zope_dottedname_style('.', pyramid.tests) |
| | | self.assertEqual(result, pyramid.tests) |
| | | result = typ._zope_dottedname_style('.', tests) |
| | | self.assertEqual(result, tests) |
| | | |
| | | def test__zope_dottedname_style_irresolveable_relative_is_dot(self): |
| | | typ = self._makeOne() |
| | |
| | | "relative name '.whatever' irresolveable without package") |
| | | |
| | | def test_zope_dottedname_style_irrresolveable_relative(self): |
| | | import pyramid.tests |
| | | import tests |
| | | typ = self._makeOne() |
| | | self.assertRaises(ImportError, typ._zope_dottedname_style, |
| | | '.notexisting', pyramid.tests) |
| | | '.notexisting', tests) |
| | | |
| | | def test__zope_dottedname_style_resolveable_relative(self): |
| | | import pyramid |
| | | import tests |
| | | typ = self._makeOne() |
| | | result = typ._zope_dottedname_style('.tests', pyramid) |
| | | from pyramid import tests |
| | | result = typ._zope_dottedname_style('.', tests) |
| | | self.assertEqual(result, tests) |
| | | |
| | | def test__zope_dottedname_style_irresolveable_absolute(self): |
| | |
| | | def test__zope_dottedname_style_resolveable_absolute(self): |
| | | typ = self._makeOne() |
| | | result = typ._zope_dottedname_style( |
| | | 'pyramid.tests.test_path.TestDottedNameResolver', None) |
| | | 'tests.test_path.TestDottedNameResolver', None) |
| | | self.assertEqual(result, self.__class__) |
| | | |
| | | def test__pkg_resources_style_resolve_absolute(self): |
| | | typ = self._makeOne() |
| | | result = typ._pkg_resources_style( |
| | | 'pyramid.tests.test_path:TestDottedNameResolver', None) |
| | | 'tests.test_path:TestDottedNameResolver', None) |
| | | self.assertEqual(result, self.__class__) |
| | | |
| | | def test__pkg_resources_style_irrresolveable_absolute(self): |
| | | typ = self._makeOne() |
| | | self.assertRaises(ImportError, typ._pkg_resources_style, |
| | | 'pyramid.tests:nonexisting', None) |
| | | 'tests:nonexisting', None) |
| | | |
| | | def test__pkg_resources_style_resolve_relative(self): |
| | | import pyramid.tests |
| | | import tests |
| | | typ = self._makeOne() |
| | | result = typ._pkg_resources_style( |
| | | '.test_path:TestDottedNameResolver', pyramid.tests) |
| | | '.test_path:TestDottedNameResolver', tests) |
| | | self.assertEqual(result, self.__class__) |
| | | |
| | | def test__pkg_resources_style_resolve_relative_is_dot(self): |
| | | import pyramid.tests |
| | | import tests |
| | | typ = self._makeOne() |
| | | result = typ._pkg_resources_style('.', pyramid.tests) |
| | | self.assertEqual(result, pyramid.tests) |
| | | result = typ._pkg_resources_style('.', tests) |
| | | self.assertEqual(result, tests) |
| | | |
| | | def test__pkg_resources_style_resolve_relative_nocurrentpackage(self): |
| | | typ = self._makeOne() |
| | |
| | | def test_resolve_using_pkgresources_style(self): |
| | | typ = self._makeOne() |
| | | result = typ.resolve( |
| | | 'pyramid.tests.test_path:TestDottedNameResolver') |
| | | 'tests.test_path:TestDottedNameResolver') |
| | | self.assertEqual(result, self.__class__) |
| | | |
| | | def test_resolve_using_zope_dottedname_style(self): |
| | | typ = self._makeOne() |
| | | result = typ.resolve( |
| | | 'pyramid.tests.test_path:TestDottedNameResolver') |
| | | 'tests.test_path:TestDottedNameResolver') |
| | | self.assertEqual(result, self.__class__) |
| | | |
| | | def test_resolve_missing_raises(self): |
| | |
| | | self.__class__) |
| | | |
| | | def test_ctor_string_module_resolveable(self): |
| | | import pyramid.tests |
| | | typ = self._makeOne('pyramid.tests.test_path') |
| | | self.assertEqual(typ.package, pyramid.tests) |
| | | import tests |
| | | typ = self._makeOne('tests.test_path') |
| | | self.assertEqual(typ.package, tests) |
| | | |
| | | def test_ctor_string_package_resolveable(self): |
| | | import pyramid.tests |
| | | typ = self._makeOne('pyramid.tests') |
| | | self.assertEqual(typ.package, pyramid.tests) |
| | | import tests |
| | | typ = self._makeOne('tests') |
| | | self.assertEqual(typ.package, tests) |
| | | |
| | | def test_ctor_string_irresolveable(self): |
| | | self.assertRaises(ValueError, self._makeOne, 'cant.be.found') |
| | | |
| | | def test_ctor_module(self): |
| | | import pyramid.tests |
| | | import pyramid.tests.test_path |
| | | typ = self._makeOne(pyramid.tests.test_path) |
| | | self.assertEqual(typ.package, pyramid.tests) |
| | | import tests |
| | | from . import test_path |
| | | typ = self._makeOne(test_path) |
| | | self.assertEqual(typ.package, tests) |
| | | |
| | | def test_ctor_package(self): |
| | | import pyramid.tests |
| | | typ = self._makeOne(pyramid.tests) |
| | | self.assertEqual(typ.package, pyramid.tests) |
| | | import tests |
| | | typ = self._makeOne(tests) |
| | | self.assertEqual(typ.package, tests) |
| | | |
| | | def test_ctor_None(self): |
| | | typ = self._makeOne(None) |
File was renamed from pyramid/tests/test_registry.py |
| | |
| | | |
| | | def test_default_package_name(self): |
| | | registry = self._makeOne() |
| | | self.assertEqual(registry.package_name, 'pyramid.tests') |
| | | self.assertEqual(registry.package_name, 'tests') |
| | | |
| | | def test_registerHandler_and_notify(self): |
| | | registry = self._makeOne() |
File was renamed from pyramid/tests/test_renderers.py |
| | |
| | | |
| | | def _registerRenderer(self): |
| | | renderer = self.config.testing_add_renderer( |
| | | 'pyramid.tests:abc/def.pt') |
| | | 'tests:abc/def.pt') |
| | | renderer.string_response = 'abc' |
| | | return renderer |
| | | |
| | |
| | | renderer.assert_(request=request) |
| | | |
| | | def test_it_with_package(self): |
| | | import pyramid.tests |
| | | import tests |
| | | renderer = self._registerRenderer() |
| | | request = testing.DummyRequest() |
| | | result = self._callFUT('abc/def.pt', dict(a=1), request=request, |
| | | package=pyramid.tests) |
| | | package=tests) |
| | | self.assertEqual(result, 'abc') |
| | | renderer.assert_(a=1) |
| | | renderer.assert_(request=request) |
| | |
| | | |
| | | def test_it_no_request(self): |
| | | renderer = self.config.testing_add_renderer( |
| | | 'pyramid.tests:abc/def.pt') |
| | | 'tests:abc/def.pt') |
| | | renderer.string_response = 'abc' |
| | | response = self._callFUT('abc/def.pt', dict(a=1)) |
| | | self.assertEqual(response.body, b'abc') |
| | |
| | | |
| | | def test_it_with_request(self): |
| | | renderer = self.config.testing_add_renderer( |
| | | 'pyramid.tests:abc/def.pt') |
| | | 'tests:abc/def.pt') |
| | | renderer.string_response = 'abc' |
| | | request = testing.DummyRequest() |
| | | response = self._callFUT('abc/def.pt', |
| | |
| | | renderer.assert_(request=request) |
| | | |
| | | def test_it_with_package(self): |
| | | import pyramid.tests |
| | | import tests |
| | | renderer = self.config.testing_add_renderer( |
| | | 'pyramid.tests:abc/def.pt') |
| | | 'tests:abc/def.pt') |
| | | renderer.string_response = 'abc' |
| | | request = testing.DummyRequest() |
| | | response = self._callFUT('abc/def.pt', dict(a=1), request=request, |
| | | package=pyramid.tests) |
| | | package=tests) |
| | | self.assertEqual(response.body, b'abc') |
| | | renderer.assert_(a=1) |
| | | renderer.assert_(request=request) |
| | |
| | | |
| | | def test_it_no_package(self): |
| | | renderer = self.config.testing_add_renderer( |
| | | 'pyramid.tests:abc/def.pt') |
| | | 'tests:abc/def.pt') |
| | | result = self._callFUT('abc/def.pt') |
| | | self.assertEqual(result, renderer) |
| | | |
| | | def test_it_with_package(self): |
| | | import pyramid.tests |
| | | import tests |
| | | renderer = self.config.testing_add_renderer( |
| | | 'pyramid.tests:abc/def.pt') |
| | | result = self._callFUT('abc/def.pt', package=pyramid.tests) |
| | | 'tests:abc/def.pt') |
| | | result = self._callFUT('abc/def.pt', package=tests) |
| | | self.assertEqual(result, renderer) |
| | | |
| | | def test_it_with_registry(self): |
| | | renderer = self.config.testing_add_renderer( |
| | | 'pyramid.tests:abc/def.pt') |
| | | 'tests:abc/def.pt') |
| | | result = self._callFUT('abc/def.pt', registry=self.config.registry) |
| | | self.assertEqual(result, renderer) |
| | | |
| | |
| | | from pyramid.config import Configurator |
| | | isolated_config = Configurator() |
| | | renderer = isolated_config.testing_add_renderer( |
| | | 'pyramid.tests:abc/def.pt') |
| | | 'tests:abc/def.pt') |
| | | result = self._callFUT('abc/def.pt', registry=isolated_config.registry) |
| | | self.assertEqual(result, renderer) |
| | | |
File was renamed from pyramid/tests/test_scaffolds/test_copydir.py |
| | |
| | | from pyramid.compat import NativeIO |
| | | self.dirname = tempfile.mkdtemp() |
| | | self.out = NativeIO() |
| | | self.fixturetuple = ('pyramid.tests.test_scaffolds', |
| | | self.fixturetuple = ('tests.test_scaffolds', |
| | | 'fixture_scaffold') |
| | | |
| | | def tearDown(self): |
| | |
| | | self.assertTrue( |
| | | 'Copying fixture_scaffold/+package+/__init__.py_tmpl to' in result) |
| | | source = pkg_resources.resource_filename( |
| | | 'pyramid.tests.test_scaffolds', |
| | | 'tests.test_scaffolds', |
| | | 'fixture_scaffold/+package+/__init__.py_tmpl') |
| | | target = os.path.join(self.dirname, 'mypackage', '__init__.py') |
| | | with open(target, 'r') as f: |
| | |
| | | self.assertTrue('Creating' in result) |
| | | self.assertTrue('Copying __init__.py_tmpl to' in result) |
| | | source = pkg_resources.resource_filename( |
| | | 'pyramid.tests.test_scaffolds', |
| | | 'tests.test_scaffolds', |
| | | 'fixture_scaffold/+package+/__init__.py_tmpl') |
| | | target = os.path.join(self.dirname, 'mypackage', '__init__.py') |
| | | with open(target, 'r') as f: |
| | |
| | | from pyramid.compat import NativeIO |
| | | self.dirname = tempfile.mkdtemp() |
| | | self.out = NativeIO() |
| | | self.fixturetuple = ('pyramid.tests.test_scaffolds', |
| | | 'fixture_scaffold') |
| | | self.fixturetuple = ('tests.test_scaffolds', 'fixture_scaffold') |
| | | self.src_content = """\ |
| | | These are not the droids |
| | | that you are looking for.""" |
File was renamed from pyramid/tests/test_scripts/test_prequest.py |
| | |
| | | import unittest |
| | | from pyramid.tests.test_scripts import dummy |
| | | from . import dummy |
| | | |
| | | class TestPRequestCommand(unittest.TestCase): |
| | | def _getTargetClass(self): |
File was renamed from pyramid/tests/test_scripts/test_proutes.py |
| | |
| | | import os |
| | | import unittest |
| | | from pyramid.tests.test_scripts import dummy |
| | | from . import dummy |
| | | |
| | | |
| | | class DummyIntrospector(object): |
| | |
| | | compare_to = L[-1].split()[:3] |
| | | self.assertEqual( |
| | | compare_to, |
| | | ['a', '/a', 'pyramid.tests.test_scripts.test_proutes.view'] |
| | | ['a', '/a', 'tests.test_scripts.test_proutes.view'] |
| | | ) |
| | | |
| | | def test_one_route_with_long_name_one_view_registered(self): |
| | |
| | | compare_to, |
| | | ['very_long_name_123', |
| | | '/and_very_long_pattern_as_well', |
| | | 'pyramid.tests.test_scripts.test_proutes.view'] |
| | | 'tests.test_scripts.test_proutes.view'] |
| | | ) |
| | | |
| | | def test_class_view(self): |
| | |
| | | compare_to = L[-1].split() |
| | | expected = [ |
| | | 'foo', '/a/b', |
| | | 'pyramid.tests.test_scripts.dummy.DummyView.view', 'POST' |
| | | 'tests.test_scripts.dummy.DummyView.view', 'POST' |
| | | ] |
| | | self.assertEqual(compare_to, expected) |
| | | |
| | |
| | | self.assertEqual(result, 0) |
| | | self.assertEqual(len(L), 3) |
| | | compare_to = L[-1].split()[:3] |
| | | view_module = 'pyramid.tests.test_scripts.dummy' |
| | | view_str = '<pyramid.tests.test_scripts.dummy.DummyMultiView' |
| | | view_module = 'tests.test_scripts.dummy' |
| | | view_str = '<tests.test_scripts.dummy.DummyMultiView' |
| | | final = '%s.%s' % (view_module, view_str) |
| | | |
| | | self.assertEqual( |
| | |
| | | compare_to = L[-1].split() |
| | | expected = [ |
| | | 'foo', '/a/b', |
| | | 'pyramid.tests.test_scripts.test_proutes.view1', 'POST' |
| | | 'tests.test_scripts.test_proutes.view1', 'POST' |
| | | ] |
| | | self.assertEqual(compare_to, expected) |
| | | |
| | |
| | | compare_to = L[-1].split() |
| | | expected = [ |
| | | 'foo', '/a/b', |
| | | 'pyramid.tests.test_scripts.test_proutes.view1', 'POST' |
| | | 'tests.test_scripts.test_proutes.view1', 'POST' |
| | | ] |
| | | self.assertEqual(compare_to, expected) |
| | | |
| | |
| | | compare_to = L[-1].split() |
| | | expected = [ |
| | | 'foo', '/a/b', |
| | | 'pyramid.tests.test_scripts.test_proutes.view1', 'POST' |
| | | 'tests.test_scripts.test_proutes.view1', 'POST' |
| | | ] |
| | | self.assertEqual(compare_to, expected) |
| | | |
| | |
| | | compare_to = L[-1].split() |
| | | expected = [ |
| | | 'foo', '/a/b', |
| | | 'pyramid.tests.test_scripts.test_proutes.view1', |
| | | 'tests.test_scripts.test_proutes.view1', |
| | | '<route', 'mismatch>' |
| | | ] |
| | | self.assertEqual(compare_to, expected) |
| | |
| | | |
| | | expected = [ |
| | | ['__static/', '/static/*subpath', |
| | | 'pyramid.tests.test_scripts:static/', '*'], |
| | | 'tests.test_scripts:static/', '*'], |
| | | ['__static2/', '/static2/*subpath', path2 + os.sep, '*'], |
| | | ['__pyramid_scaffold/', '/pyramid_scaffold/*subpath', |
| | | 'pyramid:scaffolds/starter/+package+/static/', '*'], |
| | |
| | | compare_to = L[-1].split() |
| | | expected = [ |
| | | 'foo', '/a/b', |
| | | 'pyramid.tests.test_scripts.test_proutes.view1', |
| | | 'tests.test_scripts.test_proutes.view1', |
| | | 'GET' |
| | | ] |
| | | self.assertEqual(compare_to, expected) |
| | |
| | | compare_to = L[-1].split() |
| | | expected = [ |
| | | 'foo', '/a/b', |
| | | 'pyramid.tests.test_scripts.test_proutes.view1', |
| | | 'tests.test_scripts.test_proutes.view1', |
| | | '!POST,*' |
| | | ] |
| | | self.assertEqual(compare_to, expected) |
| | |
| | | compare_to = L[-1].split() |
| | | expected = [ |
| | | 'foo', '/a/b', |
| | | 'pyramid.tests.test_scripts.test_proutes.view1', |
| | | 'tests.test_scripts.test_proutes.view1', |
| | | '!POST,*' |
| | | ] |
| | | self.assertEqual(compare_to, expected) |
File was renamed from pyramid/tests/test_scripts/test_pserve.py |
| | |
| | | import os |
| | | import unittest |
| | | from pyramid.tests.test_scripts import dummy |
| | | from . import dummy |
| | | |
| | | |
| | | here = os.path.abspath(os.path.dirname(__file__)) |
| | |
| | | inst = self._makeOne('development.ini') |
| | | loader = self.loader('/base/path.ini') |
| | | loader.settings = {'pserve': { |
| | | 'watch_files': 'foo\n/baz\npyramid.tests.test_scripts:*.py', |
| | | 'watch_files': 'foo\n/baz\ntests.test_scripts:*.py', |
| | | }} |
| | | inst.pserve_file_config(loader, global_conf={'a': '1'}) |
| | | self.assertEqual(loader.calls[0]['defaults'], { |
File was renamed from pyramid/tests/test_scripts/test_pshell.py |
| | |
| | | import os |
| | | import unittest |
| | | from pyramid.tests.test_scripts import dummy |
| | | from . import dummy |
| | | |
| | | |
| | | class TestPShellCommand(unittest.TestCase): |
File was renamed from pyramid/tests/test_scripts/test_ptweens.py |
| | |
| | | import unittest |
| | | from pyramid.tests.test_scripts import dummy |
| | | from . import dummy |
| | | |
| | | class TestPTweensCommand(unittest.TestCase): |
| | | def _getTargetClass(self): |
File was renamed from pyramid/tests/test_scripts/test_pviews.py |
| | |
| | | import unittest |
| | | from pyramid.tests.test_scripts import dummy |
| | | from . import dummy |
| | | |
| | | class TestPViewsCommand(unittest.TestCase): |
| | | def _getTargetClass(self): |
| | |
| | | self.assertEqual(L[3], ' context: context') |
| | | self.assertEqual(L[4], ' view name: a') |
| | | self.assertEqual(L[8], |
| | | ' pyramid.tests.test_scripts.dummy.DummyView') |
| | | ' tests.test_scripts.dummy.DummyView') |
| | | |
| | | def test_views_command_single_view_function_traversal(self): |
| | | from pyramid.registry import Registry |
| | |
| | | self.assertEqual(L[3], ' context: context') |
| | | self.assertEqual(L[4], ' view name: a') |
| | | self.assertEqual(L[8], |
| | | ' pyramid.tests.test_scripts.test_pviews.view') |
| | | ' tests.test_scripts.test_pviews.view') |
| | | |
| | | def test_views_command_single_view_traversal_with_permission(self): |
| | | from pyramid.registry import Registry |
| | |
| | | self.assertEqual(L[3], ' context: context') |
| | | self.assertEqual(L[4], ' view name: a') |
| | | self.assertEqual(L[8], |
| | | ' pyramid.tests.test_scripts.dummy.DummyView') |
| | | ' tests.test_scripts.dummy.DummyView') |
| | | self.assertEqual(L[9], ' required permission = test') |
| | | |
| | | def test_views_command_single_view_traversal_with_predicates(self): |
| | |
| | | self.assertEqual(L[3], ' context: context') |
| | | self.assertEqual(L[4], ' view name: a') |
| | | self.assertEqual(L[8], |
| | | ' pyramid.tests.test_scripts.dummy.DummyView') |
| | | ' tests.test_scripts.dummy.DummyView') |
| | | self.assertEqual(L[9], ' view predicates (predicate = x)') |
| | | |
| | | def test_views_command_single_view_route(self): |
| | |
| | | self.assertEqual(L[10], ' route path: /a') |
| | | self.assertEqual(L[11], ' subpath: ') |
| | | self.assertEqual(L[15], |
| | | ' pyramid.tests.test_scripts.dummy.DummyView') |
| | | ' tests.test_scripts.dummy.DummyView') |
| | | |
| | | def test_views_command_multi_view_nested(self): |
| | | from pyramid.registry import Registry |
| | |
| | | self.assertEqual(L[3], ' context: context') |
| | | self.assertEqual(L[4], ' view name: a') |
| | | self.assertEqual(L[8], |
| | | ' pyramid.tests.test_scripts.dummy.DummyMultiView') |
| | | ' tests.test_scripts.dummy.DummyMultiView') |
| | | self.assertEqual(L[12], |
| | | ' pyramid.tests.test_scripts.dummy.view1.call') |
| | | ' tests.test_scripts.dummy.view1.call') |
| | | |
| | | def test_views_command_single_view_route_with_route_predicates(self): |
| | | from pyramid.registry import Registry |
| | |
| | | self.assertEqual(L[11], ' subpath: ') |
| | | self.assertEqual(L[12], ' route predicates (predicate = x)') |
| | | self.assertEqual(L[16], |
| | | ' pyramid.tests.test_scripts.dummy.DummyView') |
| | | ' tests.test_scripts.dummy.DummyView') |
| | | |
| | | def test_views_command_multiview(self): |
| | | from pyramid.registry import Registry |
| | |
| | | self.assertEqual(L[3], ' context: context') |
| | | self.assertEqual(L[4], ' view name: a') |
| | | self.assertEqual(L[8], |
| | | ' pyramid.tests.test_scripts.dummy.view.call') |
| | | ' tests.test_scripts.dummy.view.call') |
| | | |
| | | def test_views_command_multiview_with_permission(self): |
| | | from pyramid.registry import Registry |
| | |
| | | self.assertEqual(L[3], ' context: context') |
| | | self.assertEqual(L[4], ' view name: a') |
| | | self.assertEqual(L[8], |
| | | ' pyramid.tests.test_scripts.dummy.view.call') |
| | | ' tests.test_scripts.dummy.view.call') |
| | | self.assertEqual(L[9], ' required permission = test') |
| | | |
| | | def test_views_command_multiview_with_predicates(self): |
| | |
| | | self.assertEqual(L[3], ' context: context') |
| | | self.assertEqual(L[4], ' view name: a') |
| | | self.assertEqual(L[8], |
| | | ' pyramid.tests.test_scripts.dummy.view.call') |
| | | ' tests.test_scripts.dummy.view.call') |
| | | self.assertEqual(L[9], ' view predicates (predicate = x)') |
| | | |
| | | class Test_main(unittest.TestCase): |
File was renamed from pyramid/tests/test_session.py |
| | |
| | | |
| | | def test_loads(self): |
| | | # generated from dumping Dummy() using protocol=2 |
| | | cstruct = b'\x80\x02cpyramid.tests.test_session\nDummy\nq\x00)\x81q\x01.' |
| | | cstruct = b'\x80\x02ctests.test_session\nDummy\nq\x00)\x81q\x01.' |
| | | serializer = self._makeOne() |
| | | result = serializer.loads(cstruct) |
| | | self.assertIsInstance(result, Dummy) |
File was renamed from pyramid/tests/test_static.py |
| | |
| | | self.assertEqual(inst.index, 'index.html') |
| | | |
| | | def test_call_adds_slash_path_info_empty(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':''}) |
| | | context = DummyContext() |
| | | from pyramid.httpexceptions import HTTPMovedPermanently |
| | | self.assertRaises(HTTPMovedPermanently, inst, context, request) |
| | | |
| | | def test_path_info_slash_means_index_html(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | | self.assertTrue(b'<html>static</html>' in response.body) |
| | | |
| | | def test_oob_singledot(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/./index.html'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | |
| | | self.assertTrue(b'<html>static</html>' in response.body) |
| | | |
| | | def test_oob_emptyelement(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'//index.html'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | |
| | | self.assertTrue(b'<html>static</html>' in response.body) |
| | | |
| | | def test_oob_dotdotslash(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/subdir/../../minimal.pt'}) |
| | | context = DummyContext() |
| | | from pyramid.httpexceptions import HTTPNotFound |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_oob_dotdotslash_encoded(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest( |
| | | {'PATH_INFO':'/subdir/%2E%2E%2F%2E%2E/minimal.pt'}) |
| | | context = DummyContext() |
| | |
| | | |
| | | def test_oob_os_sep(self): |
| | | import os |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | dds = '..' + os.sep |
| | | request = self._makeRequest({'PATH_INFO':'/subdir/%s%sminimal.pt' % |
| | | (dds, dds)}) |
| | |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_resource_doesnt_exist(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/notthere'}) |
| | | context = DummyContext() |
| | | from pyramid.httpexceptions import HTTPNotFound |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_resource_isdir(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/subdir/'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | | self.assertTrue(b'<html>subdir</html>' in response.body) |
| | | |
| | | def test_resource_is_file(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/index.html'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | |
| | | |
| | | def test_resource_is_file_with_wsgi_file_wrapper(self): |
| | | from pyramid.response import _BLOCK_SIZE |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/index.html'}) |
| | | class _Wrapper(object): |
| | | def __init__(self, file, block_size=None): |
| | |
| | | app_iter.file.close() |
| | | |
| | | def test_resource_is_file_with_cache_max_age(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static', cache_max_age=600) |
| | | inst = self._makeOne('tests:fixtures/static', cache_max_age=600) |
| | | request = self._makeRequest({'PATH_INFO':'/index.html'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | |
| | | 'Expires', 'Last-Modified']) |
| | | |
| | | def test_resource_is_file_with_no_cache_max_age(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static', |
| | | inst = self._makeOne('tests:fixtures/static', |
| | | cache_max_age=None) |
| | | request = self._makeRequest({'PATH_INFO':'/index.html'}) |
| | | context = DummyContext() |
| | |
| | | ['Content-Length', 'Content-Type', 'Last-Modified']) |
| | | |
| | | def test_resource_notmodified(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/index.html'}) |
| | | request.if_modified_since = fiveyrsfuture |
| | | context = DummyContext() |
| | |
| | | app_iter.close() |
| | | |
| | | def test_not_found(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/notthere.html'}) |
| | | context = DummyContext() |
| | | from pyramid.httpexceptions import HTTPNotFound |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_gz_resource_no_content_encoding(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/arcs.svg.tgz'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | |
| | | response.app_iter.close() |
| | | |
| | | def test_resource_no_content_encoding(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':'/index.html'}) |
| | | context = DummyContext() |
| | | response = inst(context, request) |
| | |
| | | self.assertEqual(inst.index, 'index.html') |
| | | |
| | | def test_call_adds_slash_path_info_empty(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest({'PATH_INFO':''}) |
| | | request.subpath = () |
| | | context = DummyContext() |
| | |
| | | self.assertRaises(HTTPMovedPermanently, inst, context, request) |
| | | |
| | | def test_path_info_slash_means_index_html(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = () |
| | | context = DummyContext() |
| | |
| | | self.assertTrue(b'<html>static</html>' in response.body) |
| | | |
| | | def test_oob_singledot(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('.', 'index.html') |
| | | context = DummyContext() |
| | |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_oob_emptyelement(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('', 'index.html') |
| | | context = DummyContext() |
| | |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_oob_dotdotslash(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('subdir', '..', '..', 'minimal.pt') |
| | | context = DummyContext() |
| | |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_oob_dotdotslash_encoded(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('subdir', '%2E%2E', '%2E%2E', 'minimal.pt') |
| | | context = DummyContext() |
| | |
| | | |
| | | def test_oob_os_sep(self): |
| | | import os |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | dds = '..' + os.sep |
| | | request = self._makeRequest() |
| | | request.subpath = ('subdir', dds, dds, 'minimal.pt') |
| | |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_resource_doesnt_exist(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('notthere,') |
| | | context = DummyContext() |
| | |
| | | self.assertRaises(HTTPNotFound, inst, context, request) |
| | | |
| | | def test_resource_isdir(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('subdir',) |
| | | context = DummyContext() |
| | |
| | | self.assertTrue(b'<html>subdir</html>' in response.body) |
| | | |
| | | def test_resource_is_file(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('index.html',) |
| | | context = DummyContext() |
| | |
| | | self.assertTrue(b'<html>static</html>' in response.body) |
| | | |
| | | def test_resource_is_file_with_cache_max_age(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static', cache_max_age=600) |
| | | inst = self._makeOne('tests:fixtures/static', cache_max_age=600) |
| | | request = self._makeRequest() |
| | | request.subpath = ('index.html',) |
| | | context = DummyContext() |
| | |
| | | 'Expires', 'Last-Modified']) |
| | | |
| | | def test_resource_is_file_with_no_cache_max_age(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static', |
| | | inst = self._makeOne('tests:fixtures/static', |
| | | cache_max_age=None) |
| | | request = self._makeRequest() |
| | | request.subpath = ('index.html',) |
| | |
| | | ['Content-Length', 'Content-Type', 'Last-Modified']) |
| | | |
| | | def test_resource_notmodified(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.if_modified_since = fiveyrsfuture |
| | | request.subpath = ('index.html',) |
| | |
| | | app_iter.close() |
| | | |
| | | def test_not_found(self): |
| | | inst = self._makeOne('pyramid.tests:fixtures/static') |
| | | inst = self._makeOne('tests:fixtures/static') |
| | | request = self._makeRequest() |
| | | request.subpath = ('notthere.html',) |
| | | context = DummyContext() |
| | |
| | | ('css/main-test.css', {})) |
| | | |
| | | def test_it_with_absspec(self): |
| | | fut = self._makeOne('pyramid.tests:fixtures/manifest.json') |
| | | fut = self._makeOne('tests:fixtures/manifest.json') |
| | | self.assertEqual(fut('foo', 'bar', {}), ('bar', {})) |
| | | self.assertEqual( |
| | | fut('foo', 'css/main.css', {}), |
File was renamed from pyramid/tests/test_testing.py |
| | |
| | | self.assertEqual(config.registry, current['registry']) |
| | | self.assertEqual(current['registry'].__class__, Registry) |
| | | self.assertEqual(current['request'], None) |
| | | self.assertEqual(config.package.__name__, 'pyramid.tests') |
| | | self.assertEqual(config.package.__name__, 'tests') |
| | | self._assertSMHook(get_current_registry) |
| | | |
| | | def test_it_with_registry(self): |
File was renamed from pyramid/tests/test_url.py |
| | |
| | | result = request.static_url('static/foo.css') |
| | | self.assertEqual(result, 'abc') |
| | | self.assertEqual(info.args, |
| | | ('pyramid.tests:static/foo.css', request, {}) ) |
| | | ('tests:static/foo.css', request, {}) ) |
| | | |
| | | def test_static_url_abs(self): |
| | | from pyramid.interfaces import IStaticURLInfo |
| | | request = self._makeOne() |
| | | info = DummyStaticURLInfo('abc') |
| | | request.registry.registerUtility(info, IStaticURLInfo) |
| | | result = request.static_url('pyramid.tests:static/foo.css') |
| | | result = request.static_url('tests:static/foo.css') |
| | | self.assertEqual(result, 'abc') |
| | | self.assertEqual(info.args, |
| | | ('pyramid.tests:static/foo.css', request, {}) ) |
| | | ('tests:static/foo.css', request, {}) ) |
| | | |
| | | def test_static_url_found_abs_no_registry_on_request(self): |
| | | from pyramid.interfaces import IStaticURLInfo |
| | |
| | | info = DummyStaticURLInfo('abc') |
| | | registry.registerUtility(info, IStaticURLInfo) |
| | | del request.registry |
| | | result = request.static_url('pyramid.tests:static/foo.css') |
| | | result = request.static_url('tests:static/foo.css') |
| | | self.assertEqual(result, 'abc') |
| | | self.assertEqual(info.args, |
| | | ('pyramid.tests:static/foo.css', request, {}) ) |
| | | ('tests:static/foo.css', request, {}) ) |
| | | |
| | | def test_static_url_abspath_integration_with_staticurlinfo(self): |
| | | from pyramid.interfaces import IStaticURLInfo |
| | |
| | | result = request.static_path('static/foo.css') |
| | | self.assertEqual(result, 'abc') |
| | | self.assertEqual(info.args, |
| | | ('pyramid.tests:static/foo.css', request, |
| | | ('tests:static/foo.css', request, |
| | | {'_app_url':'/foo'}) |
| | | ) |
| | | |
| | |
| | | request.script_name = '/foo' |
| | | info = DummyStaticURLInfo('abc') |
| | | request.registry.registerUtility(info, IStaticURLInfo) |
| | | result = request.static_path('pyramid.tests:static/foo.css') |
| | | result = request.static_path('tests:static/foo.css') |
| | | self.assertEqual(result, 'abc') |
| | | self.assertEqual(info.args, |
| | | ('pyramid.tests:static/foo.css', request, |
| | | ('tests:static/foo.css', request, |
| | | {'_app_url':'/foo'}) |
| | | ) |
| | | |
| | |
| | | result = request.static_path('static/foo.css') |
| | | self.assertEqual(result, 'abc') |
| | | self.assertEqual(info.args, |
| | | ('pyramid.tests:static/foo.css', request, |
| | | ('tests:static/foo.css', request, |
| | | {'_app_url':'/foo'}) |
| | | ) |
| | | |
| | |
| | | request = self._makeRequest() |
| | | result = self._callFUT('abc', request, _app_url='') |
| | | self.assertEqual(result, 'static url') |
| | | self.assertEqual(request.path, 'pyramid.tests:abc') |
| | | self.assertEqual(request.path, 'tests:abc') |
| | | self.assertEqual(request.kw, {'_app_url':''}) |
| | | |
| | | class Test_static_path(unittest.TestCase): |
| | |
| | | request = self._makeRequest() |
| | | result = self._callFUT('abc', request, _app_url='') |
| | | self.assertEqual(result, 'static path') |
| | | self.assertEqual(request.path, 'pyramid.tests:abc') |
| | | self.assertEqual(request.path, 'tests:abc') |
| | | self.assertEqual(request.kw, {'_app_url':''}) |
| | | |
| | | class Test_current_route_url(unittest.TestCase): |
File was renamed from pyramid/tests/test_util.py |
| | |
| | | |
| | | def test_new_class_keeps_parent_module_name(self): |
| | | foo = self._makeOne() |
| | | self.assertEqual(foo.__module__, 'pyramid.tests.test_util') |
| | | self.assertEqual(foo.__class__.__module__, 'pyramid.tests.test_util') |
| | | self.assertEqual(foo.__module__, 'tests.test_util') |
| | | self.assertEqual(foo.__class__.__module__, 'tests.test_util') |
| | | foo.set_property(lambda _: 1, name='x', reify=True) |
| | | self.assertEqual(foo.__module__, 'pyramid.tests.test_util') |
| | | self.assertEqual(foo.__class__.__module__, 'pyramid.tests.test_util') |
| | | self.assertEqual(foo.__module__, 'tests.test_util') |
| | | self.assertEqual(foo.__class__.__module__, 'tests.test_util') |
| | | |
| | | class Test_WeakOrderedSet(unittest.TestCase): |
| | | def _makeOne(self): |
| | |
| | | def test_method(self): |
| | | self.assertEqual( |
| | | self._callFUT(self.test_method), |
| | | 'method test_method of class pyramid.tests.test_util.' |
| | | 'method test_method of class tests.test_util.' |
| | | 'Test_object_description') |
| | | |
| | | def test_class(self): |
| | | self.assertEqual( |
| | | self._callFUT(self.__class__), |
| | | 'class pyramid.tests.test_util.Test_object_description') |
| | | 'class tests.test_util.Test_object_description') |
| | | |
| | | def test_function(self): |
| | | self.assertEqual( |
| | | self._callFUT(dummyfunc), |
| | | 'function pyramid.tests.test_util.dummyfunc') |
| | | 'function tests.test_util.dummyfunc') |
| | | |
| | | def test_instance(self): |
| | | inst = Dummy() |
File was renamed from pyramid/tests/test_view.py |
| | |
| | | self.assertEqual(settings[0]['custom_predicates'], (1,)) |
| | | |
| | | def test_call_with_renderer_string(self): |
| | | import pyramid.tests |
| | | import tests |
| | | decorator = self._makeOne(renderer='fixtures/minimal.pt') |
| | | venusian = DummyVenusian() |
| | | decorator.venusian = venusian |
| | |
| | | self.assertEqual(len(settings), 1) |
| | | renderer = settings[0]['renderer'] |
| | | self.assertEqual(renderer, 'fixtures/minimal.pt') |
| | | self.assertEqual(config.pkg, pyramid.tests) |
| | | self.assertEqual(config.pkg, tests) |
| | | |
| | | def test_call_with_renderer_dict(self): |
| | | import pyramid.tests |
| | | import tests |
| | | decorator = self._makeOne(renderer={'a':1}) |
| | | venusian = DummyVenusian() |
| | | decorator.venusian = venusian |
| | |
| | | settings = config.settings |
| | | self.assertEqual(len(settings), 1) |
| | | self.assertEqual(settings[0]['renderer'], {'a':1}) |
| | | self.assertEqual(config.pkg, pyramid.tests) |
| | | self.assertEqual(config.pkg, tests) |
| | | |
| | | def test_call_with_renderer_IRendererInfo(self): |
| | | import pyramid.tests |
| | | import tests |
| | | from pyramid.interfaces import IRendererInfo |
| | | @implementer(IRendererInfo) |
| | | class DummyRendererHelper(object): |
| | |
| | | self.assertEqual(len(settings), 1) |
| | | renderer = settings[0]['renderer'] |
| | | self.assertTrue(renderer is renderer_helper) |
| | | self.assertEqual(config.pkg, pyramid.tests) |
| | | self.assertEqual(config.pkg, tests) |
| | | |
| | | def test_call_withdepth(self): |
| | | decorator = self._makeOne(_depth=1) |
| | |
| | | |
| | | class DummyVenusianInfo(object): |
| | | scope = 'notaclass' |
| | | module = sys.modules['pyramid.tests'] |
| | | module = sys.modules['tests'] |
| | | codeinfo = 'codeinfo' |
| | | |
| | | class DummyVenusian(object): |
File was renamed from pyramid/tests/test_viewderivers.py |
| | |
| | | self.assertEqual( |
| | | e.args[0], |
| | | 'Could not convert return value of the view callable function ' |
| | | 'pyramid.tests.test_viewderivers.view into a response ' |
| | | 'tests.test_viewderivers.view into a response ' |
| | | 'object. The value returned was None. You may have forgotten ' |
| | | 'to return a value from the view callable.' |
| | | ) |
| | |
| | | self.assertEqual( |
| | | e.args[0], |
| | | "Could not convert return value of the view callable function " |
| | | "pyramid.tests.test_viewderivers.view into a response " |
| | | "tests.test_viewderivers.view into a response " |
| | | "object. The value returned was {'a': 1}. You may have " |
| | | "forgotten to define a renderer in the view configuration." |
| | | ) |
| | |
| | | msg = e.args[0] |
| | | self.assertTrue(msg.startswith( |
| | | 'Could not convert return value of the view callable object ' |
| | | '<pyramid.tests.test_viewderivers.')) |
| | | '<tests.test_viewderivers.')) |
| | | self.assertTrue(msg.endswith( |
| | | '> into a response object. The value returned was None. You ' |
| | | 'may have forgotten to return a value from the view callable.')) |
| | |
| | | e.args[0], |
| | | 'Could not convert return value of the view callable ' |
| | | 'method __call__ of ' |
| | | 'class pyramid.tests.test_viewderivers.AView into a ' |
| | | 'class tests.test_viewderivers.AView into a ' |
| | | 'response object. The value returned was None. You may have ' |
| | | 'forgotten to return a value from the view callable.' |
| | | ) |
| | |
| | | e.args[0], |
| | | 'Could not convert return value of the view callable ' |
| | | 'method theviewmethod of ' |
| | | 'class pyramid.tests.test_viewderivers.AView into a ' |
| | | 'class tests.test_viewderivers.AView into a ' |
| | | 'response object. The value returned was None. You may have ' |
| | | 'forgotten to return a value from the view callable.' |
| | | ) |
| | |
| | | deps = virtualenv |
| | | |
| | | [testenv:lint] |
| | | skip_install = True |
| | | skip_install = true |
| | | basepython = python3.5 |
| | | commands = |
| | | flake8 pyramid/ |
| | |
| | | # combination of versions of coverage and nosexcover that i can find. |
| | | [testenv:py2-cover] |
| | | commands = |
| | | coverage run --source=pyramid {envbindir}/nosetests |
| | | coverage run {envbindir}/nosetests |
| | | coverage xml -o coverage-py2.xml |
| | | setenv = |
| | | COVERAGE_FILE=.coverage.py2 |
| | |
| | | |
| | | [testenv:py3-cover] |
| | | commands = |
| | | coverage run --source=pyramid {envbindir}/nosetests |
| | | coverage run {envbindir}/nosetests |
| | | coverage xml -o coverage-py3.xml |
| | | setenv = |
| | | COVERAGE_FILE=.coverage.py3 |
| | |
| | | testing |
| | | |
| | | [testenv:coverage] |
| | | skip_install = True |
| | | skip_install = true |
| | | basepython = python3.5 |
| | | commands = |
| | | coverage erase |
| | | coverage combine |
| | | coverage xml |
| | | coverage report --show-missing --fail-under=100 |
| | | coverage report --fail-under=100 |
| | | deps = |
| | | coverage |
| | | setenv = |
| | | COVERAGE_FILE=.coverage |
| | | |
| | | [testenv:build] |
| | | skip_install = true |
| | | basepython = python3.6 |
| | | commands = |
| | | # clean up build/ and dist/ folders |
| | | python -c 'import shutil; shutil.rmtree("dist", ignore_errors=True)' |
| | | python setup.py clean --all |
| | | # build sdist |
| | | python setup.py sdist --dist-dir {toxinidir}/dist |
| | | # build wheel from sdist |
| | | pip wheel -v --no-deps --no-index --wheel-dir {toxinidir}/dist --find-links {toxinidir}/dist pyramid |
| | | |
| | | deps = |
| | | setuptools |
| | | wheel |