MCPcopy
hub / github.com/django/django / test_default_creation

Method test_default_creation

tests/multiple_database/tests.py:32–62  ·  view source on GitHub ↗

Objects created on the default database don't leak onto other databases

(self)

Source from the content-addressed store, hash-verified

30 self.assertEqual(Book.objects.db_manager("other").all().db, "other")
31
32 def test_default_creation(self):
33 """
34 Objects created on the default database don't leak onto other databases
35 """
36 # Create a book on the default database using create()
37 Book.objects.create(title="Pro Django", published=datetime.date(2008, 12, 16))
38
39 # Create a book on the default database using a save
40 dive = Book()
41 dive.title = "Dive into Python"
42 dive.published = datetime.date(2009, 5, 4)
43 dive.save()
44
45 # Book exists on the default database, but not on other database
46 try:
47 Book.objects.get(title="Pro Django")
48 Book.objects.using("default").get(title="Pro Django")
49 except Book.DoesNotExist:
50 self.fail('"Pro Django" should exist on default database')
51
52 with self.assertRaises(Book.DoesNotExist):
53 Book.objects.using("other").get(title="Pro Django")
54
55 try:
56 Book.objects.get(title="Dive into Python")
57 Book.objects.using("default").get(title="Dive into Python")
58 except Book.DoesNotExist:
59 self.fail('"Dive into Python" should exist on default database')
60
61 with self.assertRaises(Book.DoesNotExist):
62 Book.objects.using("other").get(title="Dive into Python")
63
64 def test_other_creation(self):
65 """

Callers

nothing calls this directly

Calls 5

BookClass · 0.70
createMethod · 0.45
saveMethod · 0.45
getMethod · 0.45
usingMethod · 0.45

Tested by

no test coverage detected