Hello Kumar,

Thanks for example. This works great except except I had to change to
using a file database rather than in memory (it kept complaining of an
OperationalError: no such table: ...)

Thanks for the great library too, it will save us lots of time and
make our tests much easier to understand.

Regards, Andrew.



On Jun 19, 10:05 pm, "Kumar McMillan" <[EMAIL PROTECTED]>
wrote:
> On 6/14/07, Andrew <[EMAIL PROTECTED]> wrote:
>
> > I've since come across the Fixture library (http://code.google.com/p/
> > fixture/) which solves the problem of creating and loadingfixtures
> > and I am trying to see if I can use this from within Turbogears. Has
> > any one had any experience of using this?
>
> Yes you *should* be able to use fixture from within TurboGears.  But
> you'll have to take this with a grain of salt since 1) I'm not very
> familiar with TurboGears and 2) I haven't tested this code.  I took an
> example from the docs and wrote some code using the fixture module to
> accomplish more or less the same thing.  Let me know if you have
> questions or if it doesn't work ;)
>
> """example using fixture to accomplish the equivalent of the Turbo
> Gears example
> from Testing Your Model -http://docs.turbogears.org/1.0/Testing
>
> """
>
> from turbogears import testutil
> from projectname import model
> from fixture import DataSet, SQLObjectFixture
>
> from turbogears import database
> database.set_db_uri("sqlite:///:memory:")
>
> # this loads a row of data just like the docs do with test_name()
> class MyUrlData(DataSet):
>     class tg_url:
>         name="TurboGears"
>         link="http://www.turbogears.com";
>         description="cool python web framework"
>
> # this creates a fixture object, which is sort of like importing a
> python module :
> db_fixture = SQLObjectFixture(
>     # this says to load the MyUrlData rows using the sqlobject named MyURL :
>     env={'MyUrlData': MyUrl},
>     # the dsn from above (note that this works because SO pools connections) :
>     dsn="sqlite:///:memory:")
>
> class TestMyURL(testutil.DBTest):
>     model = model
>
>     def setUp(self):
>         super(TestMyURL, self).setUp()
>         self.data = db_fixture.data(MyUrlData)
>         self.data.setup()
>
>     def tearDown(self):
>         super(TestMyURL, self).tearDown()
>         self.data.teardown()
>
>     def test_name(self):
>         entry = model.MyUrl.select()[0]
>         assert entry.name==self.data.tg_url.name # i.e. TurboGears
>
>     def test_model_reset(self):
>         # this might fail?  I'm not sure what was resets the model
>         entry = list(model.MyUrl.select())
>         assert len(entry) is 0


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to