MCPcopy
hub / github.com/django/django / test_inline

Method test_inline

tests/admin_views/tests.py:5325–5402  ·  view source on GitHub ↗

Inline models which inherit from a common parent are correctly handled.

(self)

Source from the content-addressed store, hash-verified

5323 self.client.force_login(self.superuser)
5324
5325 def test_inline(self):
5326 """
5327 Inline models which inherit from a common parent are correctly handled.
5328 """
5329 foo_user = "foo username"
5330 bar_user = "bar username"
5331
5332 name_re = re.compile(b'name="(.*?)"')
5333
5334 # test the add case
5335 response = self.client.get(reverse("admin:admin_views_persona_add"))
5336 names = name_re.findall(response.content)
5337 names.remove(b"csrfmiddlewaretoken")
5338 # make sure we have no duplicate HTML names
5339 self.assertEqual(len(names), len(set(names)))
5340
5341 # test the add case
5342 post_data = {
5343 "name": "Test Name",
5344 # inline data
5345 "accounts-TOTAL_FORMS": "1",
5346 "accounts-INITIAL_FORMS": "0",
5347 "accounts-MAX_NUM_FORMS": "0",
5348 "accounts-0-username": foo_user,
5349 "accounts-2-TOTAL_FORMS": "1",
5350 "accounts-2-INITIAL_FORMS": "0",
5351 "accounts-2-MAX_NUM_FORMS": "0",
5352 "accounts-2-0-username": bar_user,
5353 }
5354
5355 response = self.client.post(reverse("admin:admin_views_persona_add"), post_data)
5356 self.assertEqual(response.status_code, 302) # redirect somewhere
5357 self.assertEqual(Persona.objects.count(), 1)
5358 self.assertEqual(FooAccount.objects.count(), 1)
5359 self.assertEqual(BarAccount.objects.count(), 1)
5360 self.assertEqual(FooAccount.objects.all()[0].username, foo_user)
5361 self.assertEqual(BarAccount.objects.all()[0].username, bar_user)
5362 self.assertEqual(Persona.objects.all()[0].accounts.count(), 2)
5363
5364 persona_id = Persona.objects.all()[0].id
5365 foo_id = FooAccount.objects.all()[0].id
5366 bar_id = BarAccount.objects.all()[0].id
5367
5368 # test the edit case
5369
5370 response = self.client.get(
5371 reverse("admin:admin_views_persona_change", args=(persona_id,))
5372 )
5373 names = name_re.findall(response.content)
5374 names.remove(b"csrfmiddlewaretoken")
5375 # make sure we have no duplicate HTML names
5376 self.assertEqual(len(names), len(set(names)))
5377
5378 post_data = {
5379 "name": "Test Name",
5380 "accounts-TOTAL_FORMS": "2",
5381 "accounts-INITIAL_FORMS": "1",
5382 "accounts-MAX_NUM_FORMS": "0",

Callers

nothing calls this directly

Calls 7

reverseFunction · 0.90
compileMethod · 0.45
getMethod · 0.45
removeMethod · 0.45
postMethod · 0.45
countMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected