Hi,
I'm fairly new to Django and unittest and I seem to be having a
problem getting manage.py to execute all of my tests. I can only get
it to execute one test at a time by specifying the test method. When I
just specify the TestCase class expecting it to execute all of the
test methods, it won't run any of the tests.
In my articles/tests.py file I have the following:
-------------------------------------------------------------------------------------------------------------
# -*- coding: utf-8 -*-
from django.test import TestCase
from django.test.client import Client
from oslaurier.articles.models import Article
class ArticleTestCase(TestCase):
fixtures = ['test_fixture.json']
def setUp(self):
self.client = Client()
def test_index(self):
"""
Test that article index page returns a 200 response
"""
response = self.client.get('/articles/')
self.failUnlessEqual(response.status_code, 200)
def test_index_default_list(self):
"""
Test that index is only displaying non-draft, non-hidden
articles
"""
response = self.client.get('/articles/')
hello_world = Article.objects.get(slug='hello-world')
two_author = Article.objects.get(slug='two-author-article')
multi_author = Article.objects.get(slug='multi-author-
article')
self.assertEqual(list(response.context
['articles'].object_list).sort(),
[multi_author, two_author, hello_world].sort())
class ArticlePaginationTestCase(TestCase):
fixtures = ['pagination.json']
def setUp(self):
self.client = Client()
def default_num_per_page(self):
"""
Test that the default number of articles per page is 10
"""
response = self.client.get('/articles/')
self.assertEqual(len(response.context
['articles'].object_list), 10)
def first_set_has_next(self):
"""
Test that first set of articles has a next set
"""
response = self.client.get('/articles/?num_per_page=10')
self.assertTrue(response.context['articles'].has_next)
-------------------------------------------------------------------------------------------------------------
If I run python manage.py test articles.ArticlePaginationTestCase I
get:
Creating test database...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_flatpage
Creating table django_redirect
Creating table django_session
Creating table django_site
Creating table articles_article
Installing index for admin.LogEntry model
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for flatpages.FlatPage model
Installing index for redirects.Redirect model
Installing index for articles.Article model
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Destroying test database...
I would've expected it to run both test methods under
ArticlesPaginationTestCase.
If I run python manage.py test
articles.ArticlesPaginationTestCase.default_num_per_page I get:
Creating test database...
Creating table django_admin_log
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_flatpage
Creating table django_redirect
Creating table django_session
Creating table django_site
Creating table articles_article
Installing index for admin.LogEntry model
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for flatpages.FlatPage model
Installing index for redirects.Redirect model
Installing index for articles.Article model
.
----------------------------------------------------------------------
Ran 1 test in 0.364s
OK
Destroying test database...
Which is what I would expect.
What am I doing wrong or what is a better way of going about testing
functionality that requires one fixture for one set of tests and
another fixture for another set?
Thank you for any help you can provide.
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---