2

my problem is that. this is a old django project that I need to work on it.

As unknown reason, the project don't use django model. Instead, it define some class to CRUD the database by pure sql. and the project has no tests at all.

now, I want to add unittest for the project(views/models/and so on).but I wonder if this test can use fixture without model define?

I don't have so much time to test this by my hand. So is there any one knows about this?

hackrole
  • 121
  • 8
  • There's no way for us to know if the custom class can handle loading fixtures. You'll have to write unit tests for the custom ORM first, and then write them for the app – ptr Mar 14 '14 at 10:11
  • there's no custom ORM at all. only a DBConnect class with method like query/execute(accept a sql, return a connect cursor). – hackrole Mar 14 '14 at 10:47
  • 1
    That's the custom ORM, basically. If they're not using django models (and subsequently the `objects` model manager) then they must have some logic to convert form data (or whatever) into database records. – ptr Mar 14 '14 at 12:56

1 Answers1

0

The answer to your top question is yes, you should be able to use the Django test framework pieces that don't depend on models.

The answer to your inner question about using fixtures (which sounds like it may be the real question) is, not without writing some additional test code. Django uses fixtures to populate Django models, and you don't have any Django models.

So, write your tests using django.utils.unittest and deal with the fixture loading there.

Paul Bissex
  • 1,611
  • 1
  • 17
  • 22
  • so I can't use the django fixture. Instead, I need to load the data by my self in the TestCase. But what I wonder is django use a databaseproxy while test run, so if there is no modeles, how it get the message about the tables. – hackrole Mar 17 '14 at 06:02
  • it seems ok. Even though I have to write the data_load method in the testcase. Thank you all very much. – hackrole Mar 17 '14 at 09:06