Changeset 458 for elixir/trunk/tests/test_m2m.py
- Timestamp:
- 09/17/09 13:54:19 (4 years ago)
- Files:
-
- 1 modified
-
elixir/trunk/tests/test_m2m.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
elixir/trunk/tests/test_m2m.py
r451 r458 4 4 5 5 from elixir import * 6 import elixir 6 7 7 8 #----------- … … 24 25 25 26 setup_all(True) 26 27 A.mapper.compile() 28 29 # check m2m table was generated correctly 30 m2m_table = A.bs_.property.secondary 31 assert m2m_table.name in metadata.tables 32 33 # check column names 34 m2m_cols = m2m_table.columns 35 assert 'bs__id' in m2m_cols 36 assert 'as__id' in m2m_cols 37 38 # check the relationships work as expected 27 39 b1 = B(name='b1', as_=[A(name='a1')]) 28 40 … … 36 48 assert b in a.bs_ 37 49 38 def test_column_format(self): 50 def test_custom_global_column_nameformat(self): 51 # this needs to be done before declaring the classes 52 elixir.options.M2MCOL_NAMEFORMAT = elixir.options.OLD_M2MCOL_NAMEFORMAT 53 54 class A(Entity): 55 bs_ = ManyToMany('B') 56 57 class B(Entity): 58 as_ = ManyToMany('A') 59 60 setup_all(True) 61 62 # revert to original format 63 elixir.options.M2MCOL_NAMEFORMAT = elixir.options.NEW_M2MCOL_NAMEFORMAT 64 65 # check m2m table was generated correctly 66 A.mapper.compile() 67 m2m_table = A.bs_.property.secondary 68 assert m2m_table.name in metadata.tables 69 70 # check column names 71 m2m_cols = m2m_table.columns 72 assert '%s_id' % A.table.name in m2m_cols 73 assert '%s_id' % B.table.name in m2m_cols 74 75 def test_alternate_column_formatter(self): 76 # this needs to be done before declaring the classes 77 elixir.options.M2MCOL_NAMEFORMAT = \ 78 elixir.relationships.alternate_m2m_column_formatter 79 80 class A(Entity): 81 as_ = ManyToMany('A') 82 bs_ = ManyToMany('B') 83 84 class B(Entity): 85 as_ = ManyToMany('A') 86 87 setup_all(True) 88 A.mapper.compile() 89 90 # revert to original format 91 elixir.options.M2MCOL_NAMEFORMAT = elixir.options.NEW_M2MCOL_NAMEFORMAT 92 93 # check m2m table column names were generated correctly 94 m2m_cols = A.bs_.property.secondary.columns 95 assert '%s_id' % A.table.name in m2m_cols 96 assert '%s_id' % B.table.name in m2m_cols 97 98 # check selfref m2m table column names were generated correctly 99 m2m_cols = A.as_.property.secondary.columns 100 assert 'as__id' in m2m_cols 101 assert 'inverse_id' in m2m_cols 102 103 def test_manual_column_format(self): 39 104 class A(Entity): 40 105 using_options(tablename='aye') … … 49 114 setup_all(True) 50 115 51 b1 = B(name='b1', as_=[A(name='a1')]) 52 53 session.commit() 54 session.clear() 55 56 a = A.query.one() 57 b = B.query.one() 58 59 assert a in b.as_ 60 assert b in a.bs_ 61 116 # check column names were generated correctly 117 A.mapper.compile() 62 118 m2m_cols = A.bs_.property.secondary.columns 63 119 assert 'a_id' in m2m_cols 64 120 assert 'b_id' in m2m_cols 65 121 122 # check the relationships work as expected 123 b1 = B(name='b1', as_=[A(name='a1')]) 124 125 session.commit() 126 session.clear() 127 128 a = A.query.one() 129 b = B.query.one() 130 131 assert a in b.as_ 132 assert b in a.bs_ 133 66 134 def test_multi_pk_in_target(self): 67 135 class A(Entity): … … 137 205 assert barney in homer.friends 138 206 207 m2m_cols = Person.friends.property.secondary.columns 208 assert 'friends_id' in m2m_cols 209 assert 'inverse_id' in m2m_cols 210 139 211 def test_bidirectional_selfref(self): 140 212 class Person(Entity): … … 159 231 assert homer in barney.friends 160 232 assert barney in homer.friends 233 234 m2m_cols = Person.friends.property.secondary.columns 235 assert 'friends_id' in m2m_cols 236 assert 'is_friend_of_id' in m2m_cols 161 237 162 238 def test_has_and_belongs_to_many(self):
