Le repo des sources pour le site web des JM2L
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

tests.py 883 B

9 yıl önce
1234567891011121314151617181920212223242526272829303132
  1. import unittest
  2. import transaction
  3. from pyramid import testing
  4. from .models import DBSession
  5. class TestMyView(unittest.TestCase):
  6. def setUp(self):
  7. self.config = testing.setUp()
  8. from sqlalchemy import create_engine
  9. engine = create_engine('sqlite://')
  10. from .models import (
  11. Base,
  12. MyModel,
  13. )
  14. DBSession.configure(bind=engine)
  15. Base.metadata.create_all(engine)
  16. with transaction.manager:
  17. model = MyModel(name='one', value=55)
  18. DBSession.add(model)
  19. def tearDown(self):
  20. DBSession.remove()
  21. testing.tearDown()
  22. def test_it(self):
  23. from .views import my_view
  24. request = testing.DummyRequest()
  25. info = my_view(request)
  26. self.assertEqual(info['one'].name, 'one')
  27. self.assertEqual(info['project'], 'pyramid_blogr')