I am in the process of working up my unit tests for an app set to
release pretty soon, the issue I am having is with getting the unit
tests for my views to run properly.
The issue is that in each view I have a login check for a custom login
function (we could not use the django auth system unfortunately),
every time I try to GET or POST to the view in my unit test I get
redirected to the login view.
The login check checks that the info passed in the request matches
that in a session variable that is set on login.
So what i need to do is set the session variable and pass a
participant_id in my request, which I think I am doing. However it is
not getting past the check...
Code is posted below:
this is the login check:
def getLoggedParticipant(request):
if 'participant_id' not in request.session:
return
try:
return
Participant.objects.get(pk=request.session['participant_id'])
except Participant.DoesNotExist:
return
I pass the participant id here:
class test_Views_TestCase(TestCase):
''' test the views return the correct items '''
fixtures = ['initial_data.json']
def setUp(self):
setup_test_environment()
cleanDB()
self.client = Client()
def test_broadcast_overview(self):
response = self.client.get('/broadcasts/new/' )
# Check that the respose is 302 Redirect OK
self.failUnlessEqual(response.status_code, 302)
def test_broadcast_overview_with_user(self):
participant = Participant.objects.get(nickname = 'twheeler')
''' Get the participant'''
self.client.session['participant_id']=
participant.participant_id
''' Set session '''
response = self.client.get('/broadcasts/new/',
{'loggedParticipant': participant} )
self.assertEqual(self.client.session['participant_id'],1)
self.assertEqual(response.status_code, 302)
redirects ok but to the wrong page
''' This piece I added to get an idea of what was happening
'''
print self.client.session - returns {participant_id', 1}
print response returns the auth/login view which is the
issue,
print participant
I cannot get past the login check in the view... which is this
def broadcast_overview(request):
''' shows list of links to add new broadcasts when the broadcaster
has not yet created any, or shows the current broadcasters list'''
loggedParticipant = getLoggedParticipant(request)
if not loggedParticipant or not
loggedParticipant.isBroadcaster():
'''isBroadcaster() is a method in my model - check to see if the
participant is in a specific program'''
return HttpResponseRedirect('/auth/login')
any thoughts would be a great help....
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---