summaryrefslogtreecommitdiff
path: root/tests/foreign_object
diff options
context:
space:
mode:
authorSaJH <wogur981208@gmail.com>2025-09-15 19:55:20 -0400
committerJacob Walls <jacobtylerwalls@gmail.com>2025-09-16 10:25:16 -0400
commit308f674e6d0a89653b5071a2b0cfbf5747b33c89 (patch)
treec30d0c04327f495cee8e0e2e733cd4d7c51fcdc7 /tests/foreign_object
parent82b3b84a78055844ee07d5d97843a4fc72872e28 (diff)
Refs #36580 -- Added coverage for excluding ForeignObject from constraint validation.
Diffstat (limited to 'tests/foreign_object')
-rw-r--r--tests/foreign_object/models/__init__.py3
-rw-r--r--tests/foreign_object/models/customers.py19
-rw-r--r--tests/foreign_object/tests.py8
3 files changed, 29 insertions, 1 deletions
diff --git a/tests/foreign_object/models/__init__.py b/tests/foreign_object/models/__init__.py
index 69778d3ddd..d2ddc68646 100644
--- a/tests/foreign_object/models/__init__.py
+++ b/tests/foreign_object/models/__init__.py
@@ -1,5 +1,5 @@
from .article import Article, ArticleIdea, ArticleTag, ArticleTranslation, NewsArticle
-from .customers import Address, Contact, Customer
+from .customers import Address, Contact, Customer, CustomerTab
from .empty_join import SlugPage
from .person import Country, Friendship, Group, Membership, Person
@@ -12,6 +12,7 @@ __all__ = [
"Contact",
"Country",
"Customer",
+ "CustomerTab",
"Friendship",
"Group",
"Membership",
diff --git a/tests/foreign_object/models/customers.py b/tests/foreign_object/models/customers.py
index 91ac091524..085b7272e9 100644
--- a/tests/foreign_object/models/customers.py
+++ b/tests/foreign_object/models/customers.py
@@ -39,3 +39,22 @@ class Contact(models.Model):
to_fields=["customer_id", "company"],
from_fields=["customer_code", "company_code"],
)
+
+
+class CustomerTab(models.Model):
+ customer_id = models.IntegerField()
+ customer = models.ForeignObject(
+ Customer,
+ from_fields=["customer_id"],
+ to_fields=["id"],
+ on_delete=models.CASCADE,
+ )
+
+ class Meta:
+ required_db_features = {"supports_table_check_constraints"}
+ constraints = [
+ models.CheckConstraint(
+ condition=models.Q(customer__lt=1000),
+ name="customer_id_limit",
+ ),
+ ]
diff --git a/tests/foreign_object/tests.py b/tests/foreign_object/tests.py
index b4072d500d..436d9583c4 100644
--- a/tests/foreign_object/tests.py
+++ b/tests/foreign_object/tests.py
@@ -15,6 +15,7 @@ from .models import (
ArticleTag,
ArticleTranslation,
Country,
+ CustomerTab,
Friendship,
Group,
Membership,
@@ -767,3 +768,10 @@ class TestCachedPathInfo(TestCase):
foreign_object_restored = pickle.loads(pickle.dumps(foreign_object))
self.assertIn("path_infos", foreign_object_restored.__dict__)
self.assertIn("reverse_path_infos", foreign_object_restored.__dict__)
+
+
+class ForeignObjectModelValidationTests(TestCase):
+ @skipUnlessDBFeature("supports_table_check_constraints")
+ def test_validate_constraints_excluding_foreign_object(self):
+ customer_tab = CustomerTab(customer_id=150)
+ customer_tab.validate_constraints(exclude={"customer"})