| 1 |
--- Testing.txt 2008-04-16 18:20:17.000000000 -0700 |
|---|
| 2 |
+++ Testing-rev.txt 2008-04-28 20:40:59.000000000 -0700 |
|---|
| 3 |
@@ -200,9 +200,12 @@ |
|---|
| 4 |
probably need a separate database for testing. To make this simpler, TurboGears |
|---|
| 5 |
provides the ``testutil.DBTest`` class. |
|---|
| 6 |
|
|---|
| 7 |
-If you inherit from this class, TG will create and drop all the tables in your |
|---|
| 8 |
-model for each method. In the example below, ``test_model_reset()`` is working |
|---|
| 9 |
-on a completely empty database despite coming after ``test_name()``. |
|---|
| 10 |
+If you inherit from this class, and you are using |
|---|
| 11 |
+`SQLObject <1.0/SQLObject>`_, TG will provide ``setUp()`` and ``tearDown()`` |
|---|
| 12 |
+methods that create and drop all the tables in your model for each method. |
|---|
| 13 |
+In the example below, ``test_model_reset()`` is working on a completely empty |
|---|
| 14 |
+database despite coming after ``test_name()``, thanks to the ``setUp()`` and |
|---|
| 15 |
+``tearDown()`` methods inherited from ``testutil.DBTest``. |
|---|
| 16 |
|
|---|
| 17 |
:: |
|---|
| 18 |
|
|---|
| 19 |
@@ -227,6 +230,38 @@ |
|---|
| 20 |
assert len(entry) is 0 |
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
+If you want to define your own ``setUp()`` and/or ``tearDown()`` make |
|---|
| 24 |
+sure that you call those methods from the parent class or you'll get |
|---|
| 25 |
+``OperationalError: no such table: ...`` exceptions. |
|---|
| 26 |
+ |
|---|
| 27 |
+:: |
|---|
| 28 |
+ |
|---|
| 29 |
+ from turbogears import testutil |
|---|
| 30 |
+ from projectname import model |
|---|
| 31 |
+ |
|---|
| 32 |
+ class TestMyURL(testutil.DBTest): |
|---|
| 33 |
+ model = model |
|---|
| 34 |
+ |
|---|
| 35 |
+ def setUp(self): |
|---|
| 36 |
+ """Pre-test setup. |
|---|
| 37 |
+ |
|---|
| 38 |
+ Use the parent class setUp() method to create database tables, |
|---|
| 39 |
+ then ... |
|---|
| 40 |
+ """ |
|---|
| 41 |
+ super(TestMyURL, self).setUp() |
|---|
| 42 |
+ # Additional set-up code |
|---|
| 43 |
+ |
|---|
| 44 |
+ |
|---|
| 45 |
+ def tearDown(self): |
|---|
| 46 |
+ """Post-test tear-down. |
|---|
| 47 |
+ |
|---|
| 48 |
+ Use parent class tearDown() method to reset database |
|---|
| 49 |
+ before next test. |
|---|
| 50 |
+ """ |
|---|
| 51 |
+ super(TestMyURL, self).tearDown() |
|---|
| 52 |
+ # Additional tear-down code |
|---|
| 53 |
+ |
|---|
| 54 |
+ |
|---|
| 55 |
Other Functionality |
|---|
| 56 |
~~~~~~~~~~~~~~~~~~~ |
|---|
| 57 |
|
|---|