Changeset 516 for elixir/trunk

Show
Ignore:
Timestamp:
11/13/09 11:06:20 (3 years ago)
Author:
ged
Message:

added tests for custom collection, or custom session on base class (they serve
more as examples than real tests but that's already quite useful).

Location:
elixir/trunk/tests
Files:
2 modified

Legend:

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

    r515 r516  
    1212 
    1313def setup(): 
    14     # this is an ugly hack because globally defined entities of other tests  
    15     # (a.*, b.*, db1.* and db2.*) leak into this one because of nosetests  
    16     # habit of importing all modules before running the first test.  
    17     # test_abstract is usually the first test to be run, so it gets all the  
     14    # this is an ugly hack because globally defined entities of other tests 
     15    # (a.*, b.*, db1.* and db2.*) leak into this one because of nosetests 
     16    # habit of importing all modules before running the first test. 
     17    # test_abstract is usually the first test to be run, so it gets all the 
    1818    # crap. 
    1919    cleanup_all() 
     
    196196        session.commit() 
    197197 
    198  
  • elixir/trunk/tests/test_custombase.py

    r510 r516  
    44 
    55from elixir import * 
     6import elixir 
    67 
    78def setup(): 
     
    182183        assert TestA._descriptor.identity == 'test_a' 
    183184 
     185    def test_base_custom_collection(self): 
     186        global A, B 
     187 
     188        collection = elixir.collection.RelativeEntityCollection() 
     189 
     190        class Base(object): 
     191            __metaclass__ = EntityMeta 
     192            using_options_defaults(collection=collection) 
     193 
     194        class A(Base): 
     195            b = ManyToOne('B') 
     196 
     197        class B(Base): 
     198            a = OneToOne('A') 
     199 
     200        assert not elixir.entities 
     201        assert A.table is None 
     202        assert B.table is None 
     203 
     204        setup_entities(collection) 
     205 
     206        assert A.table is not None 
     207        assert B.table is not None 
     208 
     209        del A 
     210        del B 
     211 
     212    def test_base_custom_session(self): 
     213        from sqlalchemy.orm import sessionmaker 
     214 
     215        class Base(object): 
     216            __metaclass__ = EntityMeta 
     217            using_options_defaults(session=None) 
     218 
     219        class A(Base): 
     220            b = ManyToOne('B') 
     221 
     222        class B(Base): 
     223            a = OneToOne('A') 
     224         
     225        setup_all(True) 
     226 
     227        a = A() 
     228 
     229        assert a not in elixir.session 
     230 
     231        session = sessionmaker()() 
     232        session.add(a) 
     233        assert a in session 
     234