Changeset 234

Show
Ignore:
Timestamp:
10/22/07 17:22:20 (6 years ago)
Author:
ged
Message:

converted most tests to the attribute syntax + reorganized tests around

Location:
elixir/trunk/tests
Files:
1 added
21 modified

Legend:

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

    r147 r234  
    22 
    33class A(Entity): 
    4     has_field('name', String(30)) 
    5     belongs_to('b', of_kind='tests.b.B') 
     4    name = Field(String(30)) 
     5    b = ManyToOne('tests.b.B') 
    66 
  • elixir/trunk/tests/b.py

    r199 r234  
    22 
    33class B(Entity): 
    4     has_field('name', String(30)) 
    5     has_many('as_', of_kind='tests.a.A') 
     4    name = Field(String(30)) 
     5    as_ = OneToMany('tests.a.A') 
    66 
  • elixir/trunk/tests/test_associable.py

    r225 r234  
    3434    def test_basic(self): 
    3535        class Address(Entity): 
    36             has_field('street', String(130)) 
    37             has_field('city', String) 
     36            street = Field(String(130)) 
     37            city = Field(String) 
    3838            using_options(shortnames=True) 
    3939 
    4040        class Comment(Entity): 
    41             has_field('id', Integer, primary_key=True) 
    42             has_field('name', Unicode) 
    43             has_field('text', String) 
     41            id = Field(Integer, primary_key=True) 
     42            name = Field(Unicode) 
     43            text = Field(String) 
    4444 
    4545        is_addressable = associable(Address, 'addresses') 
     
    4747 
    4848        class Person(Entity): 
    49             has_field('id', Integer, primary_key=True) 
    50             has_field('name', Unicode) 
    51             has_many('orders', of_kind='Order') 
     49            id = Field(Integer, primary_key=True) 
     50            name = Field(Unicode) 
     51            orders = OneToMany('Order') 
    5252            using_options(shortnames=True) 
    5353            is_addressable() 
     
    5555 
    5656        class Order(Entity): 
    57             has_field('order_num', Integer, primary_key=True) 
    58             has_field('item_count', Integer) 
    59             belongs_to('person', of_kind='Person') 
     57            order_num = Field(Integer, primary_key=True) 
     58            item_count = Field(Integer) 
     59            person = ManyToOne('Person') 
    6060            using_options(shortnames=True) 
    6161            is_addressable('address', uselist=False) 
     
    9090    def test_with_forward_ref(self): 
    9191        class Checkout(Entity): 
    92             belongs_to('by', of_kind='Villian', ondelete='cascade') 
    93             has_field('stamp', DateTime) 
     92            by = ManyToOne('Villian', ondelete='cascade') 
     93            stamp = Field(DateTime) 
    9494 
    9595        can_checkout = associable(Checkout, 'checked_out') 
    9696 
    9797        class Article(Entity): 
    98             has_field('title', Unicode) 
    99             has_field('content', Unicode) 
     98            title = Field(Unicode) 
     99            content = Field(Unicode) 
    100100            can_checkout('checked_out_by', uselist=False) 
    101101            using_options(tablename='article') 
    102102 
    103103        class Villian(Entity): 
    104             has_field('name', Unicode) 
     104            name = Field(Unicode) 
    105105            using_options(tablename='villian') 
    106106 
  • elixir/trunk/tests/test_autoload.py

    r225 r234  
    11""" 
    2     simple test case 
     2test autoloaded entities 
    33""" 
    44 
     
    4444    # without having to make them global. 
    4545    class Person(Entity): 
    46         belongs_to('father', of_kind='Person') 
    47         has_many('children', of_kind='Person') 
    48         has_many('pets', of_kind='Animal', inverse='owner') 
    49         has_many('animals', of_kind='Animal', inverse='feeder') 
    50         has_and_belongs_to_many('categories', of_kind='Category',  
     46        father = ManyToOne('Person') 
     47        children = OneToMany('Person') 
     48        pets = OneToMany('Animal', inverse='owner') 
     49        animals = OneToMany('Animal', inverse='feeder') 
     50        categories = ManyToMany('Category',  
    5151                                tablename='person_category') 
    52         has_and_belongs_to_many('appreciate', of_kind='Person', 
     52        appreciate = ManyToMany('Person', 
    5353                                tablename='person_person', 
    5454                                local_side='person_id1') 
    55         has_and_belongs_to_many('isappreciatedby', of_kind='Person', 
     55        isappreciatedby = ManyToMany('Person', 
    5656                                tablename='person_person', 
    5757                                local_side='person_id2') 
    5858 
    5959    class Animal(Entity): 
    60         belongs_to('owner', of_kind='Person', colname='owner_id') 
    61         belongs_to('feeder', of_kind='Person', colname='feeder_id') 
     60        owner = ManyToOne('Person', colname='owner_id') 
     61        feeder = ManyToOne('Person', colname='feeder_id') 
    6262 
    6363 
    6464    class Category(Entity): 
    65         has_and_belongs_to_many('persons', of_kind='Person',  
     65        persons = ManyToMany('Person',  
    6666                                tablename='person_category') 
    6767 
     
    122122        assert p is Person.get_by(name="Lisa").father 
    123123 
    124     def test_autoload_has_and_belongs_to_many(self): 
     124    def test_autoload_m2m(self): 
    125125        stupid = Category(name="Stupid") 
    126126        simpson = Category(name="Simpson") 
     
    147147        assert c in grampa.categories 
    148148 
    149     def test_autoload_has_and_belongs_to_many_selfref(self): 
     149    def test_autoload_m2m_selfref(self): 
    150150        barney = Person(name="Barney") 
    151151        homer = Person(name="Homer", appreciate=[barney]) 
     
    160160        assert homer in barney.isappreciatedby 
    161161 
    162 if __name__ == '__main__': 
    163     setup() 
    164  
    165     test = TestAutoload() 
    166     test.setup() 
    167     test.test_autoload() 
    168     test.teardown() 
    169  
    170     test.setup() 
    171     test.test_autoload_selfref() 
    172     test.teardown() 
    173  
    174     test.setup() 
    175     test.test_autoload_has_and_belongs_to_many() 
    176     test.teardown() 
    177  
    178     test.setup() 
    179     test.test_autoload_has_and_belongs_to_many_selfref() 
    180     test.teardown() 
    181  
    182     teardown() 
  • elixir/trunk/tests/test_autoload_mixed.py

    r178 r234  
    1919 
    2020        class Item(Entity): 
    21             belongs_to('owner', of_kind='User') 
     21            owner = ManyToOne('User') 
    2222 
    2323        setup_all(True) 
  • elixir/trunk/tests/test_autosetup.py

    r222 r234  
    1919    def test_autosetup_manual_setup_all(self): 
    2020        class Person(Entity): 
    21             has_field('name', Unicode(30)) 
     21            name = Field(Unicode(30)) 
    2222            using_options(autosetup=True, tablename='person') 
    2323 
     
    3434    def test_cleanup_before_setup(self): 
    3535        class Person(Entity): 
    36             has_field('name', Unicode(30)) 
     36            name = Field(Unicode(30)) 
    3737            using_options(autosetup=True, tablename='person') 
    3838 
     
    4848    def test_no_autosetup(self): 
    4949        class Person(Entity): 
    50             has_field('name', Unicode(30)) 
     50            name = Field(Unicode(30)) 
    5151            using_options(autosetup=False, tablename='person') 
    5252 
     
    6363    def test_call(self): 
    6464        class Person(Entity): 
    65             has_field('name', Unicode(30)) 
     65            name = Field(Unicode(30)) 
    6666            using_options(tablename='person') 
    6767 
     
    7272    def test_getattr(self): 
    7373        class Person(Entity): 
    74             has_field('name', Unicode(30)) 
     74            name = Field(Unicode(30)) 
    7575            using_options(tablename='person') 
    7676 
     
    8181    def test_createall(self): 
    8282        class Person(Entity): 
    83             has_field('name', Unicode(30)) 
     83            name = Field(Unicode(30)) 
    8484            using_options(tablename='person') 
    8585 
     
    8989    def test_setupall(self): 
    9090        class Person(Entity): 
    91             has_field('name', Unicode(30)) 
     91            name = Field(Unicode(30)) 
    9292            using_options(tablename='person') 
    9393 
     
    9797    def test_query(self): 
    9898        class Person(Entity): 
    99             has_field('name', Unicode(30)) 
     99            name = Field(Unicode(30)) 
    100100            using_options(tablename='person') 
    101101 
  • elixir/trunk/tests/test_class_methods.py

    r229 r234  
    1616    def test_get(self): 
    1717        class A(Entity): 
    18             has_field('name', Unicode(32)) 
     18            name = Field(Unicode(32)) 
    1919 
    2020        setup_all(True) 
  • elixir/trunk/tests/test_collections.py

    r222 r234  
    2020    def test_no_collection(self): 
    2121        class Person(Entity): 
    22             has_field('name', Unicode(30)) 
     22            name = Field(Unicode(30)) 
    2323            using_options(autosetup=False, tablename='person', collection=None) 
    2424 
     
    3636 
    3737        class A(Entity): 
    38             has_field('name', Unicode(30)) 
     38            name = Field(Unicode(30)) 
    3939            using_options(collection=collection1, autosetup=False,  
    4040                          tablename='a') 
    4141 
    4242        class B(Entity): 
    43             has_field('name', Unicode(30)) 
     43            name = Field(Unicode(30)) 
    4444            using_options(collection=collection2, autosetup=False, 
    4545                          tablename='b') 
     
    6060    def test_setup_after_cleanup(self): 
    6161        class A(Entity): 
    62             has_field('name', Unicode(30)) 
     62            name = Field(Unicode(30)) 
    6363            using_options(autosetup=False, tablename='a') 
    6464 
  • elixir/trunk/tests/test_encryption.py

    r225 r234  
    77     
    88    class Person(Entity): 
    9         has_field('name', Unicode) 
    10         has_field('password', Unicode) 
    11         has_field('ssn', Unicode) 
    12         has_many('pets', of_kind='Pet') 
     9        name = Field(Unicode) 
     10        password = Field(Unicode) 
     11        ssn = Field(Unicode) 
     12        pets = OneToMany('Pet') 
    1313        acts_as_encrypted(for_fields=['password', 'ssn'], with_secret='secret') 
    1414 
    1515    class Pet(Entity): 
    16         has_field('name', Unicode) 
    17         has_field('codename', Unicode) 
     16        name = Field(Unicode) 
     17        codename = Field(Unicode) 
    1818        acts_as_encrypted(for_fields=['codename'], with_secret='secret2') 
    19         belongs_to('owner', of_kind='Person') 
     19        owner = ManyToOne('Person') 
    2020 
    2121     
  • elixir/trunk/tests/test_events.py

    r225 r234  
    1717     
    1818    class Document(Entity): 
    19         has_field('name', Unicode) 
     19        name = Field(Unicode) 
    2020         
    2121        @before_insert 
  • elixir/trunk/tests/test_inherit.py

    r225 r234  
    1313def do_tst(inheritance, polymorphic, with_rel, expected_res): 
    1414    class A(Entity): 
    15         has_field('data1', String(20)) 
     15        data1 = Field(String(20)) 
    1616        using_options(inheritance=inheritance, polymorphic=polymorphic) 
    1717 
    1818    class B(A): 
    19         has_field('data2', String(20)) 
     19        data2 = Field(String(20)) 
    2020        if with_rel: 
    21             has_many('many_c', of_kind='C', inverse='some_b')         
     21            many_c = OneToMany('C', inverse='some_b')         
    2222        using_options(inheritance=inheritance, polymorphic=polymorphic) 
    2323 
    2424    class C(B): 
    25         has_field('data3', String(20)) 
     25        data3 = Field(String(20)) 
    2626        if with_rel: 
    27             belongs_to('some_b', of_kind='B', inverse='many_c') 
     27            some_b = ManyToOne('B', inverse='many_c') 
    2828        using_options(inheritance=inheritance, polymorphic=polymorphic) 
    2929 
    3030    class D(A): 
    31         has_field('data4', String(20)) 
     31        data4 = Field(String(20)) 
    3232        using_options(inheritance=inheritance, polymorphic=polymorphic) 
    3333 
  • elixir/trunk/tests/test_m2m.py

    r233 r234  
    11""" 
    2     simple test case 
     2test many to many relationships 
    33""" 
    44 
     
    77#----------- 
    88 
    9 class TestMultipleRelationships(object): 
     9class TestManyToMany(object): 
    1010    def setup(self): 
    1111        metadata.bind = 'sqlite:///' 
     
    1414        cleanup_all(True) 
    1515     
     16    def test_simple(self): 
     17        class A(Entity): 
     18            name = Field(Unicode(60)) 
     19            bs_ = ManyToMany('B') 
    1620 
    17     def test_has_and_belongs_to_many_multi_ref(self): 
     21        class B(Entity): 
     22            name = Field(Unicode(60)) 
     23            as_ = ManyToMany('A') 
     24 
     25        setup_all(True) 
     26 
     27        b1 = B(name='b1', as_=[A(name='a1')]) 
     28 
     29        session.flush() 
     30        session.clear() 
     31 
     32        a = A.query.one() 
     33        b = B.query.one() 
     34 
     35        assert a in b.as_ 
     36        assert b in a.bs_ 
     37 
     38    def test_multi(self): 
    1839        class A(Entity): 
    1940            name = Field(String(100)) 
     
    4263        assert b2 in a1.rel1 
    4364 
     65    def test_selfref(self): 
     66        class Person(Entity): 
     67            name = Field(Unicode(30)) 
     68             
     69            friends = ManyToMany('Person') 
     70 
     71        create_all() 
     72 
     73        barney = Person(name="Barney") 
     74        homer = Person(name="Homer", friends=[barney]) 
     75        barney.friends.append(homer) 
     76 
     77        session.flush() 
     78        session.clear() 
     79         
     80        homer = Person.get_by(name="Homer") 
     81        barney = Person.get_by(name="Barney") 
     82 
     83        assert homer in barney.friends 
     84        assert barney in homer.friends 
     85 
     86    def test_has_and_belongs_to_many(self): 
     87        class A(Entity): 
     88            has_field('name', String(100)) 
     89 
     90            has_and_belongs_to_many('bs', of_kind='B') 
     91             
     92        class B(Entity): 
     93            has_field('name', String(100), primary_key=True) 
     94 
     95        setup_all(True) 
     96         
     97        b1 = B(name='b1') 
     98        a1 = A(name='a1', bs=[B(name='b2'), b1]) 
     99        a2 = A(name='a2', bs=[B(name='b3'), b1]) 
     100        a3 = A(name='a3') 
     101 
     102        session.flush() 
     103        session.clear() 
     104         
     105        a1 = A.get_by(name='a1') 
     106        a2 = A.get_by(name='a2') 
     107        a3 = A.get_by(name='a3') 
     108        b1 = B.get_by(name='b1') 
     109        b2 = B.get_by(name='b2') 
     110 
     111        assert b1 in a1.bs 
     112        assert b2 in a1.bs 
     113        assert b1 in a2.bs 
     114        assert not a3.bs 
     115 
  • elixir/trunk/tests/test_m2o.py

    r232 r234  
    11""" 
    2     simple test case 
     2test many to one relationships 
    33""" 
    44 
     
    88    metadata.bind = 'sqlite:///' 
    99 
    10 class TestOneWay(object): 
     10class TestManyToOne(object): 
    1111    def teardown(self): 
    1212        cleanup_all(True) 
    1313     
    14     def test_m2o(self): 
     14    def test_simple(self): 
    1515        class A(Entity): 
    1616            name = Field(Unicode(60)) 
     
    3131        assert b.a.name == 'a1' 
    3232 
    33     def test_m2o_with_key_pk(self): 
     33    def test_with_key_pk(self): 
    3434        class A(Entity): 
    3535            test = Field(Integer, primary_key=True, key='testx') 
     
    122122        assert A.table.columns.has_key('c_b_a_id') 
    123123 
    124     def test_multi_m2o(self): 
     124    def test_multi(self): 
    125125        class A(Entity): 
    126126            name = Field(String(32)) 
  • elixir/trunk/tests/test_nestedclass.py

    r125 r234  
    1 from elixir import Entity, has_field, String 
     1from elixir import Entity, Field, String 
    22 
    33def setup(): 
     
    55 
    66    class Thing(Entity): 
    7         has_field('name', String(40)) 
    8         has_field('type', String(40)) 
     7        name = Field(String(40)) 
     8        type = Field(String(40)) 
    99         
    1010        class Stuff(Entity): 
    11             has_field('ping', String(32)) 
    12             has_field('pong', String(32)) 
     11            ping = Field(String(32)) 
     12            pong = Field(String(32)) 
    1313         
    14         has_field('other', String(40)) 
     14        other = Field(String(40)) 
    1515     
    1616class TestNestedClass(object): 
  • elixir/trunk/tests/test_options.py

    r225 r234  
    1818    def test_version_id_col(self): 
    1919        class Person(Entity): 
    20             has_field('name', Unicode(30)) 
     20            name = Field(Unicode(30)) 
    2121  
    2222            using_options(version_id_col=True) 
     
    6565 
    6666        class MyEntity(Entity): 
    67             has_field('name', Unicode(30)) 
     67            name = Field(Unicode(30)) 
    6868 
    6969        class MySuperTestEntity(Entity): 
    70             has_field('name', Unicode(30)) 
     70            name = Field(Unicode(30)) 
    7171 
    7272        setup_all(True) 
     
    9494        class Person(Entity): 
    9595            using_options(session=ctx) 
    96             has_field('firstname', Unicode(30)) 
    97             has_field('surname', Unicode(30)) 
     96            firstname = Field(Unicode(30)) 
     97            surname = Field(Unicode(30)) 
    9898 
    9999        create_all(engine) 
     
    111111        class Person(Entity): 
    112112            using_options(session=None) 
    113             has_field('firstname', Unicode(30)) 
    114             has_field('surname', Unicode(30)) 
     113            firstname = Field(Unicode(30)) 
     114            surname = Field(Unicode(30)) 
    115115 
    116116        create_all(engine) 
     
    152152        class Person(Entity): 
    153153            using_options(session=store) 
    154             has_field('firstname', Unicode(30)) 
    155             has_field('surname', Unicode(30)) 
     154            firstname = Field(Unicode(30)) 
     155            surname = Field(Unicode(30)) 
    156156 
    157157        create_all(engine) 
     
    178178        class Person(Entity): 
    179179            using_options(session=Session) 
    180             has_field('firstname', Unicode(30)) 
    181             has_field('surname', Unicode(30)) 
     180            firstname = Field(Unicode(30)) 
     181            surname = Field(Unicode(30)) 
    182182 
    183183        create_all(engine) 
     
    205205         
    206206        class Person(Entity): 
    207             has_field('firstname', Unicode(30)) 
    208             has_field('surname', Unicode(30)) 
     207            firstname = Field(Unicode(30)) 
     208            surname = Field(Unicode(30)) 
    209209 
    210210        create_all(engine) 
     
    229229         
    230230        class Person(Entity): 
    231             has_field('firstname', Unicode(30)) 
    232             has_field('surname', Unicode(30)) 
     231            firstname = Field(Unicode(30)) 
     232            surname = Field(Unicode(30)) 
    233233 
    234234            using_table_options(UniqueConstraint('firstname', 'surname')) 
     
    253253    def test_unique_constraint_belongs_to(self): 
    254254        class Author(Entity): 
    255             has_field("name", Unicode) 
     255            name = Field(Unicode) 
    256256 
    257257        class Book(Entity): 
    258             has_field("title", Unicode, required=True) 
    259             belongs_to("author", of_kind="Author") 
     258            title = Field(Unicode, required=True) 
     259            author = ManyToOne("Author") 
    260260 
    261261            using_table_options(UniqueConstraint("title", "author_id")) 
  • elixir/trunk/tests/test_order_by.py

    r225 r234  
    11""" 
    2     test options 
     2test ordering options 
    33""" 
    44 
     
    1010     
    1111    class Record(Entity): 
    12         has_field('title', Unicode(100)) 
    13         has_field('year', Integer) 
    14         belongs_to('artist', of_kind='Artist') 
    15         has_and_belongs_to_many('genres', of_kind='Genre') 
     12        title = Field(Unicode(100)) 
     13        year = Field(Integer) 
     14        artist = ManyToOne('Artist') 
     15        genres = ManyToMany('Genre') 
    1616 
    1717        # order titles descending by year, then by title 
     
    2222 
    2323    class Artist(Entity): 
    24         has_field('name', Unicode(30)) 
    25         has_many('records', of_kind='Record', order_by=['year', '-title']) 
     24        name = Field(Unicode(30)) 
     25        records = OneToMany('Record', order_by=['year', '-title']) 
    2626 
    2727    class Genre(Entity): 
    28         has_field('name', Unicode(30)) 
    29         has_and_belongs_to_many('records', of_kind='Record',  
    30                                 order_by='-title') 
     28        name = Field(Unicode(30)) 
     29        records = ManyToMany('Record', order_by='-title') 
    3130 
    3231    metadata.bind = 'sqlite:///' 
     
    7675        assert records[-1].year == 1989 
    7776 
    78     def test_has_many_order_by(self): 
     77    def test_o2m_order_by(self): 
    7978        records = Artist.get_by(name="Dream Theater").records 
    8079 
     
    8988        assert records[-1].year == 2005 
    9089 
    91     def test_has_and_belongs_to_many_order_by(self): 
     90    def test_m2m_order_by(self): 
    9291        records = Genre.get_by(name="Progressive metal").records 
    9392 
  • elixir/trunk/tests/test_packages.py

    r225 r234  
    4646 
    4747        class C(Entity): 
    48             has_field('name', String(30)) 
    49             belongs_to('a', of_kind=A) 
     48            name = Field(String(30)) 
     49            a = ManyToOne(A) 
    5050 
    5151        setup_all(True) 
     
    6262 
    6363        class C(Entity): 
    64             has_field('name', String(30)) 
    65             belongs_to('a', of_kind='A') 
     64            name = Field(String(30)) 
     65            a = ManyToOne('A') 
    6666 
    6767        setup_all(True) 
  • elixir/trunk/tests/test_properties.py

    r229 r234  
    11""" 
    2     simple test case 
     2test special properties (eg. column_property, ...) 
    33""" 
    44 
  • elixir/trunk/tests/test_selfref.py

    r225 r234  
    1313        cleanup_all() 
    1414     
    15     def test_belongs_to_selfref(self): 
    16         class Person(Entity): 
    17             with_fields( 
    18                 name = Field(Unicode(30)) 
    19             ) 
    20              
    21             belongs_to('father', of_kind='Person', inverse='children') 
    22             has_many('children', of_kind='Person', inverse='father') 
    23  
    24         create_all() 
    25  
    26         grampa = Person(name="Abe") 
    27         homer = Person(name="Homer") 
    28         bart = Person(name="Bart") 
    29         lisa = Person(name="Lisa") 
    30          
    31         grampa.children.append(homer)         
    32         homer.children.append(bart) 
    33         lisa.father = homer 
    34          
    35         session.flush() 
    36         session.clear() 
    37          
    38         p = Person.get_by(name="Homer") 
    39          
    40         print "%s is %s's child." % (p.name, p.father.name)         
    41         print "His children are: %s." % ( 
    42                 " and ".join(c.name for c in p.children)) 
    43          
    44         assert p in p.father.children 
    45         assert p.father is Person.get_by(name="Abe") 
    46         assert p is Person.get_by(name="Lisa").father 
    47  
    48     def test_has_and_belongs_to_many_selfref(self): 
    49         class Person(Entity): 
    50             with_fields( 
    51                 name = Field(Unicode(30)) 
    52             ) 
    53              
    54             has_and_belongs_to_many('friends', of_kind='Person') 
    55  
    56         create_all() 
    57  
    58         barney = Person(name="Barney") 
    59         homer = Person(name="Homer", friends=[barney]) 
    60         barney.friends.append(homer) 
    61  
    62         session.flush() 
    63         session.clear() 
    64          
    65         homer = Person.get_by(name="Homer") 
    66         barney = Person.get_by(name="Barney") 
    67  
    68         assert homer in barney.friends 
    69         assert barney in homer.friends 
    7015 
    7116class TestMultiSelfRef(object): 
     
    7621        cleanup_all() 
    7722 
    78     def test_belongs_to_multiple_selfref(self): 
    79         # define a self-referential table with several relations 
    8023 
    81         class TreeNode(Entity): 
    82             has_field('name', String(50), nullable=False) 
    83  
    84             belongs_to('parent', of_kind='TreeNode') 
    85             has_many('children', of_kind='TreeNode', inverse='parent') 
    86             belongs_to('root', of_kind='TreeNode') 
    87  
    88             def __str__(self): 
    89                 return self._getstring(0) 
    90  
    91             def _getstring(self, level): 
    92                 s = '  ' * level + \ 
    93                     "%s (%s,%s,%s, %d)" % (self.name, self.id, self.parent_id, 
    94                                            self.root_id, id(self)) + \ 
    95                     '\n' 
    96                 s += ''.join([n._getstring(level+1) for n in self.children]) 
    97                 return s 
    98  
    99         create_all() 
    100  
    101         node2 = TreeNode(name='node2') 
    102         node2.children.append(TreeNode(name='subnode1')) 
    103         node2.children.append(TreeNode(name='subnode2')) 
    104         node = TreeNode(name='rootnode') 
    105         node.children.append(TreeNode(name='node1')) 
    106         node.children.append(node2) 
    107         node.children.append(TreeNode(name='node3')) 
    108              
    109         session.flush() 
    110         session.clear() 
    111          
    112         root = TreeNode.get_by(name='rootnode') 
    113         print root 
    114  
    115 if __name__ == '__main__': 
    116     test = TestSelfRef() 
    117     test.setup() 
    118     test.test_belongs_to_selfref() 
    119     test.teardown()         
    120     test.setup() 
    121     test.test_has_and_belongs_to_many_selfref() 
    122     test.teardown()         
    123  
    124     test = TestMultiSelfRef() 
    125     test.setup() 
    126     test.test_belongs_to_multiple_selfref() 
    127     test.teardown()         
  • elixir/trunk/tests/test_simplerel.py

    r230 r234  
    77    def teardown(self): 
    88        cleanup_all(True) 
    9  
    10     def test_m2o_and_o2m(self): 
    11         class A(Entity): 
    12             name = Field(Unicode(60)) 
    13             bs = OneToMany('B') 
    14  
    15         class B(Entity): 
    16             name = Field(Unicode(60)) 
    17             a = ManyToOne('A') 
    18  
    19         setup_all(True) 
    20  
    21         b1 = B(name='b1', a=A(name='a1')) 
    22  
    23         session.flush() 
    24         session.clear() 
    25  
    26         b = B.query.one() 
    27         a = b.a 
    28  
    29         assert b in a.bs 
    309 
    3110    def test_o2o(self): 
     
    5029        assert b == a.b 
    5130 
    52     def test_m2m(self): 
    53         class A(Entity): 
    54             name = Field(Unicode(60)) 
    55             bs_ = ManyToMany('B') 
    5631 
    57         class B(Entity): 
    58             name = Field(Unicode(60)) 
    59             as_ = ManyToMany('A') 
    60  
    61         setup_all(True) 
    62  
    63         b1 = B(name='b1', as_=[A(name='a1')]) 
    64  
    65         session.flush() 
    66         session.clear() 
    67  
    68         a = A.query.one() 
    69         b = B.query.one() 
    70  
    71         assert a in b.as_ 
    72         assert b in a.bs_ 
    73  
  • elixir/trunk/tests/test_versioning.py

    r225 r234  
    1010 
    1111    class Director(Entity): 
    12         has_field('name', Unicode(60)) 
    13         has_many('movies', of_kind='Movie', inverse='director') 
     12        name = Field(Unicode(60)) 
     13        movies = OneToMany('Movie', inverse='director') 
    1414        using_options(tablename='directors') 
    1515 
    1616 
    1717    class Movie(Entity): 
    18         has_field('id', Integer, primary_key=True) 
    19         has_field('title', Unicode(60), primary_key=True) 
    20         has_field('description', Unicode(512)) 
    21         has_field('releasedate', DateTime) 
    22         has_field('ignoreme', Integer, default=0) 
    23         belongs_to('director', of_kind='Director', inverse='movies') 
    24         has_and_belongs_to_many('actors', of_kind='Actor', inverse='movies', tablename='movie_casting') 
     18        id = Field(Integer, primary_key=True) 
     19        title = Field(Unicode(60), primary_key=True) 
     20        description = Field(Unicode(512)) 
     21        releasedate = Field(DateTime) 
     22        ignoreme = Field(Integer, default=0) 
     23        director = ManyToOne('Director', inverse='movies') 
     24        actors = ManyToMany('Actor', inverse='movies', tablename='movie_casting') 
    2525        using_options(tablename='movies') 
    2626        acts_as_versioned(ignore=['ignoreme']) 
     
    2828 
    2929    class Actor(Entity): 
    30         has_field('name', Unicode(60)) 
    31         has_and_belongs_to_many('movies', of_kind='Movie', inverse='actors', tablename='movie_casting') 
     30        name = Field(Unicode(60)) 
     31        movies = ManyToMany('Movie', inverse='actors', tablename='movie_casting') 
    3232        using_options(tablename='actors') 
    3333