I'm using Django 1.8 and Python 3.5.
I have a view method I would love to test. I am supplying the self.client.get
method with the data but it fails to validate the form. what am I doing wrong?
This is the view method:
def saveNewDriverInfo(request):
if request.user.is_authenticated():
form = DriverForm(request.POST)
if form.is_valid():
new_Driver = form.save()
carid = form.cleaned_data['carID']
Car = get_object_or_404(Car, pk=carid)
return redirect('carmanager:carDetails', carID=carid
else:
return HttpResponse("something went wong some where! yes i said wong!")
This is the test method:
def test_saveNewDriverInfo(self):
self.client.login(username="testuser",password="testuser321")
response= self.client.get(reverse('carmanager:saveNewDriverInfo'),data={'form':{'carID':'1034567','Driver_Last_Name':'daddy','Driver_First_Name':'daddy','Driver_Middle_Initial':'K','entered_by':'king'}})
#self.assertRedirects(response, expected_url, status_code, target_status_code, host, msg_prefix, fetch_redirect_response)
self.assertNotContains(response, 'something went wrong' ,200)
Also, note that this test works because it gets the response. But the line that is commented out is what I want to use.
However, I cant seem to feed the information to the DriverForm. Any help will be greatly appreciated.