I have a view that should be setting an initial value for a form field based on a GET value. I want to test this. I'm currently using Django's test client but I am open to looking at other tools.
Sorry, I did not mention that I am well aware of the assertContains method but I was hoping there was a better way other than searching the HTML for an input
tag and the value
attribute.
Hate to answer my own question (like the 3rd time I've done it) but after mocking around with the test client, I've found a better way:
def test_creating_stop(self):
c = self.client
# Check that name is pre-filled
response = c.get('%s?name=abcd' % reverse('add_new_stop'))
self.assertEqual(response.context['form'].initial['name'], 'abcd')
Does anyone see anything wrong with this? I'll leave it up for a while see what people think.