File: test_packages.py

package info (click to toggle)
elixir 0.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 640 kB
  • ctags: 1,079
  • sloc: python: 4,936; makefile: 10
file content (71 lines) | stat: -rw-r--r-- 1,778 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
Test spreading entities accross several modules
"""

import sys

from elixir import *

def setup():
    metadata.bind = 'sqlite:///'

class TestPackages(object):
    def teardown(self):
        cleanup_all(True)

    def test_full_entity_path(self):
        # This is an ugly workaround because when nosetest is run globally (ie
        # either on the tests directory or in the "trunk" directory, it imports
        # all modules, including a and b. Then when any other test calls
        # setup_all(), A and B are also setup, but then the other test also
        # calls cleanup_all(), so when we get here, A and B are already dead
        # and reimporting their modules does nothing because they were already
        # imported.

        sys.modules.pop('tests.a', None)
        sys.modules.pop('tests.b', None)

        from tests.a import A
        from tests.b import B

        setup_all(True)

        b1 = B(name='b1', as_=[A(name='a1')])

        session.commit()
        session.clear()

        a = A.query.one()

        assert a in a.b.as_

    def test_ref_to_imported_entity_using_class(self):
        sys.modules.pop('tests.a', None)
        sys.modules.pop('tests.b', None)

        from tests.a import A
        from tests.b import B

        class C(Entity):
            name = Field(String(30))
            a = ManyToOne(A)

        setup_all(True)

        assert 'a_id' in C.table.columns

    def test_ref_to_imported_entity_using_name(self):
        sys.modules.pop('tests.a', None)
        sys.modules.pop('tests.b', None)

        from tests.a import A
        from tests.b import B

        class C(Entity):
            name = Field(String(30))
            a = ManyToOne('A')

        setup_all(True)

        assert 'a_id' in C.table.columns