コード例 #1
0
ファイル: test_related.py プロジェクト: yvasilev/resql
    def test_store_entity_with_virtual_fields_default_store_location (self):
        s = Related()
        s.bind(self.path)

        class Person (Entity):
            pk = Field(Integer, primary_key=True)
            firstname = Field(String)
            surname = Field(String, virtual=True)

        class Account (Entity):
            homedir = Field(String, virtual=True)
            person = Field(OneToOne, entity=Person, primary_key=True)

        p1 = Person(pk=1, firstname='Homer', surname='Simpson')
        p2 = Person(pk=2, firstname='Bart', surname='Simpson')

        a1 = Account(homedir='/home/hsimpson', person=p1)
        a2 = Account(homedir='/home/bsimpson', person=p2)

        s.store_location(p1)
        s.store_location(p2)

        self.assertTrue(os.path.isfile(os.path.join(self.path, 'Person', '1.conf')))
        self.assertTrue(os.path.isfile(os.path.join(self.path, 'Person', '2.conf')))

        self.assertEqual(open(os.path.join(self.path, 'Person', '1.conf'), 'rU').read(),
                         '\n[Person]\n\npk: 1\nfirstname: Homer\n'
                         '\n[Account]\n\nperson: 1\n')
        self.assertEqual(open(os.path.join(self.path, 'Person', '2.conf'), 'rU').read(),
                         '\n[Person]\n\npk: 2\nfirstname: Bart\n'
                         '\n[Account]\n\nperson: 2\n')
コード例 #2
0
ファイル: test_related.py プロジェクト: yvasilev/resql
    def test_base_bind (self):
        s = Related()

        self.assertEqual(os.path.dirname(s.base_location), os.getcwd())
        self.assertEqual(os.path.basename(s.base_location), '.tesqldb')

        s.bind(self.path)

        self.assertEqual(os.path.dirname(s.base_location), '/tmp')
        self.assertEqual(os.path.basename(s.base_location), 'test.tesqldb')
コード例 #3
0
ファイル: test_related.py プロジェクト: yvasilev/resql
    def test_entity_default_by_object_make_location (self):
        s = Related()
        s.bind(self.path)

        class Person (Entity):
            pk = Field(Integer, primary_key=True)
            firstname = Field(String)
            surname = Field(String)

        class Account (Entity):
            homedir = Field(String)
            person = Field(OneToOne, entity=Person, primary_key=True)

        p1 = Person(pk=1, firstname='Homer', surname='Simpson')
        p2 = Person(pk=2, firstname='Bart', surname='Simpson')

        self.assertEqual(s.make_location(p1),
                         os.path.join(self.path, 'Person', '1.conf'))
        self.assertEqual(s.make_location(p2),
                         os.path.join(self.path, 'Person', '2.conf'))

        self.assertTrue(os.path.isdir(os.path.join(self.path, 'Person')))

        a1 = Account(homedir='/home/hsimpson', person=p1)
        a2 = Account(homedir='/home/bsimpson', person=p2)

        self.assertEqual(s.make_location(a1),
                         os.path.join(self.path, 'Person', '1.conf'))
        self.assertEqual(s.make_location(a2),
                         os.path.join(self.path, 'Person', '2.conf'))

        self.assertTrue(os.path.isdir(os.path.join(self.path, 'Person')))
コード例 #4
0
ファイル: test_related.py プロジェクト: yvasilev/resql
    def test_entity_default_by_class_make_location (self):
        s = Related()
        s.bind(self.path)

        class Person (Entity):
            pk = Field(Integer, primary_key=True)
            firstname = Field(String)
            surname = Field(String)

        self.assertEqual(s.make_location(Person),
                         os.path.join(self.path, 'Person'))

        self.assertTrue(os.path.isdir(os.path.join(self.path, 'Person')))

        class Account (Entity):
            homedir = Field(String)
            person = Field(OneToOne, entity=Person, primary_key=True)

        self.assertEqual(s.get_location(Account),
                         os.path.join(self.path, 'Person'))

        self.assertTrue(os.path.isdir(os.path.join(self.path, 'Person')))
