MCPcopy
hub / github.com/django/django / test_in_bulk_non_unique_meta_constaint

Method test_in_bulk_non_unique_meta_constaint

tests/lookup/tests.py:291–314  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

289
290 @isolate_apps("lookup")
291 def test_in_bulk_non_unique_meta_constaint(self):
292 class Model(models.Model):
293 ean = models.CharField(max_length=100)
294 brand = models.CharField(max_length=100)
295 name = models.CharField(max_length=80)
296
297 class Meta:
298 constraints = [
299 models.UniqueConstraint(
300 fields=["ean"],
301 name="partial_ean_unique",
302 condition=models.Q(is_active=True),
303 ),
304 models.UniqueConstraint(
305 fields=["brand", "name"],
306 name="together_brand_name_unique",
307 ),
308 ]
309
310 msg = "in_bulk()'s field_name must be a unique field but '%s' isn't."
311 for field_name in ["brand", "ean"]:
312 with self.subTest(field_name=field_name):
313 with self.assertRaisesMessage(ValueError, msg % field_name):
314 Model.objects.in_bulk(field_name=field_name)
315
316 def test_in_bulk_sliced_queryset(self):
317 msg = "Cannot use 'limit' or 'offset' with in_bulk()."

Callers

nothing calls this directly

Calls 2

assertRaisesMessageMethod · 0.80
in_bulkMethod · 0.80

Tested by

no test coverage detected