|
Revision 233, 0.9 kB
(checked in by ged, 6 years ago)
|
|
rename
|
| Line | |
|---|
| 1 | """ |
|---|
| 2 | simple test case |
|---|
| 3 | """ |
|---|
| 4 | |
|---|
| 5 | from elixir import * |
|---|
| 6 | |
|---|
| 7 | #----------- |
|---|
| 8 | |
|---|
| 9 | class TestMultipleRelationships(object): |
|---|
| 10 | def setup(self): |
|---|
| 11 | metadata.bind = 'sqlite:///' |
|---|
| 12 | |
|---|
| 13 | def teardown(self): |
|---|
| 14 | cleanup_all(True) |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | def test_has_and_belongs_to_many_multi_ref(self): |
|---|
| 18 | class A(Entity): |
|---|
| 19 | name = Field(String(100)) |
|---|
| 20 | |
|---|
| 21 | rel1 = ManyToMany('B') |
|---|
| 22 | rel2 = ManyToMany('B') |
|---|
| 23 | |
|---|
| 24 | class B(Entity): |
|---|
| 25 | name = Field(String(20), primary_key=True) |
|---|
| 26 | |
|---|
| 27 | setup_all(True) |
|---|
| 28 | |
|---|
| 29 | b1 = B(name='b1') |
|---|
| 30 | a1 = A(name='a1', rel1=[B(name='b2'), b1], |
|---|
| 31 | rel2=[B(name='b3'), B(name='b4'), b1]) |
|---|
| 32 | |
|---|
| 33 | session.flush() |
|---|
| 34 | session.clear() |
|---|
| 35 | |
|---|
| 36 | a1 = A.query.one() |
|---|
| 37 | b1 = B.get_by(name='b1') |
|---|
| 38 | b2 = B.get_by(name='b2') |
|---|
| 39 | |
|---|
| 40 | assert b1 in a1.rel1 |
|---|
| 41 | assert b1 in a1.rel2 |
|---|
| 42 | assert b2 in a1.rel1 |
|---|