コード例 #5
0
ファイル: test_related.py プロジェクト: yvasilev/resql
    def test_store_load_entity_with_virtual_pk_default_store_location (self):
        s = Related()
        s.bind(self.path)

        class Person (Entity):
            pk = Field(Indexer, primary_key=True, autoincrement=True, virtual=True)
            firstname = Field(String)
            surname = Field(String)

        class Account (Entity):
            homedir = Field(String)
            person = Field(OneToOne, entity=Person, primary_key=True, virtual=True)

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

        a1 = Account(homedir='/home/hsimpson', person=p1)
        a2 = Account(homedir='/home/bsimpson', person=p2)

        s.store_location(p1)
        s.store_location(p2)

        self.assertTrue(os.path.isfile(os.path.join(self.path, 'Person', '0.conf')))
        self.assertTrue(os.path.isfile(os.path.join(self.path, 'Person', '1.conf')))

        self.assertEqual(open(os.path.join(self.path, 'Person', '0.conf'), 'rU').read(),
                         '\n[Person]\n\nfirstname: Homer\nsurname: Simpson\n'
                         '\n[Account]\n\nhomedir: /home/hsimpson\n')
        self.assertEqual(open(os.path.join(self.path, 'Person', '1.conf'), 'rU').read(),
                         '\n[Person]\n\nfirstname: Bart\nsurname: Simpson\n'
                         '\n[Account]\n\nhomedir: /home/bsimpson\n')

        np1 = s.load_location(Person, 0)
        np2 = s.load_location(Person, 1)

        self.assertTrue(isinstance(np1, list))
        self.assertEqual(np1[0].meta.name, 'Person')
        self.assertEqual(np1[0].pk, 0)
        self.assertEqual(np1[0].firstname, 'Homer')
        self.assertEqual(np1[0].surname, 'Simpson')
        self.assertEqual(np1[1].homedir, '/home/hsimpson')
        self.assertEqual(np1[1].person, np1[0])

        self.assertTrue(isinstance(np2, list))
        self.assertEqual(np2[0].meta.name, 'Person')
        self.assertEqual(np2[0].pk, 1)
        self.assertEqual(np2[0].firstname, 'Bart')
        self.assertEqual(np2[0].surname, 'Simpson')
        self.assertEqual(np2[1].homedir, '/home/bsimpson')
        self.assertEqual(np2[1].person, np2[0])
コード例 #6
0
ファイル: test_related.py プロジェクト: yvasilev/resql
    def test_load_entity_default_store_location (self):
        s = Related()
        s.bind(self.path)

        class Person (Entity):
            pk = Field(Integer, primary_key=True)
            firstname = Field(String)
            surname = Field(String)

        class Account (Entity):
            homedir = Field(String)
            person = Field(OneToOne, entity=Person, primary_key=True)

        p1 = Person(pk=1, firstname='Homer', surname='Simpson')
        p2 = Person(pk=2, firstname='Bart', surname='Simpson')

        a1 = Account(homedir='/home/hsimpson', person=p1)
        a2 = Account(homedir='/home/bsimpson', person=p2)

        s.store_location(p1)
        s.store_location(p2)

        self.assertTrue(os.path.isfile(os.path.join(self.path, 'Person', '1.conf')))
        self.assertTrue(os.path.isfile(os.path.join(self.path, 'Person', '2.conf')))

        np1 = s.load_location(Person, 1)
        np2 = s.load_location(Person, 2)

        self.assertTrue(isinstance(np1, list))
        self.assertEqual(np1[0].meta.name, 'Person')
        self.assertEqual(np1[0].pk, 1)
        self.assertEqual(np1[0].firstname, 'Homer')
        self.assertEqual(np1[0].surname, 'Simpson')
        self.assertEqual(np1[1].homedir, '/home/hsimpson')
        self.assertEqual(np1[1].person, np1[0])

        self.assertTrue(isinstance(np2, list))
        self.assertEqual(np2[0].meta.name, 'Person')
        self.assertEqual(np2[0].pk, 2)
        self.assertEqual(np2[0].firstname, 'Bart')
        self.assertEqual(np2[0].surname, 'Simpson')
        self.assertEqual(np2[1].homedir, '/home/bsimpson')
        self.assertEqual(np2[1].person, np2[0])
コード例 #7
0
ファイル: test_related.py プロジェクト: yvasilev/resql
    def test_list_entity_default_store_location (self):
        s = Related()
        s.bind(self.path)

        class Person (Entity):
            pk = Field(Integer, primary_key=True)
            firstname = Field(String)
            surname = Field(String)

        class Account (Entity):
            homedir = Field(String)
            person = Field(OneToOne, entity=Person, primary_key=True)

        p1 = Person(pk=1, firstname='Homer', surname='Simpson')
        p2 = Person(pk=2, firstname='Bart', surname='Simpson')

        a1 = Account(homedir='/home/hsimpson', person=p1)

        s.store_location(p1)
        s.store_location(p2)

        self.assertTrue(os.path.isfile(os.path.join(self.path, 'Person', '1.conf')))
        self.assertTrue(os.path.isfile(os.path.join(self.path, 'Person', '2.conf')))

        self.assertEqual(s.list_location(p1),
                         os.path.join(self.path, 'Person', '1.conf'))
        self.assertEqual(s.list_location(Person, 1),
                         os.path.join(self.path, 'Person', '1.conf'))
        self.assertEqual(s.list_location(p2),
                         os.path.join(self.path, 'Person', '2.conf'))
        self.assertEqual(s.list_location(Person, 2),
                         os.path.join(self.path, 'Person', '2.conf'))
        self.assertEqual(s.list_location(Person, 3), None)

        self.assertEqual(s.list_location(a1),
                         os.path.join(self.path, 'Person', '1.conf'))
        self.assertEqual(s.list_location(Account, 1),
                         os.path.join(self.path, 'Person', '1.conf'))
        self.assertEqual(s.list_location(Account, 2), None)

        self.assertEqual(list(s.list_location(Person)),
                         [os.path.join(self.path, 'Person', '1.conf'),
                          os.path.join(self.path, 'Person', '2.conf')])

        self.assertEqual(list(s.list_location(Account)),
                         [os.path.join(self.path, 'Person', '1.conf')])