Ok, with the help of
http://www.petersblog.org/node/1051
I was able to setup a decent debug sesion + unit testing setup
I do this:
#Clase sobre la cual basar los test...
import unittest
import sys
import os
SETTINGS_MODULE = 'settings'
project_dir = os.path.abspath('../')
sys.path.append(os.path.join(project_dir, '..'))
sys.path.append("..")
sys.path.pop()
os.environ['DJANGO_SETTINGS_MODULE'] = 'jhonWeb.settings'
from django.conf import settings
from django.core import management
from django import db
from django.contrib.auth.management import create_superuser
from django.contrib.auth import models as auth_app
from django.db.models import signals
from django.db import connection
from django.dispatch import dispatcher
from jhonWeb.core.models import Country,City,State,Settings
from jhonWeb.blogs.models import Blog
from jhonWeb.links.models import Link
from jhonWeb.multimedia.models import *
from jhonWeb.restaurant.models import Restaurant
from jhonWeb.core.install import InstallJhonWeb
class BaseTestJhonWeb(unittest.TestCase):
def _testSetup(self):
pass
def setUp(self):
# Change Settings
settings.DATABASE_NAME = ':memory:'
settings.DATABASE_ENGINE = 'sqlite3'
# Reload DB module
#reload(db)
# Install Models
cursor = connection.cursor()
self._set_autocommit(connection)
# disable the "create a super user" question
dispatcher.disconnect(create_superuser, sender=auth_app,
signal=signals.post_syncdb)
management.syncdb()
self._testSetup()
def testBasic(self):
self.testData()
self.assertEqual(4,Blog.objects.count())
def _set_autocommit(self, connection):
"""
Make sure a connection is in autocommit mode.
"""
if hasattr(connection.connection, "autocommit"):
connection.connection.autocommit(True)
elif hasattr(connection.connection, "set_isolation_level"):
connection.connection.set_isolation_level(0)
And simply inherit from this:
class BaseTestWithTestData(BaseTestJhonWeb):
def _testSetup(self):
InstallJhonWeb(crearDatos=False)
def testBasic(self):
self.assertEqual(4,Blog.objects.count())
self.assertEqual(2,Image.objects.count())
#self.assertEqual(1,Link.objects.count())
self.assertEqual(2,Restaurant.objects.count())
Pay attention to this hack:
dispatcher.disconnect(create_superuser, sender=auth_app,
signal=signals.post_syncdb)
is for disable the question for create the superuser.
However, in Komodo I'm getting this:
Traceback (most recent call last):
File "E:\Proyectos\Python\jhonWeb\Test\BaseTest.py", line 49, in
setUp
dispatcher.disconnect(create_superuser, sender=auth_app,
signal=signals.post_syncdb)
File
"d:\programacion\otros\python24\lib\site-packages\django\django\dispatch\dispatcher.py",
line 217, in disconnect
raise errors.DispatcherKeyError(
DispatcherKeyError: "No receivers found for signal <object object at
0x009CC488> from sender <module 'django.contrib.auth.models' from
'd:\\programacion\\otros\\python24\\lib\\site-packages\\django\\django\\contrib\\auth\\models.pyc'>"
And this is for each test.... I don't know what to do here... look like
everything else is working fine...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" 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/django-users
-~----------~----~----~----~------~----~------~--~---