On 30/11/2011 16:10, Benedict Verheyen wrote:
<snip>

Hi,


I managed to create the standalone application, that's the good news.
I have some questions on testing the app below.

I ended up making a virtualenv for the application. Afterwards, I copied the 
relevant files
(templates, view, urls, static) to this directory.
I still need to add docs, complete test suites, manifest.In and other text 
files.
But what I have now works.

To test it, I made a new project, copied the application directory to the 
projects src
and installed it from there with "python setup.py develop".

application directory
├── bin
│   ├── activate
│   ├── ...
├── include
│   └── ...
├── lib
│   └── python2.7
├── src
│   ├── django
├── manage.py
├── setup.py
└── mycompany_language
    ├── __init__.py
    ├── settings.py
    ├── static
    │   └── mycompany_language
    ├── templates
    │   └── mycompany_language
    ├── tests
    │   ├── __init__.py
    │   ├── runtests.py
    │   ├── testsettings.py
    │   ├── tests.py
    ├── urls.py
    └── views
        ├── __init__.py
        ├── views_language.py


What I spent most time on, was figuring out how I could run the tests to
test the application. "python manage.py test" doesn't work if I use
the "normal" settings.py as it only contains a few constants.
The error is: there is no database defined in there.
I use the settings file to specify LANGUAGES, DEFAULT_LANGUAGE and LANGUAGE_CODE
and nothing more.

After looking at some other apps, I figured out that I could use a second
settings file specific to testing (testsettings.py).
If I specify this testsettings file in the "python manage.py test" command,
the command "python manage.py test 
--settings=mycompany_language.tests.testsettings" works.
However, running a specific test fails:

$ python manage.py test --settings=mycompany_language.tests.testsettings 
mycompany_language.SetLanguageTest
>>> "App with label company_language is missing a models.py module."

Indeed, in this example, I don't have models.py file and providing an empty one 
seemed weird.
Besides, the settings file doesn't have a proper INSTALLED_APPS stance.
Anyway, I then tried to run the tests from the tests directory without manage.py


In tests.py, I have this at the top
=================================================
import os, sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'testsettings'
from django.conf import settings
...
=================================================

testsettings.py
=================================================
APP_PATH=os.path.abspath(os.path.join(os.path.dirname(__file__),".."))
PROJECT_PATH=os.path.abspath(os.path.join(APP_PATH,".."))
sys.path += [APP_PATH, PROJECT_PATH]
# Import main settings
from mycompany_language.settings import *
...
=================================================

I could then run the tests from the test directory with "python tests.py"
This complained about not finding the module company_language.tests
    ImportError: No module named company_language.tests

This is why i added these 3 lines to testsettings.py

APP_PATH=os.path.abspath(os.path.join(os.path.dirname(__file__),".."))
PROJECT_PATH=os.path.abspath(os.path.join(APP_PATH,".."))
sys.path += [APP_PATH, PROJECT_PATH]

And then running the tests finally worked.

I do have some questions:
1. Is there a problem with running application tests not via "python manage.py 
test"?
If the latter is preferable, I suppose I do have to specify the APP in there.
I would like to avoid putting too much in the settings file as I just meant to 
use it
for some application specific settings.

2. Is it ok to specify application specific constants in the settings file?
In my test project, I then access them like this:
    from mycompany_language.settings import *

For the doc, I will look into Sphinx.

Regards,
Benedict


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