First of all, you do not need selenium to test views. Selenium is a tool for high-level testing in a browser - it is good and useful when you write user interface tests that simulate a real user.
The nose is a tool that makes testing easier by providing features such as automatic test detection, a number of helper functions, etc. The best way to combine the nose with the django project is to use django_nose . All you have to do is:
- add
django_nose to INSTALLED_APPS - define
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
Then, every time you run the python manage.py test <project_name> nose, you will use your tests.
So, speaking of testing this particular kind, you should check:
- login_required decorator operation - in other words, an unauthorized user will be redirected to the login page
- if
request.method not POST, messages are not sent + are redirected to /reports/messages - sending SMS messages using the POST method + redirecting to
/reports/messages
Testing the first two statements is pretty straight forward, but to verify the last statement you need to provide more detailed information about what Batch , ProcessRequests and how it works. I mean that you probably don't want to send real SMS messages during testing - this will help mocking . Basically, you need to make fun of (replace with your own on-the-fly implementation) Batch , ProcessRequests objects. Here is an example of what you should have in test_views.py :
from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.test.client import Client from django.test import TestCase class ProcessAllTestCase(TestCase): def setUp(self): self.client = Client() self.user = User.objects.create_user('john', ' lennon@thebeatles.com ', 'johnpassword') def test_login_required(self): response = self.client.get(reverse('process_all')) self.assertRedirects(response, '/login') def test_get_method(self): self.client.login(username='john', password='johnpassword') response = self.client.get(reverse('process_all')) self.assertRedirects(response, '/reports/messages')
See also:
Hope this helps.
alecxe
source share