MCPcopy
hub / github.com/django/django / test_get_relations

Method test_get_relations

tests/introspection/tests.py:219–246  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

217
218 @skipUnlessDBFeature("can_introspect_foreign_keys")
219 def test_get_relations(self):
220 with connection.cursor() as cursor:
221 relations = connection.introspection.get_relations(
222 cursor, Article._meta.db_table
223 )
224
225 if connection.vendor == "mysql" and connection.mysql_is_mariadb:
226 no_db_on_delete = None
227 else:
228 no_db_on_delete = DO_NOTHING
229 # {field_name: (field_name_other_table, other_table, db_on_delete)}
230 expected_relations = {
231 "reporter_id": ("id", Reporter._meta.db_table, no_db_on_delete),
232 "response_to_id": ("id", Article._meta.db_table, no_db_on_delete),
233 }
234 self.assertEqual(relations, expected_relations)
235
236 # Removing a field shouldn't disturb get_relations (#17785)
237 body = Article._meta.get_field("body")
238 with connection.schema_editor() as editor:
239 editor.remove_field(Article, body)
240 with connection.cursor() as cursor:
241 relations = connection.introspection.get_relations(
242 cursor, Article._meta.db_table
243 )
244 with connection.schema_editor() as editor:
245 editor.add_field(Article, body)
246 self.assertEqual(relations, expected_relations)
247
248 @skipUnlessDBFeature("can_introspect_foreign_keys", "supports_on_delete_db_cascade")
249 def test_get_relations_db_on_delete_cascade(self):

Callers

nothing calls this directly

Calls 6

cursorMethod · 0.80
schema_editorMethod · 0.80
get_relationsMethod · 0.45
get_fieldMethod · 0.45
remove_fieldMethod · 0.45
add_fieldMethod · 0.45

Tested by

no test coverage detected