Hi I've got the same problem.

Here's what I'd like to do: I'm trying to create a generic
"time_series" app, which has models which are inherited by other apps
but are not functional by themselves. I would like to create test
models in tests.py, and then run unittests on them.

from django.test import TestCase
from django.db import models
from time_series.models import *
import datetime

class TestDatePoint(DatePointCanonical):
    """ Testing datepoint class """
    data = models.IntegerField()
    name = models.CharField(max_length=50)

    def __unicode__(self):
        return '%d %s' % (self.data, self.date)

class TestTimeSeries(TimeSeries):
    """ Testing Time Series Class """
    time_series = models.ForeignKey(TestDatePoint, null=True,
            related_name='time_series')

class InheritanceTest(TestCase):
    def setUp(self):
        self.ts = TestTimeSeries.objects.create()
        self.a = self.ts.add(
                data=5, name="first", date=datetime.date.today())
        print 'success'

    def testFirst(self):
        self.assertEqual(self.ts.first, self.a)

    def testCanonical(self):
        self.assertEqual(self.ts.canonical, self.a)

running ./manage.py test time_series give me this:
<snip>
EE..
======================================================================
ERROR: testCanonical (time_series.tests.InheritanceTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/griff/code/geonet/time_series/tests.py", line 43, in
setUp
    self.ts = TestTimeSeries.objects.create()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/manager.py", line 125, in
create
    return self.get_query_set().create(**kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/query.py", line 308, in
create
    obj.save(force_insert=True)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/base.py", line 419, in
save
    self.save_base(force_insert=force_insert,
force_update=force_update)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/base.py", line 504, in
save_base
    result = manager._insert(values, return_id=update_pk)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/manager.py", line 179, in
_insert
    return insert_query(self.model, values, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/query.py", line 1087, in
insert_query
    return query.execute_sql(return_id)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/sql/subqueries.py", line
320, in execute_sql
    cursor = super(InsertQuery, self).execute_sql(None)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/sql/query.py", line 2373,
in execute_sql
    cursor.execute(sql, params)
ProgrammingError: relation "time_series_testtimeseries" does not exist
LINE 1: INSERT INTO
"time_series_testtimeseries" ("time_series_id") ...
                    ^


======================================================================
ERROR: testFirst (time_series.tests.InheritanceTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/griff/code/geonet/time_series/tests.py", line 43, in
setUp
    self.ts = TestTimeSeries.objects.create()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/manager.py", line 125, in
create
    return self.get_query_set().create(**kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/query.py", line 308, in
create
    obj.save(force_insert=True)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/base.py", line 419, in
save
    self.save_base(force_insert=force_insert,
force_update=force_update)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/base.py", line 504, in
save_base
    result = manager._insert(values, return_id=update_pk)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/manager.py", line 179, in
_insert
    return insert_query(self.model, values, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/query.py", line 1087, in
insert_query
    return query.execute_sql(return_id)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/sql/subqueries.py", line
320, in execute_sql
    cursor = super(InsertQuery, self).execute_sql(None)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/django/db/models/sql/query.py", line 2373,
in execute_sql
    cursor.execute(sql, params)
ProgrammingError: relation "time_series_testtimeseries" does not exist
LINE 1: INSERT INTO
"time_series_testtimeseries" ("time_series_id") ...
                    ^


----------------------------------------------------------------------
Ran 4 tests in 0.042s

FAILED (errors=2)
Destroying test database...


LINE 1: INSERT INTO
"time_series_testtimeseries" ("time_series_id") ...

I'm guessing the issue is: running syncdb after the models are
defined. I tried connection.creation.create_test_db() but I still get
the same problem.

I just did some digging and I have a modest proposal:

django-tagging i think has the best practice here: where tagging.tests
is its own app with a models file and settings file that modifies the
global settings for tests and adds tagging.tests as an app.

what if a .tests app could be treated as such, with .tests.tests.py
autoexecuted and .tests.models auto-syncdb'ed?

sorry for the long post,

-griff

On Dec 4, 1:06 pm, "Mark (Nosrednakram)" <nosrednak...@gmail.com>
wrote:
> I thinks I may have figured out what seems to be a good way.  I create
> themodelsin the top of the test.py file.  This is working and the
> table are only there for testing so I'm no polluting my database with
> these tables after thetestsare finished.  Still looking for feedback
> on best practice though.
>
> Thanks Again,
> Mark
>
> On Dec 4, 5:37 am, "Mark (Nosrednakram)" <nosrednak...@gmail.com>
> wrote:
>
> > Hello Django Users,
>
> > I have a few applications that don't have definedmodelsbut that
> > interact with othermodels.  The most recent is a full text search
> > engine based on Whoosh.  Whoosh has it own back end for storing
> > indexes.  The application indexesmodelsbut doesn't have any of it's
> > ownmodelsdefined.  What is the best way to create a test I have the
> > following ideas:
>
> >   * Create testmodelsif settings.py has DEBUG=True but not sure how
> > to remove table when DEBUG !=True
> >   * Create  a testing application that has seeded data andmodelsfor
> > this type of situation
> >   * Create tables from within the test script
>
> > Is there a standard way to do this I haven't found?  If not any
> > suggestions on the ideas?  Thoughts on above? Other examples are
> > online table exporter, chat.
>
> > Thank you,
> > Mark

--

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


Reply via email to