|
1 | 1 | import sys
|
2 | 2 | import unittest
|
3 | 3 | import tarantool
|
| 4 | +import pkg_resources |
| 5 | + |
4 | 6 | from .lib.tarantool_server import TarantoolServer
|
| 7 | +from .lib.skip import skip_or_run_constraints_test |
5 | 8 | from tarantool.error import NotSupportedError
|
6 | 9 |
|
7 | 10 |
|
@@ -102,6 +105,33 @@ def setUpClass(self):
|
102 | 105 | end
|
103 | 106 | """)
|
104 | 107 |
|
| 108 | + if self.srv.admin.tnt_version >= pkg_resources.parse_version('2.10.0'): |
| 109 | + self.srv.admin(""" |
| 110 | + box.schema.create_space( |
| 111 | + 'constr_tester_1', { |
| 112 | + format = { |
| 113 | + { name = 'id', type = 'unsigned' }, |
| 114 | + { name = 'payload', type = 'number' }, |
| 115 | + } |
| 116 | + }) |
| 117 | + box.space.constr_tester_1:create_index('I1', { parts = {'id'} }) |
| 118 | +
|
| 119 | + box.space.constr_tester_1:insert({1, 999}) |
| 120 | +
|
| 121 | + box.schema.create_space( |
| 122 | + 'constr_tester_2', { |
| 123 | + format = { |
| 124 | + { name = 'id', type = 'unsigned' }, |
| 125 | + { name = 'table1_id', type = 'unsigned', |
| 126 | + foreign_key = { fk_video = { space = 'constr_tester_1', field = 'id' } }, |
| 127 | + }, |
| 128 | + { name = 'payload', type = 'number' }, |
| 129 | + } |
| 130 | + }) |
| 131 | + box.space.constr_tester_2:create_index('I1', { parts = {'id'} }) |
| 132 | + box.space.constr_tester_2:create_index('I2', { parts = {'table1_id'} }) |
| 133 | + """) |
| 134 | + |
105 | 135 | def setUp(self):
|
106 | 136 | # prevent a remote tarantool from clean our session
|
107 | 137 | if self.srv.is_started():
|
@@ -541,6 +571,22 @@ def test_08_schema_fetch_disable_via_connection_pool(self):
|
541 | 571 | self._run_test_schema_fetch_disable(self.pool_con_schema_disable,
|
542 | 572 | mode=tarantool.Mode.ANY)
|
543 | 573 |
|
| 574 | + @skip_or_run_constraints_test |
| 575 | + def test_09_foreign_key_info_fetched_to_schema(self): |
| 576 | + self.assertIn('foreign_key', self.sch.get_space('constr_tester_2').format['table1_id']) |
| 577 | + |
| 578 | + @skip_or_run_constraints_test |
| 579 | + def test_10_foreign_key_valid_insert(self): |
| 580 | + self.assertSequenceEqual( |
| 581 | + self.con.insert('constr_tester_2', [1, 1, 623]), |
| 582 | + [[1, 1, 623]]) |
| 583 | + |
| 584 | + @skip_or_run_constraints_test |
| 585 | + def test_11_foreign_key_invalid_insert(self): |
| 586 | + with self.assertRaisesRegex(tarantool.DatabaseError, |
| 587 | + 'foreign tuple was not found'): |
| 588 | + self.con.insert('constr_tester_2', [2, 999, 623]) |
| 589 | + |
544 | 590 | @classmethod
|
545 | 591 | def tearDownClass(self):
|
546 | 592 | self.con.close()
|
|
0 commit comments