summaryrefslogtreecommitdiff
path: root/docs/quick_tutorial
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2021-01-15 13:31:48 -0600
committerGitHub <noreply@github.com>2021-01-15 13:31:48 -0600
commit074f4f3eeec94b133293c0d1d0fa81d681b08e37 (patch)
tree2c0b41982a2298592a180887a924b67fa16d65e0 /docs/quick_tutorial
parent837358ee6be552fd2f990d1ed8d6ea9e1c98d583 (diff)
parentb0dd658429367dd5e3cd99973bcc9a6763dcc5e7 (diff)
downloadpyramid-074f4f3eeec94b133293c0d1d0fa81d681b08e37.tar.gz
pyramid-074f4f3eeec94b133293c0d1d0fa81d681b08e37.tar.bz2
pyramid-074f4f3eeec94b133293c0d1d0fa81d681b08e37.zip
Merge pull request #3648 from Pylons/prep-2.0-docs
More 2.0 docs prep
Diffstat (limited to 'docs/quick_tutorial')
-rw-r--r--docs/quick_tutorial/cookiecutters/.gitignore3
-rw-r--r--docs/quick_tutorial/cookiecutters/README.txt7
-rw-r--r--docs/quick_tutorial/cookiecutters/pytest.ini2
-rw-r--r--docs/quick_tutorial/cookiecutters/tests/conftest.py76
-rw-r--r--docs/quick_tutorial/cookiecutters/tests/test_functional.py7
-rw-r--r--docs/quick_tutorial/cookiecutters/tests/test_it.py39
-rw-r--r--docs/quick_tutorial/cookiecutters/tests/test_views.py13
7 files changed, 103 insertions, 44 deletions
diff --git a/docs/quick_tutorial/cookiecutters/.gitignore b/docs/quick_tutorial/cookiecutters/.gitignore
index 1853d983c..e9336274d 100644
--- a/docs/quick_tutorial/cookiecutters/.gitignore
+++ b/docs/quick_tutorial/cookiecutters/.gitignore
@@ -11,7 +11,7 @@ dist/
nosetests.xml
env*/
tmp/
-Data.fs*
+Data*.fs*
*.sublime-project
*.sublime-workspace
.*.sw?
@@ -19,3 +19,4 @@ Data.fs*
.DS_Store
coverage
test
+*.sqlite
diff --git a/docs/quick_tutorial/cookiecutters/README.txt b/docs/quick_tutorial/cookiecutters/README.txt
index 55c5dcec6..74a86520c 100644
--- a/docs/quick_tutorial/cookiecutters/README.txt
+++ b/docs/quick_tutorial/cookiecutters/README.txt
@@ -4,15 +4,16 @@ cc_starter
Getting Started
---------------
-- Change directory into your newly created project.
+- Change directory into your newly created project if not already there. Your
+ current directory should be the same as this README.txt file and setup.py.
cd cc_starter
-- Create a Python virtual environment.
+- Create a Python virtual environment, if not already created.
python3 -m venv env
-- Upgrade packaging tools.
+- Upgrade packaging tools, if necessary.
env/bin/pip install --upgrade pip setuptools
diff --git a/docs/quick_tutorial/cookiecutters/pytest.ini b/docs/quick_tutorial/cookiecutters/pytest.ini
index 515cc3cf0..b678eef00 100644
--- a/docs/quick_tutorial/cookiecutters/pytest.ini
+++ b/docs/quick_tutorial/cookiecutters/pytest.ini
@@ -1,5 +1,5 @@
[pytest]
-addopts = --strict
+addopts = --strict-markers
testpaths =
cc_starter
diff --git a/docs/quick_tutorial/cookiecutters/tests/conftest.py b/docs/quick_tutorial/cookiecutters/tests/conftest.py
new file mode 100644
index 000000000..ec09cdb2d
--- /dev/null
+++ b/docs/quick_tutorial/cookiecutters/tests/conftest.py
@@ -0,0 +1,76 @@
+import os
+from pyramid.paster import get_appsettings
+from pyramid.scripting import prepare
+from pyramid.testing import DummyRequest, testConfig
+import pytest
+import webtest
+
+from myproject import main
+
+
+def pytest_addoption(parser):
+ parser.addoption('--ini', action='store', metavar='INI_FILE')
+
+@pytest.fixture(scope='session')
+def ini_file(request):
+ # potentially grab this path from a pytest option
+ return os.path.abspath(request.config.option.ini or 'testing.ini')
+
+@pytest.fixture(scope='session')
+def app_settings(ini_file):
+ return get_appsettings(ini_file)
+
+@pytest.fixture(scope='session')
+def app(app_settings):
+ return main({}, **app_settings)
+
+@pytest.fixture
+def testapp(app):
+ testapp = webtest.TestApp(app, extra_environ={
+ 'HTTP_HOST': 'example.com',
+ })
+
+ return testapp
+
+@pytest.fixture
+def app_request(app):
+ """
+ A real request.
+
+ This request is almost identical to a real request but it has some
+ drawbacks in tests as it's harder to mock data and is heavier.
+
+ """
+ with prepare(registry=app.registry) as env:
+ request = env['request']
+ request.host = 'example.com'
+ yield request
+
+@pytest.fixture
+def dummy_request():
+ """
+ A lightweight dummy request.
+
+ This request is ultra-lightweight and should be used only when the request
+ itself is not a large focus in the call-stack. It is much easier to mock
+ and control side-effects using this object, however:
+
+ - It does not have request extensions applied.
+ - Threadlocals are not properly pushed.
+
+ """
+ request = DummyRequest()
+ request.host = 'example.com'
+
+ return request
+
+@pytest.fixture
+def dummy_config(dummy_request):
+ """
+ A dummy :class:`pyramid.config.Configurator` object. This allows for
+ mock configuration, including configuration for ``dummy_request``, as well
+ as pushing the appropriate threadlocals.
+
+ """
+ with testConfig(request=dummy_request) as config:
+ yield config
diff --git a/docs/quick_tutorial/cookiecutters/tests/test_functional.py b/docs/quick_tutorial/cookiecutters/tests/test_functional.py
new file mode 100644
index 000000000..bac5d63f4
--- /dev/null
+++ b/docs/quick_tutorial/cookiecutters/tests/test_functional.py
@@ -0,0 +1,7 @@
+def test_root(testapp):
+ res = testapp.get('/', status=200)
+ assert b'Pyramid' in res.body
+
+def test_notfound(testapp):
+ res = testapp.get('/badurl', status=404)
+ assert res.status_code == 404
diff --git a/docs/quick_tutorial/cookiecutters/tests/test_it.py b/docs/quick_tutorial/cookiecutters/tests/test_it.py
deleted file mode 100644
index 634abfdf2..000000000
--- a/docs/quick_tutorial/cookiecutters/tests/test_it.py
+++ /dev/null
@@ -1,39 +0,0 @@
-import unittest
-
-from pyramid import testing
-
-
-class ViewTests(unittest.TestCase):
- def setUp(self):
- self.config = testing.setUp()
-
- def tearDown(self):
- testing.tearDown()
-
- def test_my_view(self):
- from cc_starter.views.default import my_view
- request = testing.DummyRequest()
- info = my_view(request)
- self.assertEqual(info['project'], 'cc_starter')
-
- def test_notfound_view(self):
- from cc_starter.views.notfound import notfound_view
- request = testing.DummyRequest()
- info = notfound_view(request)
- self.assertEqual(info, {})
-
-
-class FunctionalTests(unittest.TestCase):
- def setUp(self):
- from cc_starter import main
- app = main({})
- from webtest import TestApp
- self.testapp = TestApp(app)
-
- def test_root(self):
- res = self.testapp.get('/', status=200)
- self.assertTrue(b'Pyramid' in res.body)
-
- def test_notfound(self):
- res = self.testapp.get('/badurl', status=404)
- self.assertTrue(res.status_code == 404)
diff --git a/docs/quick_tutorial/cookiecutters/tests/test_views.py b/docs/quick_tutorial/cookiecutters/tests/test_views.py
new file mode 100644
index 000000000..1fd9db8ab
--- /dev/null
+++ b/docs/quick_tutorial/cookiecutters/tests/test_views.py
@@ -0,0 +1,13 @@
+from myproject.views.default import my_view
+from myproject.views.notfound import notfound_view
+
+
+def test_my_view(app_request):
+ info = my_view(app_request)
+ assert app_request.response.status_int == 200
+ assert info['project'] == 'myproject'
+
+def test_notfound_view(app_request):
+ info = notfound_view(app_request)
+ assert app_request.response.status_int == 404
+ assert info == {}