Show
Ignore:
Timestamp:
03/23/09 11:56:17 (4 years ago)
Author:
ged
Message:

Fixed using to_dict with a ManyToOne relationship in the "deep" set and that
relationship being None in the entity being converted.

Files:
1 modified

Legend:

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

    r361 r448  
    2626        tbl1 = ManyToOne(Table1) 
    2727 
    28     setup_all(True) 
     28    setup_all() 
    2929 
    3030def teardown(): 
    31     cleanup_all(True) 
     31    cleanup_all() 
    3232 
    3333class TestDeepSet(object): 
     34    def setup(self): 
     35        create_all() 
     36 
     37    def teardown(self): 
     38        session.close() 
     39        drop_all() 
     40 
    3441    def test_set_attr(self): 
    3542        t1 = Table1() 
     
    8895        session.commit() 
    8996        try: 
    90             t1.from_dict(dict(tbl2s=[{'t2id':t2.t2id+1}])) 
     97            t1.from_dict(dict(tbl2s=[{'t2id': t2.t2id+1}])) 
    9198            assert False 
    9299        except: 
     
    97104        assert t1.to_dict() == {'t1id': 50, 'name': 'test1'} 
    98105 
     106    def test_to_deep_m2o(self): 
     107        t1 = Table1(t1id=1, name='test1') 
     108        t2 = Table2(t2id=1, name='test2', tbl1=t1) 
     109        session.flush() 
     110        assert t2.to_dict(deep={'tbl1': {}}) == \ 
     111               {'t2id': 1, 'name': 'test2', 'tbl1_t1id': 1, 
     112                'tbl1': {'name': 'test1'}} 
     113 
     114    def test_to_deep_m2o_none(self): 
     115        t2 = Table2(t2id=1, name='test2') 
     116        session.flush() 
     117        assert t2.to_dict(deep={'tbl1': {}}) == \ 
     118               {'t2id': 1, 'name': 'test2', 'tbl1_t1id': None, 'tbl1': None} 
     119 
    99120    def test_to_deep(self): 
    100121        t1 = Table1(t1id=51, name='test2') 
    101         assert t1.to_dict(deep={'tbl2s':{}}) == \ 
     122        assert t1.to_dict(deep={'tbl2s': {}}) == \ 
    102123                {'t1id': 51, 'name': 'test2', 'tbl2s': []} 
    103124 
     
    116137        t1.tbl3 = Table3(t3id=50, name='wobble') 
    117138        session.commit() 
    118         assert t1.to_dict(deep={'tbl3':{}}) == \ 
     139        assert t1.to_dict(deep={'tbl3': {}}) == \ 
    119140                {'t1id': 53, 
    120141                 'name': 'test2',