test_schema.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. # -*- coding: utf-8 -*-
  2. from odoo.models import MetaModel
  3. from odoo.tests import common
  4. from odoo.addons.base.models.ir_model import model_xmlid, field_xmlid, selection_xmlid
  5. def get_model_name(cls):
  6. name = cls._name
  7. if not name:
  8. [name] = cls._inherit if isinstance(cls._inherit, list) else [cls._inherit]
  9. assert isinstance(name, str)
  10. return name
  11. class TestReflection(common.TransactionCase):
  12. """ Test the reflection into 'ir.model', 'ir.model.fields', etc. """
  13. def assertModelXID(self, record):
  14. """ Check the XML id of the given 'ir.model' record. """
  15. xid = model_xmlid('test_new_api', record.model)
  16. self.assertEqual(record, self.env.ref(xid))
  17. def assertFieldXID(self, record):
  18. """ Check the XML id of the given 'ir.model.fields' record. """
  19. xid = field_xmlid('test_new_api', record.model, record.name)
  20. self.assertEqual(record, self.env.ref(xid))
  21. def assertSelectionXID(self, record):
  22. """ Check the XML id of the given 'ir.model.fields.selection' record. """
  23. xid = selection_xmlid('test_new_api', record.field_id.model, record.field_id.name, record.value)
  24. self.assertEqual(record, self.env.ref(xid))
  25. def test_models_fields(self):
  26. """ check that all models and fields are reflected as expected. """
  27. # retrieve the models defined in this module, and check them
  28. model_names = {
  29. get_model_name(cls)
  30. for cls in MetaModel.module_to_models['test_new_api']
  31. }
  32. ir_models = self.env['ir.model'].search([('model', 'in', list(model_names))])
  33. self.assertEqual(len(ir_models), len(model_names))
  34. for ir_model in ir_models:
  35. with self.subTest(model=ir_model.model):
  36. model = self.env[ir_model.model]
  37. self.assertModelXID(ir_model)
  38. self.assertEqual(ir_model.name, model._description or False)
  39. self.assertEqual(ir_model.state, 'manual' if model._custom else 'base')
  40. self.assertEqual(ir_model.transient, bool(model._transient))
  41. self.assertItemsEqual(ir_model.mapped('field_id.name'), list(model._fields))
  42. for ir_field in ir_model.field_id:
  43. with self.subTest(field=ir_field.name):
  44. field = model._fields[ir_field.name]
  45. self.assertFieldXID(ir_field)
  46. self.assertEqual(ir_field.model, field.model_name)
  47. self.assertEqual(ir_field.field_description, field.string)
  48. self.assertEqual(ir_field.help, field.help or False)
  49. self.assertEqual(ir_field.ttype, field.type)
  50. self.assertEqual(ir_field.state, 'manual' if field.manual else 'base')
  51. self.assertEqual(ir_field.index, bool(field.index))
  52. self.assertEqual(ir_field.store, bool(field.store))
  53. self.assertEqual(ir_field.copied, bool(field.copy))
  54. self.assertEqual(ir_field.related, field.related or False)
  55. self.assertEqual(ir_field.readonly, bool(field.readonly))
  56. self.assertEqual(ir_field.required, bool(field.required))
  57. self.assertEqual(ir_field.selectable, bool(field.search or field.store))
  58. self.assertEqual(ir_field.translate, bool(field.translate))
  59. if field.relational:
  60. self.assertEqual(ir_field.relation, field.comodel_name)
  61. if field.type == 'one2many' and field.store:
  62. self.assertEqual(ir_field.relation_field, field.inverse_name)
  63. if field.type == 'many2many' and field.store:
  64. self.assertEqual(ir_field.relation_table, field.relation)
  65. self.assertEqual(ir_field.column1, field.column1)
  66. self.assertEqual(ir_field.column2, field.column2)
  67. relation = self.env['ir.model.relation'].search([('name', '=', field.relation)])
  68. self.assertTrue(relation)
  69. self.assertIn(relation.model.model, [field.model_name, field.comodel_name])
  70. if field.type == 'selection':
  71. selection = [(sel.value, sel.name) for sel in ir_field.selection_ids]
  72. if isinstance(field.selection, list):
  73. self.assertEqual(selection, field.selection)
  74. else:
  75. self.assertEqual(selection, [])
  76. for sel in ir_field.selection_ids:
  77. self.assertSelectionXID(sel)
  78. field_description = field.get_description(self.env)
  79. if field.type in ('many2many', 'one2many'):
  80. self.assertFalse(field_description['sortable'])
  81. elif field.store and field.column_type:
  82. self.assertTrue(field_description['sortable'])
  83. class TestSchema(common.TransactionCase):
  84. def get_table_data(self, tablename):
  85. query = ''' SELECT table_catalog, table_schema, table_name, table_type,
  86. user_defined_type_catalog, user_defined_type_schema,
  87. user_defined_type_name, is_insertable_into, is_typed
  88. FROM information_schema.tables
  89. WHERE table_name=%s '''
  90. self.cr.execute(query, [tablename])
  91. return self.cr.dictfetchone()
  92. def get_columns_data(self, tablename):
  93. query = ''' SELECT table_catalog, table_schema, table_name, column_name,
  94. column_default, data_type, is_nullable, is_updatable,
  95. character_maximum_length, numeric_precision,
  96. numeric_precision_radix, numeric_scale,
  97. datetime_precision, udt_catalog, udt_schema, udt_name
  98. FROM information_schema.columns
  99. WHERE table_name=%s '''
  100. self.cr.execute(query, [tablename])
  101. return {row['column_name']: row for row in self.cr.dictfetchall()}
  102. def get_foreign_keys(self, tablename):
  103. query = ''' SELECT a.table_name, a.column_name,
  104. b.table_name, b.column_name, c.delete_rule
  105. FROM information_schema.referential_constraints c,
  106. information_schema.key_column_usage a,
  107. information_schema.constraint_column_usage b
  108. WHERE a.constraint_schema=c.constraint_schema
  109. AND a.constraint_name=c.constraint_name
  110. AND b.constraint_schema=c.constraint_schema
  111. AND b.constraint_name=c.constraint_name
  112. AND a.table_name=%s '''
  113. self.cr.execute(query, [tablename])
  114. return self.cr.fetchall()
  115. def test_00_table(self):
  116. """ check the database schema of a model """
  117. model = self.env['test_new_api.foo']
  118. self.assertEqual(model._table, 'test_new_api_foo')
  119. # retrieve schema data about that table
  120. table_data = self.get_table_data('test_new_api_foo')
  121. self.assertEqual(table_data, {
  122. 'is_insertable_into': u'YES',
  123. 'is_typed': u'NO',
  124. 'table_catalog': self.cr.dbname,
  125. 'table_name': u'test_new_api_foo',
  126. 'table_schema': u'public',
  127. 'table_type': u'BASE TABLE',
  128. 'user_defined_type_catalog': None,
  129. 'user_defined_type_name': None,
  130. 'user_defined_type_schema': None,
  131. })
  132. # retrieve schema data about the table's columns
  133. columns_data = self.get_columns_data('test_new_api_foo')
  134. self.assertEqual(set(columns_data),
  135. {'id', 'create_date', 'create_uid', 'write_date',
  136. 'write_uid', 'name', 'value1', 'value2', 'text'})
  137. # retrieve schema data about the table's foreign keys
  138. foreign_keys = self.get_foreign_keys('test_new_api_foo')
  139. self.assertItemsEqual(foreign_keys, [
  140. ('test_new_api_foo', 'create_uid', 'res_users', 'id', 'SET NULL'),
  141. ('test_new_api_foo', 'write_uid', 'res_users', 'id', 'SET NULL'),
  142. ])
  143. def test_10_boolean(self):
  144. """ check the database representation of a boolean field """
  145. model = self.env['test_new_api.message']
  146. columns_data = self.get_columns_data(model._table)
  147. self.assertEqual(columns_data['important'], {
  148. 'character_maximum_length': None,
  149. 'column_default': None,
  150. 'column_name': u'important',
  151. 'data_type': u'boolean',
  152. 'datetime_precision': None,
  153. 'is_nullable': u'YES',
  154. 'is_updatable': u'YES',
  155. 'numeric_precision': None,
  156. 'numeric_precision_radix': None,
  157. 'numeric_scale': None,
  158. 'table_catalog': self.cr.dbname,
  159. 'table_name': u'test_new_api_message',
  160. 'table_schema': u'public',
  161. 'udt_catalog': self.cr.dbname,
  162. 'udt_name': u'bool',
  163. 'udt_schema': u'pg_catalog',
  164. })
  165. def test_10_integer(self):
  166. """ check the database representation of an integer field """
  167. model = self.env['test_new_api.category']
  168. columns_data = self.get_columns_data(model._table)
  169. self.assertEqual(columns_data['color'], {
  170. 'character_maximum_length': None,
  171. 'column_default': None,
  172. 'column_name': u'color',
  173. 'data_type': u'integer',
  174. 'datetime_precision': None,
  175. 'is_nullable': u'YES',
  176. 'is_updatable': u'YES',
  177. 'numeric_precision': 32,
  178. 'numeric_precision_radix': 2,
  179. 'numeric_scale': 0,
  180. 'table_catalog': self.cr.dbname,
  181. 'table_name': u'test_new_api_category',
  182. 'table_schema': u'public',
  183. 'udt_catalog': self.cr.dbname,
  184. 'udt_name': u'int4',
  185. 'udt_schema': u'pg_catalog',
  186. })
  187. def test_10_float(self):
  188. """ check the database representation of a float field """
  189. model = self.env['test_new_api.mixed']
  190. columns_data = self.get_columns_data(model._table)
  191. self.assertEqual(columns_data['number'], {
  192. 'character_maximum_length': None,
  193. 'column_default': None,
  194. 'column_name': u'number',
  195. 'data_type': u'numeric',
  196. 'datetime_precision': None,
  197. 'is_nullable': u'YES',
  198. 'is_updatable': u'YES',
  199. 'numeric_precision': None,
  200. 'numeric_precision_radix': 10,
  201. 'numeric_scale': None,
  202. 'table_catalog': self.cr.dbname,
  203. 'table_name': u'test_new_api_mixed',
  204. 'table_schema': u'public',
  205. 'udt_catalog': self.cr.dbname,
  206. 'udt_name': u'numeric',
  207. 'udt_schema': u'pg_catalog',
  208. })
  209. def test_10_monetary(self):
  210. """ check the database representation of a monetary field """
  211. model = self.env['test_new_api.mixed']
  212. columns_data = self.get_columns_data(model._table)
  213. self.assertEqual(columns_data['amount'], {
  214. 'character_maximum_length': None,
  215. 'column_default': None,
  216. 'column_name': u'amount',
  217. 'data_type': u'numeric',
  218. 'datetime_precision': None,
  219. 'is_nullable': u'YES',
  220. 'is_updatable': u'YES',
  221. 'numeric_precision': None,
  222. 'numeric_precision_radix': 10,
  223. 'numeric_scale': None,
  224. 'table_catalog': self.cr.dbname,
  225. 'table_name': u'test_new_api_mixed',
  226. 'table_schema': u'public',
  227. 'udt_catalog': self.cr.dbname,
  228. 'udt_name': u'numeric',
  229. 'udt_schema': u'pg_catalog',
  230. })
  231. def test_10_char(self):
  232. """ check the database representation of a char field """
  233. model = self.env['res.country']
  234. self.assertFalse(type(model).code.required)
  235. self.assertEqual(type(model).code.size, 2)
  236. columns_data = self.get_columns_data(model._table)
  237. self.assertEqual(columns_data['code'], {
  238. 'character_maximum_length': 2,
  239. 'column_default': None,
  240. 'column_name': u'code',
  241. 'data_type': u'character varying',
  242. 'datetime_precision': None,
  243. 'is_nullable': u'YES',
  244. 'is_updatable': u'YES',
  245. 'numeric_precision': None,
  246. 'numeric_precision_radix': None,
  247. 'numeric_scale': None,
  248. 'table_catalog': self.cr.dbname,
  249. 'table_name': u'res_country',
  250. 'table_schema': u'public',
  251. 'udt_catalog': self.cr.dbname,
  252. 'udt_name': u'varchar',
  253. 'udt_schema': u'pg_catalog',
  254. })
  255. model = self.env['test_new_api.message']
  256. self.assertFalse(type(model).name.required)
  257. columns_data = self.get_columns_data(model._table)
  258. self.assertEqual(columns_data['name'], {
  259. 'character_maximum_length': None,
  260. 'column_default': None,
  261. 'column_name': u'name',
  262. 'data_type': u'character varying',
  263. 'datetime_precision': None,
  264. 'is_nullable': u'YES',
  265. 'is_updatable': u'YES',
  266. 'numeric_precision': None,
  267. 'numeric_precision_radix': None,
  268. 'numeric_scale': None,
  269. 'table_catalog': self.cr.dbname,
  270. 'table_name': u'test_new_api_message',
  271. 'table_schema': u'public',
  272. 'udt_catalog': self.cr.dbname,
  273. 'udt_name': u'varchar',
  274. 'udt_schema': u'pg_catalog',
  275. })
  276. model = self.env['test_new_api.category']
  277. self.assertTrue(type(model).name.required)
  278. columns_data = self.get_columns_data(model._table)
  279. self.assertEqual(columns_data['name'], {
  280. 'character_maximum_length': None,
  281. 'column_default': None,
  282. 'column_name': u'name',
  283. 'data_type': u'character varying',
  284. 'datetime_precision': None,
  285. 'is_nullable': u'NO',
  286. 'is_updatable': u'YES',
  287. 'numeric_precision': None,
  288. 'numeric_precision_radix': None,
  289. 'numeric_scale': None,
  290. 'table_catalog': self.cr.dbname,
  291. 'table_name': u'test_new_api_category',
  292. 'table_schema': u'public',
  293. 'udt_catalog': self.cr.dbname,
  294. 'udt_name': u'varchar',
  295. 'udt_schema': u'pg_catalog',
  296. })
  297. def test_10_text(self):
  298. """ check the database representation of a text field """
  299. model = self.env['test_new_api.message']
  300. columns_data = self.get_columns_data(model._table)
  301. self.assertEqual(columns_data['body'], {
  302. 'character_maximum_length': None,
  303. 'column_default': None,
  304. 'column_name': u'body',
  305. 'data_type': u'text',
  306. 'datetime_precision': None,
  307. 'is_nullable': u'YES',
  308. 'is_updatable': u'YES',
  309. 'numeric_precision': None,
  310. 'numeric_precision_radix': None,
  311. 'numeric_scale': None,
  312. 'table_catalog': self.cr.dbname,
  313. 'table_name': u'test_new_api_message',
  314. 'table_schema': u'public',
  315. 'udt_catalog': self.cr.dbname,
  316. 'udt_name': u'text',
  317. 'udt_schema': u'pg_catalog',
  318. })
  319. def test_10_html(self):
  320. """ check the database representation of an html field """
  321. model = self.env['test_new_api.mixed']
  322. columns_data = self.get_columns_data(model._table)
  323. self.assertEqual(columns_data['comment1'], {
  324. 'character_maximum_length': None,
  325. 'column_default': None,
  326. 'column_name': u'comment1',
  327. 'data_type': u'text',
  328. 'datetime_precision': None,
  329. 'is_nullable': u'YES',
  330. 'is_updatable': u'YES',
  331. 'numeric_precision': None,
  332. 'numeric_precision_radix': None,
  333. 'numeric_scale': None,
  334. 'table_catalog': self.cr.dbname,
  335. 'table_name': u'test_new_api_mixed',
  336. 'table_schema': u'public',
  337. 'udt_catalog': self.cr.dbname,
  338. 'udt_name': u'text',
  339. 'udt_schema': u'pg_catalog',
  340. })
  341. def test_10_date(self):
  342. """ check the database representation of a date field """
  343. model = self.env['test_new_api.mixed']
  344. columns_data = self.get_columns_data(model._table)
  345. self.assertEqual(columns_data['date'], {
  346. 'character_maximum_length': None,
  347. 'column_default': None,
  348. 'column_name': u'date',
  349. 'data_type': u'date',
  350. 'datetime_precision': 0,
  351. 'is_nullable': u'YES',
  352. 'is_updatable': u'YES',
  353. 'numeric_precision': None,
  354. 'numeric_precision_radix': None,
  355. 'numeric_scale': None,
  356. 'table_catalog': self.cr.dbname,
  357. 'table_name': u'test_new_api_mixed',
  358. 'table_schema': u'public',
  359. 'udt_catalog': self.cr.dbname,
  360. 'udt_name': u'date',
  361. 'udt_schema': u'pg_catalog',
  362. })
  363. def test_10_datetime(self):
  364. """ check the database representation of a datetime field """
  365. model = self.env['ir.property']
  366. columns_data = self.get_columns_data(model._table)
  367. self.assertEqual(columns_data['value_datetime'], {
  368. 'character_maximum_length': None,
  369. 'column_default': None,
  370. 'column_name': u'value_datetime',
  371. 'data_type': u'timestamp without time zone',
  372. 'datetime_precision': 6,
  373. 'is_nullable': u'YES',
  374. 'is_updatable': u'YES',
  375. 'numeric_precision': None,
  376. 'numeric_precision_radix': None,
  377. 'numeric_scale': None,
  378. 'table_catalog': self.cr.dbname,
  379. 'table_name': u'ir_property',
  380. 'table_schema': u'public',
  381. 'udt_catalog': self.cr.dbname,
  382. 'udt_name': u'timestamp',
  383. 'udt_schema': u'pg_catalog',
  384. })
  385. model = self.env['test_new_api.mixed']
  386. columns_data = self.get_columns_data(model._table)
  387. self.assertEqual(columns_data['create_date'], {
  388. 'character_maximum_length': None,
  389. 'column_default': None,
  390. 'column_name': u'create_date',
  391. 'data_type': u'timestamp without time zone',
  392. 'datetime_precision': 6,
  393. 'is_nullable': u'YES',
  394. 'is_updatable': u'YES',
  395. 'numeric_precision': None,
  396. 'numeric_precision_radix': None,
  397. 'numeric_scale': None,
  398. 'table_catalog': self.cr.dbname,
  399. 'table_name': u'test_new_api_mixed',
  400. 'table_schema': u'public',
  401. 'udt_catalog': self.cr.dbname,
  402. 'udt_name': u'timestamp',
  403. 'udt_schema': u'pg_catalog',
  404. })
  405. def test_10_selection(self):
  406. """ check the database representation of a selection field """
  407. model = self.env['test_new_api.mixed']
  408. columns_data = self.get_columns_data(model._table)
  409. self.assertEqual(columns_data['lang'], {
  410. 'character_maximum_length': None,
  411. 'column_default': None,
  412. 'column_name': u'lang',
  413. 'data_type': u'character varying',
  414. 'datetime_precision': None,
  415. 'is_nullable': u'YES',
  416. 'is_updatable': u'YES',
  417. 'numeric_precision': None,
  418. 'numeric_precision_radix': None,
  419. 'numeric_scale': None,
  420. 'table_catalog': self.cr.dbname,
  421. 'table_name': u'test_new_api_mixed',
  422. 'table_schema': u'public',
  423. 'udt_catalog': self.cr.dbname,
  424. 'udt_name': u'varchar',
  425. 'udt_schema': u'pg_catalog',
  426. })
  427. def test_10_reference(self):
  428. """ check the database representation of a reference field """
  429. model = self.env['test_new_api.mixed']
  430. columns_data = self.get_columns_data(model._table)
  431. self.assertEqual(columns_data['reference'], {
  432. 'character_maximum_length': None,
  433. 'column_default': None,
  434. 'column_name': u'reference',
  435. 'data_type': u'character varying',
  436. 'datetime_precision': None,
  437. 'is_nullable': u'YES',
  438. 'is_updatable': u'YES',
  439. 'numeric_precision': None,
  440. 'numeric_precision_radix': None,
  441. 'numeric_scale': None,
  442. 'table_catalog': self.cr.dbname,
  443. 'table_name': u'test_new_api_mixed',
  444. 'table_schema': u'public',
  445. 'udt_catalog': self.cr.dbname,
  446. 'udt_name': u'varchar',
  447. 'udt_schema': u'pg_catalog',
  448. })
  449. def test_10_many2one(self):
  450. """ check the database representation of a many2one field """
  451. model = self.env['test_new_api.mixed']
  452. columns_data = self.get_columns_data(model._table)
  453. self.assertEqual(columns_data['currency_id'], {
  454. 'character_maximum_length': None,
  455. 'column_default': None,
  456. 'column_name': u'currency_id',
  457. 'data_type': u'integer',
  458. 'datetime_precision': None,
  459. 'is_nullable': u'YES',
  460. 'is_updatable': u'YES',
  461. 'numeric_precision': 32,
  462. 'numeric_precision_radix': 2,
  463. 'numeric_scale': 0,
  464. 'table_catalog': self.cr.dbname,
  465. 'table_name': u'test_new_api_mixed',
  466. 'table_schema': u'public',
  467. 'udt_catalog': self.cr.dbname,
  468. 'udt_name': u'int4',
  469. 'udt_schema': u'pg_catalog',
  470. })
  471. foreign_keys = self.get_foreign_keys(model._table)
  472. self.assertIn(
  473. ('test_new_api_mixed', 'currency_id', 'res_currency', 'id', 'SET NULL'),
  474. foreign_keys,
  475. )
  476. def test_10_many2many(self):
  477. """ check the database representation of a many2many field """
  478. model = self.env['test_new_api.discussion']
  479. field = type(model).categories
  480. comodel = self.env[field.comodel_name]
  481. self.assertTrue(field.relation)
  482. self.assertTrue(field.column1)
  483. self.assertTrue(field.column2)
  484. columns_data = self.get_columns_data(model._table)
  485. self.assertNotIn('categories', columns_data)
  486. table_data = self.get_table_data(field.relation)
  487. self.assertEqual(table_data, {
  488. 'is_insertable_into': u'YES',
  489. 'is_typed': u'NO',
  490. 'table_catalog': self.cr.dbname,
  491. 'table_name': u'test_new_api_discussion_category',
  492. 'table_schema': u'public',
  493. 'table_type': u'BASE TABLE',
  494. 'user_defined_type_catalog': None,
  495. 'user_defined_type_name': None,
  496. 'user_defined_type_schema': None,
  497. })
  498. columns_data = self.get_columns_data(field.relation)
  499. self.assertEqual(columns_data, {
  500. field.column1: {
  501. 'character_maximum_length': None,
  502. 'column_default': None,
  503. 'column_name': u'discussion',
  504. 'data_type': u'integer',
  505. 'datetime_precision': None,
  506. 'is_nullable': u'NO',
  507. 'is_updatable': u'YES',
  508. 'numeric_precision': 32,
  509. 'numeric_precision_radix': 2,
  510. 'numeric_scale': 0,
  511. 'table_catalog': self.cr.dbname,
  512. 'table_name': u'test_new_api_discussion_category',
  513. 'table_schema': u'public',
  514. 'udt_catalog': self.cr.dbname,
  515. 'udt_name': u'int4',
  516. 'udt_schema': u'pg_catalog',
  517. },
  518. field.column2: {
  519. 'character_maximum_length': None,
  520. 'column_default': None,
  521. 'column_name': u'category',
  522. 'data_type': u'integer',
  523. 'datetime_precision': None,
  524. 'is_nullable': u'NO',
  525. 'is_updatable': u'YES',
  526. 'numeric_precision': 32,
  527. 'numeric_precision_radix': 2,
  528. 'numeric_scale': 0,
  529. 'table_catalog': self.cr.dbname,
  530. 'table_name': u'test_new_api_discussion_category',
  531. 'table_schema': u'public',
  532. 'udt_catalog': self.cr.dbname,
  533. 'udt_name': u'int4',
  534. 'udt_schema': u'pg_catalog'
  535. },
  536. })
  537. foreign_keys = self.get_foreign_keys(field.relation)
  538. self.assertItemsEqual(foreign_keys, [
  539. (field.relation, field.column1, model._table, 'id', 'CASCADE'),
  540. (field.relation, field.column2, comodel._table, 'id', 'CASCADE'),
  541. ])