Objects created on another database don't leak onto the default database
(self)
| 62 | Book.objects.using("other").get(title="Dive into Python") |
| 63 | |
| 64 | def test_other_creation(self): |
| 65 | """ |
| 66 | Objects created on another database don't leak onto the default |
| 67 | database |
| 68 | """ |
| 69 | # Create a book on the second database |
| 70 | Book.objects.using("other").create( |
| 71 | title="Pro Django", published=datetime.date(2008, 12, 16) |
| 72 | ) |
| 73 | |
| 74 | # Create a book on the default database using a save |
| 75 | dive = Book() |
| 76 | dive.title = "Dive into Python" |
| 77 | dive.published = datetime.date(2009, 5, 4) |
| 78 | dive.save(using="other") |
| 79 | |
| 80 | # Book exists on the default database, but not on other database |
| 81 | try: |
| 82 | Book.objects.using("other").get(title="Pro Django") |
| 83 | except Book.DoesNotExist: |
| 84 | self.fail('"Pro Django" should exist on other database') |
| 85 | |
| 86 | with self.assertRaises(Book.DoesNotExist): |
| 87 | Book.objects.get(title="Pro Django") |
| 88 | with self.assertRaises(Book.DoesNotExist): |
| 89 | Book.objects.using("default").get(title="Pro Django") |
| 90 | |
| 91 | try: |
| 92 | Book.objects.using("other").get(title="Dive into Python") |
| 93 | except Book.DoesNotExist: |
| 94 | self.fail('"Dive into Python" should exist on other database') |
| 95 | |
| 96 | with self.assertRaises(Book.DoesNotExist): |
| 97 | Book.objects.get(title="Dive into Python") |
| 98 | with self.assertRaises(Book.DoesNotExist): |
| 99 | Book.objects.using("default").get(title="Dive into Python") |
| 100 | |
| 101 | def test_refresh(self): |
| 102 | dive = Book(title="Dive into Python", published=datetime.date(2009, 5, 4)) |