On Sun, Oct 19, 2008 at 4:00 AM, Ian J Cottee <[EMAIL PROTECTED]> wrote:
>
> Given a backend of postgres and a simple test to test that, for
> example, your model does not accept fields with more characters than
> it should ... how do you do it?
>
> I have a part database which has two fields - code and description. e.g.
>
>    class Part(models.Model):
>        code = models.CharField(max_length=15)
>        description = models.CharField(max_length=50)
>
> I want to make sure that a code field can't have more than 15 chars.
> Even if I just greedily swallow the exception::
>
>    def testPartCodeBad(self):
>        """Reject our bad code"""
>        part = Part()
>        part.code = '1234567890123456'
>        part.description = 'AAAAAA'
>
>        try:
>            part.save()
>        except:
>            pass
>
> I still end up with
>
>    Destroying old test database...
>    Creating test database...
>    Creating table auth_permission
>    Creating table auth_group
>    Creating table auth_user
>    Creating table auth_message
>    Creating table django_content_type
>    Creating table django_session
>    Creating table django_site
>    Creating table django_admin_log
>    Creating table stock_part
>    Installing index for auth.Permission model
>    Installing index for auth.Message model
>    Installing index for admin.LogEntry model
>    .Error: Database test_taiko couldn't be flushed. Possible reasons:
>          * The database isn't running or isn't configured correctly.
>          * At least one of the expected database tables doesn't exist.
>          * The SQL was invalid.
>        Hint: Look at the output of 'django-admin.py sqlflush'. That's
> the SQL this command wasn't able to run.
>        The full error: current transaction is aborted, commands
> ignored until end of transaction block
>
> What it actually means is, you stuck 16 chars where only 15 chars were 
> allowed.
>
> Is this testable?

As far as I can make out, the error you are getting is unrelated to
the problem you are describing. Your error is telling you that you
can't flush the database. If you're getting that error, Django hasn't
started to run the test yet, so the issue isn't with your test code.
If your test case contained nothing but "self.assertEquals(1,1)", you
would get the same error. The problem lies with the test database
itself.

It's difficult to say exactly what the problem is without seeing your
database setup. However, the error that is being raised is caused by
the fact that Django can't flush the test database. The most likely
cause I can think of is a permissions problem - your test user doesn't
have permission to run DELETE TABLE on the test database.

To debug this problem, follow the instructions you have been given in
the error message: run ./manage.py sqlflush, and try to execute that
SQL manually on using the test database. This should reveal the
underlying problem.

Yours,
Russ Magee %-)

--~--~---------~--~----~------------~-------~--~----~
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