Hi,

I have an app which allows users to rate/vote for any kind of object.
Now, to test this app I need to have a fake model contained in a fake
app. Here's the file structure of my app:

myapp/
    tests/
        fakeapp/
            __init__.py
            models.py
        __init__.py
        models.py
        views.py
        urls.py

Here is the testing code (located in myapp/tests/__init__.py):

import sys

from django.test import TestCase
from django.conf import settings
from django.core.management import call_command
from django.db.models.loading import load_app

from fakeapp.models import FakeItem

class TestMyApp(TestCase):

    def setUp(self):
        self.old_INSTALLED_APPS = settings.INSTALLED_APPS
        settings.INSTALLED_APPS = (
            'django.contrib.auth',
            'django.contrib.contenttypes',
            'myapp',
            'myapp.tests.fakeapp',
        )
        load_app('myapp.tests.fakeapp')
        call_command('syncdb', verbosity=0, interactive=False) #
Create tables for fakeapp

    def tearDown(self):
        settings.INSTALLED_APPS = self.old_INSTALLED_APPS

    def test_blah(self):
        item = FakeItem.objects.create(name="blah")
        #Do some testing here...

So, all this works pretty well. The 'fakeapp' app is loaded
dynamically, tables are created and the FakeItem model can be use in
my tests.

But it feels dirty. The dynamically created tables can potentially
clash with some other applications (what if someone calls their app
'fakeapp'?). To make it safer maybe I could give a random name to that
app (e.g. 'uytwe876435gjhgdfs0908').

Is there a cleaner way to do this? In a similar app (django-voting
[1]) there is a dedicated test suite, but I'd like to avoid that if
possible.

Thanks a lot for your advice.

Regards,

Julien

[1] http://code.google.com/p/django-voting/source/browse/#svn/trunk/voting/tests

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

Reply via email to