root / elixir / trunk / tests / test_oneway.py @ 47

Revision 47, 1.0 kB (checked in by ged, 6 years ago)

- Changed tests so that when one test fails, other unrelated ones don't.

- now options are initialized to their "global defaults" values instead
of hard coded values, so we can set a bunch of options on all entities.

- added a way to set custom column names for belongs_to relations.

- implemented a way to delay setup (to have a behaviour somewhat similar
to something non dynamic). This is to be used in conjunction with the
new "setup_all" function.

- made autoload work for belongs_to/has_one/has_many relations. The user
must provide column names in that case. It would be possible (and quite
easy, I think) to guess things based on foreign keys when there is only
one relation of the same type between two entities, but I haven't done
it yet, and don't plan to do it before the release. It doesn't work yet
for HasAndBelongsToMany relationships.

Line 
1"""
2    simple test case
3"""
4
5import nose
6
7from sqlalchemy import create_engine
8from elixir     import *
9
10#FIXME: this shouldn't be necessary. cleanup_all should handle it. The problem
11# is that with this damn dynamic behavior, we can't easily re-setup the
12# entities once they've been setup once
13metadata.clear()
14
15class Person(Entity):
16    with_fields(
17        name = Field(Unicode(30))
18    )
19
20class Animal(Entity):
21    with_fields(
22        name = Field(Unicode(30)),
23        nose_color = Field(Unicode(15))
24    )
25   
26    belongs_to('owner', of_kind='Person')
27
28
29class TestOneWay(object):
30    def setup(self):
31        engine = create_engine('sqlite:///')
32        metadata.connect(engine)
33        create_all()
34   
35    def teardown(self):
36        cleanup_all()
37   
38    def test_oneway(self):
39        santa = Person(name="Santa Claus")
40        rudolph = Animal(name="Rudolph", nose_color="red")
41        rudolph.owner = santa
42       
43        objectstore.flush()
44        objectstore.clear()
45       
46        assert "Claus" in Animal.get_by(name="Rudolph").owner.name
Note: See TracBrowser for help on using the browser.