Beispiel #1
0
    def test_store_properties(self):
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            f = Folder()
            f.id = 'Holidays'
            f.title = 'Holiday Calendar'
            app._setObject(f.id, f, set_owner=0)
            transaction.commit()

            f._setProperty('pi', 3.14, 'float')
            f._setProperty('stuff', ['a', 'bc', 'd'], 'lines')
            transaction.commit()

            conn2 = self.db.open()
            try:
                app = conn2.root()['Application']
                self.assert_(hasattr(app, 'Holidays'))
                got = 0
                for k, v in app.Holidays.propertyItems():
                    if k == 'title':
                        got += 1
                        self.assertEqual(v, 'Holiday Calendar')
                    elif k == 'pi':
                        got += 1
                        self.assertEqual(v, 3.14)
                    elif k == 'stuff':
                        got += 1
                        self.assertEqual(tuple(v), ('a', 'bc', 'd'))
                self.assertEqual(got, 3)
            finally:
                conn2.close()

        finally:
            conn.close()
Beispiel #2
0
    def test_store_properties(self):
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            f = Folder()
            f.id = 'Holidays'
            f.title = 'Holiday Calendar'
            app._setObject(f.id, f, set_owner=0)
            transaction.commit()

            f._setProperty('pi', 3.14, 'float')
            f._setProperty('stuff', ['a', 'bc', 'd'], 'lines')
            transaction.commit()

            conn2 = self.db.open()
            try:
                app = conn2.root()['Application']
                self.assert_(hasattr(app, 'Holidays'))
                got = 0
                for k, v in app.Holidays.propertyItems():
                    if k == 'title':
                        got += 1
                        self.assertEqual(v, 'Holiday Calendar')
                    elif k == 'pi':
                        got += 1
                        self.assertEqual(v, 3.14)
                    elif k == 'stuff':
                        got += 1
                        self.assertEqual(tuple(v), ('a', 'bc', 'd'))
                self.assertEqual(got, 3)
            finally:
                conn2.close()

        finally:
            conn.close()
Beispiel #3
0
    def test_store_selection_properties(self):
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            f = Folder()
            f.id = 'Holidays'
            f.title = 'Holiday Calendar'
            app._setObject(f.id, f, set_owner=0)
            transaction.commit()

            f._setProperty('choices', ['alpha', 'omega', 'delta'], 'lines')
            f._setProperty('greek', 'choices', 'multiple selection')
            f._setProperty('hebrew', 'choices', 'selection')
            f.greek = ['alpha', 'omega']
            f.hebrew = 'alpha'
            transaction.commit()

            conn2 = self.db.open()
            try:
                app = conn2.root()['Application']
                self.assert_(hasattr(app, 'Holidays'))
                got = 0
                for k, v in app.Holidays.propertyItems():
                    if k == 'greek':
                        got += 1
                        self.assertEqual(tuple(v), ('alpha', 'omega'))
                    if k == 'hebrew':
                        got += 1
                        self.assertEqual(v, 'alpha')
                self.assertEqual(got, 2)
                # Be sure the select_variable got restored.
                dict = app.Holidays.propdict()
                self.assertEqual(dict['greek']['select_variable'], 'choices')
                self.assertEqual(dict['hebrew']['select_variable'], 'choices')
            finally:
                conn2.close()

        finally:
            conn.close()
Beispiel #4
0
    def test_store_selection_properties(self):
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            f = Folder()
            f.id = 'Holidays'
            f.title = 'Holiday Calendar'
            app._setObject(f.id, f, set_owner=0)
            transaction.commit()

            f._setProperty('choices', ['alpha', 'omega', 'delta'], 'lines')
            f._setProperty('greek', 'choices', 'multiple selection')
            f._setProperty('hebrew', 'choices', 'selection')
            f.greek = ['alpha', 'omega']
            f.hebrew = 'alpha'
            transaction.commit()

            conn2 = self.db.open()
            try:
                app = conn2.root()['Application']
                self.assert_(hasattr(app, 'Holidays'))
                got = 0
                for k, v in app.Holidays.propertyItems():
                    if k == 'greek':
                        got += 1
                        self.assertEqual(tuple(v), ('alpha', 'omega'))
                    if k == 'hebrew':
                        got += 1
                        self.assertEqual(v, 'alpha')
                self.assertEqual(got, 2)
                # Be sure the select_variable got restored.
                dict = app.Holidays.propdict()
                self.assertEqual(dict['greek']['select_variable'], 'choices')
                self.assertEqual(dict['hebrew']['select_variable'], 'choices')
            finally:
                conn2.close()

        finally:
            conn.close()
Beispiel #5
0
    def test_store_property_types(self):
        # Test that Ape restores properties to the correct types.
        from DateTime import DateTime
        now = DateTime()
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            f = Folder()
            f.id = 'Holidays'
            app._setObject(f.id, f, set_owner=0)
            transaction.commit()

            f._setProperty('string1', 's', 'string')
            f._setProperty('float1', 3.14, 'float')
            f._setProperty('int1', 5, 'int')
            f._setProperty('long1', 2L**33, 'long')
            f._setProperty('date1', now, 'date')
            f._setProperty('date2', now, 'date_international')
            f._setProperty('text1', 'abc\ndef', 'text')
            f._setProperty('boolean0', 0, 'boolean')
            f._setProperty('boolean1', 1, 'boolean')
            transaction.commit()

            conn2 = self.db.open()
            try:
                app2 = conn2.root()['Application']
                f2 = app2.Holidays
                self.assertEqual(f2.string1, 's')
                self.assertEqual(f2.float1, 3.14)
                self.assertEqual(f2.int1, 5)
                self.assertEqual(f2.long1, 2L**33)
                self.assertEqual(f2.date1.ISO(), now.ISO())
                self.assertEqual(f2.date2.ISO(), now.ISO())
                self.assertEqual(f2.text1, 'abc\ndef')
                self.assertEqual(f2.boolean0, 0)
                self.assertEqual(f2.boolean1, 1)
            finally:
                conn2.close()

        finally:
            conn.close()
Beispiel #6
0
    def test_store_property_types(self):
        # Test that Ape restores properties to the correct types.
        from DateTime import DateTime
        now = DateTime()
        conn = self.db.open()
        try:
            app = conn.root()['Application']
            f = Folder()
            f.id = 'Holidays'
            app._setObject(f.id, f, set_owner=0)
            transaction.commit()

            f._setProperty('string1', 's', 'string')
            f._setProperty('float1', 3.14, 'float')
            f._setProperty('int1', 5, 'int')
            f._setProperty('long1', 2L**33, 'long')
            f._setProperty('date1', now, 'date')
            f._setProperty('date2', now, 'date_international')
            f._setProperty('text1', 'abc\ndef', 'text')
            f._setProperty('boolean0', 0, 'boolean')
            f._setProperty('boolean1', 1, 'boolean')
            transaction.commit()

            conn2 = self.db.open()
            try:
                app2 = conn2.root()['Application']
                f2 = app2.Holidays
                self.assertEqual(f2.string1, 's')
                self.assertEqual(f2.float1, 3.14)
                self.assertEqual(f2.int1, 5)
                self.assertEqual(f2.long1, 2L**33)
                self.assertEqual(f2.date1.ISO(), now.ISO())
                self.assertEqual(f2.date2.ISO(), now.ISO())
                self.assertEqual(f2.text1, 'abc\ndef')
                self.assertEqual(f2.boolean0, 0)
                self.assertEqual(f2.boolean1, 1)
            finally:
                conn2.close()

        finally:
            conn.close()