MCPcopy
hub / github.com/django/django / assertFKExists

Method assertFKExists

tests/migrations/test_base.py:158–171  ·  view source on GitHub ↗
(self, table, columns, to, value=True, using="default")

Source from the content-addressed store, hash-verified

156 )
157
158 def assertFKExists(self, table, columns, to, value=True, using="default"):
159 if not connections[using].features.can_introspect_foreign_keys:
160 return
161 with connections[using].cursor() as cursor:
162 self.assertEqual(
163 value,
164 any(
165 c["foreign_key"] == to
166 for c in connections[using]
167 .introspection.get_constraints(cursor, table)
168 .values()
169 if c["columns"] == list(columns)
170 ),
171 )
172
173 def assertFKNotExists(self, table, columns, to):
174 return self.assertFKExists(table, columns, to, False)

Calls 3

cursorMethod · 0.80
valuesMethod · 0.45
get_constraintsMethod · 0.45

Tested by

no test coverage detected