Exemplo n.º 1
0
    def test_entity_absolute_location_via_location (self):
        # @location('/etc/person')   # python >= 2.6
        class Person (Entity):
            firstname = Field(String)
            surname = Field(String)

        Person = location('/etc/person')(Person) # python < 2.6

        self.assertEqual(Session.default._strategy.get_location(Person),
                         '/etc/person')
Exemplo n.º 2
0
    def test_entity_relative_location_via_location (self):
        # @location('person')   # python >= 2.6
        class Person (Entity):
            firstname = Field(String)
            surname = Field(String)

        Person = location('person')(Person) # python < 2.6

        self.assertEqual(Session.default._strategy.get_location(Person),
                         '/tmp/test.tesqldb/person')
Exemplo n.º 3
0
    def test_singleton_absolute_location_via_location (self):
        # python >= 2.6
        # @location('/etc/person')
        class Person (Entity):
            pk = Field(Integer, primary_key=True, choices=[0])
            firstname = Field(String)
            surname = Field(String)

        # python < 2.6
        Person = location('/etc/person')(Person)

        self.assertEqual(Session.default._strategy.get_location(Person),
                         '/etc/person.conf')

        p = Person(firstname='Homer', surname='Simpson')

        self.assertEqual(Session.default._strategy.get_location(p),
                         '/etc/person.conf')
Exemplo n.º 4
0
    def test_instance_absolute_location_via_location (self):
        # python >= 2.6
        # @location({None: '/etc/person', 1: '/etc/bart.conf'})
        class Person (Entity):
            firstname = Field(String)
            surname = Field(String)

        # python < 2.6
        Person = location({None: '/etc/person', 1: '/etc/bart.conf'})(Person)

        p1 = Person(firstname='Homer', surname='Simpson')

        self.assertEqual(Session.default._strategy.get_location(p1),
                         '/etc/person/0.conf')

        p2 = Person(firstname='Bart', surname='Simpson')

        self.assertEqual(Session.default._strategy.get_location(p2),
                         '/etc/bart.conf')