Show
Ignore:
Timestamp:
09/30/09 20:25:04 (4 years ago)
Author:
ged
Message:

- added test for migration after M2M column format change through local_colname
- tablename, remote_colname, local_colname, schema and table_kwargs can now be

defined on either side of a ManyToMany relationship and will propagate to
the other side if that other side doesn't specify anything for that argument.
Also added an assertion to catch the case where the same/mirror
argument is specified on both sides but with different values.

- refactored slightly the code for the table rename migration_aid so that it is

more readable.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/tests/test_m2m.py

    r478 r481  
    139139        assert 'inverse_id' in m2m_cols 
    140140 
    141     def test_upgrade(self): 
     141    def test_upgrade_rename_col(self): 
    142142        elixir.options.M2MCOL_NAMEFORMAT = elixir.options.OLD_M2MCOL_NAMEFORMAT 
    143143 
     
    212212        assert a2.is_linked_from == [a1] 
    213213 
     214    def test_upgrade_local_colname(self): 
     215        elixir.options.M2MCOL_NAMEFORMAT = elixir.options.OLD_M2MCOL_NAMEFORMAT 
     216 
     217        class A(Entity): 
     218            using_options(shortnames=True) 
     219            name = Field(String(20)) 
     220            links_to = ManyToMany('A') 
     221            is_linked_from = ManyToMany('A') 
     222            bs_ = ManyToMany('B') 
     223 
     224        class B(Entity): 
     225            using_options(shortnames=True) 
     226            name = Field(String(20)) 
     227            as_ = ManyToMany('A') 
     228 
     229        setup_all(True) 
     230 
     231        a = A(name='a1', links_to=[A(name='a2')]) 
     232 
     233        session.commit() 
     234        session.clear() 
     235 
     236        del A 
     237        del B 
     238 
     239        # do not drop the tables, that's the whole point! 
     240        cleanup_all() 
     241 
     242        # ... 
     243        elixir.options.M2MCOL_NAMEFORMAT = elixir.options.NEW_M2MCOL_NAMEFORMAT 
     244#        elixir.options.MIGRATION_TO_07_AID = True 
     245 
     246        class A(Entity): 
     247            using_options(shortnames=True) 
     248            name = Field(String(20)) 
     249            links_to = ManyToMany('A', local_colname='a_id1') 
     250            is_linked_from = ManyToMany('A', local_colname='a_id2') 
     251            bs_ = ManyToMany('B') 
     252 
     253        class B(Entity): 
     254            using_options(shortnames=True) 
     255            name = Field(String(20)) 
     256            as_ = ManyToMany('A') 
     257 
     258        setup_all() 
     259 
     260        a1 = A.get_by(name='a1') 
     261        assert len(a1.links_to) == 1 
     262        assert not a1.is_linked_from 
     263 
     264        a2 = a1.links_to[0] 
     265        assert a2.name == 'a2' 
     266        assert not a2.links_to 
     267        assert a2.is_linked_from == [a1] 
     268 
    214269    def test_manual_column_format(self): 
    215270        class A(Entity):