1

How do you find what Django name's a form within its context, so that you can assert tests on the form?

I have a simple unittest like:

def test_stuff(self):

    client = Client()
    response = client.post('/admin/app/model/add', {'name': 'Some Name'}
    self.assertFormError(response, 'what is this?!?!?', 'name', 'This name already exists')

Django's unittest framework provides methods to specifically test form fields...but they all require a form name. However, when testing admin views, these are auto-generated, so I don't know them, much less can I hard-code them inside a unittest.

How do I find this name? Attempting to print response.context shows an enormous amount of data, so I'm not sure where to start.

4

1 回答 1

0

查看源代码,我认为该表单在上下文中可用adminform.

于 2015-04-16T20:46:02.230 回答