> personnaly I use request.addfinalizer to rollback the transaction : > > https://github.com/CroissanceCommune/autonomie/ > blob/master/autonomie/tests/conftest.py#L300 > > This does work in full weight functional testing, as you need to run a web server in a separate thread from unit test main thread. Transactions are not shared between threads, so you need to commit transactions to the database in order to Selenium or other test client to see them.
Instead, the cycle is * Do database set up * Commit transactions * Connect to the test web server using a browser * Manipulate web page * Read data back from the database * Check that database matches expected values * Drop database at the end of the test (or more usual, at the beginning of the next test) Cheers, Mikko > Hope this help > > Regards > > -- > > Gaston Tjebbes > > http://majerti.fr > > > Le 24/01/2017 à 20:52, Jaime Sangcap a écrit : > > Hi everyone! Im trying to learn python and getting my hands dirty with > > pyramid. > > > > I would really appreciate it if there is anyone willing to give me a > > kickstart on how to do functional test? > > Lets say I posted a data to a url and I want to test that the data has > > been saved to the persistent store or fake store. > > How should I do it? > > > > I have this test class: > > > > class TestCatalogView: > > def test_it_loads_catalog_add_page(self, testapp): > > testapp.get('/catalog/add', status=200) > > > > def test_it_adds_the_course_on_the_catalog(self, testapp): > > response = testapp.post('/catalog/add', status='30*') > > assert 'Course has been added' in response.body > > # here I want to assert that the data has been persisted > > > > the testapp is a fixture with the following details: > > > > @fixture(scope='session') > > def pyramid_test_setup(): > > yield testing.setUp() > > testing.tearDown() > > > > > > @fixture(scope='session') > > def testapp(pyramid_test_setup): > > from tgpweb import main > > from pyramid.paster import get_appsettings > > settings = get_appsettings('testing.ini', 'main') > > app = main(global_config=None, **settings) > > return webtest.TestApp(app) > > > > > > What are the things needed to test this? Im thinking of making a > > Repository Class which uses SqlAlchemy, and another one as Fake > > repository so that in case I dont want to hit a real database I can > > swap the implementation > > > > > > If Im doing it wrong please guide me on how to make it right. maybe I > > have the wrong mindset in testing. > > > > > > Thank you in advance! > > > > -- > > You received this message because you are subscribed to the Google > > Groups "pylons-discuss" group. > > To unsubscribe from this group and stop receiving emails from it, send > > an email to [email protected] > > <mailto:[email protected]>. > > To post to this group, send email to [email protected] > > <mailto:[email protected]>. > > To view this discussion on the web visit > > https://groups.google.com/d/msgid/pylons-discuss/db009b1b- > 51c2-493a-809a-2582c6e85d9a%40googlegroups.com > > <https://groups.google.com/d/msgid/pylons-discuss/db009b1b- > 51c2-493a-809a-2582c6e85d9a%40googlegroups.com?utm_medium= > email&utm_source=footer>. > > For more options, visit https://groups.google.com/d/optout. > > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/pylons-discuss/e43d7678-0e26-082c-ab6f-a9445f223027%40gmail.com. > For more options, visit https://groups.google.com/d/optout. > -- Mikko Ohtamaa http://opensourcehacker.com http://twitter.com/moo9000 -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/CAK8RCUtK1YRfzM5SfKoPwrOXNR%3DgbCaSFMkjH-3O248RsPP03g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
