diff options
| author | Steve Piercy <web@stevepiercy.com> | 2020-01-01 21:21:25 -0800 |
|---|---|---|
| committer | Steve Piercy <web@stevepiercy.com> | 2020-01-02 23:30:59 -0800 |
| commit | bd42bcaee1176ee5bb0cc7bf311e8e91070eea88 (patch) | |
| tree | 0c54746e90ac84c014806de6217439893a1c2b1d /docs/tutorials/wiki2/src/authentication/tests | |
| parent | 6175ff659c2523974072b404636911ebb89c2d42 (diff) | |
| download | pyramid-bd42bcaee1176ee5bb0cc7bf311e8e91070eea88.tar.gz pyramid-bd42bcaee1176ee5bb0cc7bf311e8e91070eea88.tar.bz2 pyramid-bd42bcaee1176ee5bb0cc7bf311e8e91070eea88.zip | |
Resync wiki2/*.rst and related files after moving tests directory
Diffstat (limited to 'docs/tutorials/wiki2/src/authentication/tests')
| -rw-r--r-- | docs/tutorials/wiki2/src/authentication/tests/__init__.py | 0 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/src/authentication/tests/test_it.py | 66 |
2 files changed, 66 insertions, 0 deletions
diff --git a/docs/tutorials/wiki2/src/authentication/tests/__init__.py b/docs/tutorials/wiki2/src/authentication/tests/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/docs/tutorials/wiki2/src/authentication/tests/__init__.py diff --git a/docs/tutorials/wiki2/src/authentication/tests/test_it.py b/docs/tutorials/wiki2/src/authentication/tests/test_it.py new file mode 100644 index 000000000..ea16534fc --- /dev/null +++ b/docs/tutorials/wiki2/src/authentication/tests/test_it.py @@ -0,0 +1,66 @@ +import unittest + +from pyramid import testing + +import transaction + + +def dummy_request(dbsession): + return testing.DummyRequest(dbsession=dbsession) + + +class BaseTest(unittest.TestCase): + def setUp(self): + self.config = testing.setUp(settings={ + 'sqlalchemy.url': 'sqlite:///:memory:' + }) + self.config.include('tutorial.models') + settings = self.config.get_settings() + + from tutorial.models import ( + get_engine, + get_session_factory, + get_tm_session, + ) + + self.engine = get_engine(settings) + session_factory = get_session_factory(self.engine) + + self.session = get_tm_session(session_factory, transaction.manager) + + def init_database(self): + from tutorial.models.meta import Base + Base.metadata.create_all(self.engine) + + def tearDown(self): + from tutorial.models.meta import Base + + testing.tearDown() + transaction.abort() + Base.metadata.drop_all(self.engine) + + +class TestMyViewSuccessCondition(BaseTest): + + def setUp(self): + super(TestMyViewSuccessCondition, self).setUp() + self.init_database() + + from tutorial.models import MyModel + + model = MyModel(name='one', value=55) + self.session.add(model) + + def test_passing_view(self): + from tutorial.views.default import my_view + info = my_view(dummy_request(self.session)) + self.assertEqual(info['one'].name, 'one') + self.assertEqual(info['project'], 'myproj') + + +class TestMyViewFailureCondition(BaseTest): + + def test_failing_view(self): + from tutorial.views.default import my_view + info = my_view(dummy_request(self.session)) + self.assertEqual(info.status_int, 500) |
