Make sure `get_or_create` works with complex where clauses.
(self)
| 130 | self.assertEqual(instance.popularity, 100) |
| 131 | |
| 132 | def test_complex_where_clause(self): |
| 133 | """ |
| 134 | Make sure `get_or_create` works with complex where clauses. |
| 135 | """ |
| 136 | self.insert_rows() |
| 137 | |
| 138 | # When the row already exists in the db: |
| 139 | instance = ( |
| 140 | Band.objects() |
| 141 | .get_or_create( |
| 142 | (Band.name == "Pythonistas") & (Band.popularity == 1000) |
| 143 | ) |
| 144 | .run_sync() |
| 145 | ) |
| 146 | self.assertIsInstance(instance, Band) |
| 147 | self.assertEqual(instance._was_created, False) |
| 148 | |
| 149 | # When the row doesn't exist in the db: |
| 150 | instance = ( |
| 151 | Band.objects() |
| 152 | .get_or_create( |
| 153 | (Band.name == "Pythonistas2") & (Band.popularity == 2000) |
| 154 | ) |
| 155 | .run_sync() |
| 156 | ) |
| 157 | self.assertIsInstance(instance, Band) |
| 158 | self.assertEqual(instance._was_created, True) |
| 159 | |
| 160 | def test_very_complex_where_clause(self): |
| 161 | """ |
nothing calls this directly
no test coverage detected