Example #1
0
 def create_instance(self, code):
     instanceconfig = Bag(self.pkg.instance_template())
     instanceconfig.setAttr('hosted', instance=code)
     instanceconfig.setAttr('db', dbname=code)
     base_path = os.path.dirname(self.pkg.instance_folder(code))
     im = InstanceMaker(code, base_path=base_path, config=instanceconfig)
     im.do()
     return im.instance_path
Example #2
0
 def create_instance(self, code):
     instanceconfig = Bag(self.pkg.instance_template())
     instanceconfig.setAttr('hosted', instance=code)
     instanceconfig.setAttr('db', dbname=code)
     base_path = os.path.dirname(self.pkg.instance_folder(code))
     im = InstanceMaker(code, base_path=base_path, config=instanceconfig)
     im.do()
     return im.instance_path
Example #3
0
 def test_attributes(self):
     #set & get
     b = Bag(BAG_DATA)
     b.setAttr('phone.home', private=False)
     assert not b.getAttr('phone.home', 'private')
     b.setAttr('phone.home', private=True, test='is a test')
     assert b['phone.home?test'] == 'is a test' #diverso dalla documentazione track
     assert b.getAttr('phone.#sim=vadophone', 'fbplayer') == 'gattuso'
     assert b['phone.#sim=vadophone?fbplayer'] == 'gattuso'
     b.delAttr('phone.home', 'test')
     assert not b['phone.home?test']
Example #4
0
 def test_attributes(self):
     #set & get
     b = Bag(BAG_DATA)
     b.setAttr('phone.home', private=False)
     assert not b.getAttr('phone.home', 'private')
     b.setAttr('phone.home', private=True, test='is a test')
     assert b[
         'phone.home?test'] == 'is a test'  #diverso dalla documentazione track
     assert b.getAttr('phone.#sim=vadophone', 'fbplayer') == 'gattuso'
     assert b['phone.#sim=vadophone?fbplayer'] == 'gattuso'
     b.delAttr('phone.home', 'test')
     assert not b['phone.home?test']
Example #5
0
class TestAttributeBag(unittest.TestCase):
    def setUp(self):
        self.fullbag = Bag(
            {
                "office": Bag({"John": Bag(), "Frank": Bag(), "Alexandra": Bag()}),
                "friends": Bag({"Henry": Bag(), "Fred": Bag()}),
                "relatives": Bag({"Karla": Bag(), "Albert": Bag()}),
            }
        )
        self.fullbag["office"].setItem("Xavier", Bag(), fromdate="9-15-2005", role="researcher")
        self.fullbag["office"].setAttr("Frank", fromdate="3-5-1998", role="developer")
        self.fullbag["office"].setAttr("John", fromdate="2-1-1990", role="boss", age=55)

    def testattributes(self):
        self.assertEqual(self.fullbag["office"].getAttr("Xavier", "role"), "researcher")
        self.assertEqual(self.fullbag["office.Frank?a:role"], "developer")
        l = [("Frank", "developer"), ("John", "boss"), ("Alexandra", None), ("Xavier", "researcher")]
        self.failUnless(self.fullbag["office"].digest("#k,#a.role") == self.fullbag["office.?d:#k,#a.role"] == l)
        self.failUnless(
            self.fullbag["office.Xavier"] == self.fullbag["office.#3"] == self.fullbag["office.#role=researcher"]
        )

    def testBagNodes(self):
        self.fullbag.delAttr("office.John", "age")
        n = self.fullbag.getNode("office.John")
        self.assertTrue(n.hasAttr("role"))
        self.assertFalse(n.hasAttr("age"))
        self.assertEqual(n, self.fullbag.getNodeByAttr("role", "boss"))

    def testgetNodeByAttr(self):
        researcher = self.fullbag.getNodeByAttr("role", "researcher")
        self.assertEqual(researcher, self.fullbag.getNode("office.Xavier"))

    def testfromToXml(self):
        self.fullbag["relatives.Karla.birthday"] = datetime.date(1952, 12, 10)
        self.fullbag["relatives.Karla.pierciengs"] = 0
        self.fullbag["relatives.Karla.dogname"] = ""
        self.fullbag.setAttr("relatives.Karla", age=54)
        self.fullbag.toXml("mybag.xml")
        x = self.fullbag["relatives"].toXml()
        b = Bag(x)
        self.assertEqual(b.asString(), self.fullbag["relatives"].asString())

    def testsfromSource(self):
        current = os.getcwd()
        fromlocal_std = Bag("%s/test_files/standardxml.xml" % current)
        self.assertTrue(isinstance(fromlocal_std, Bag))
        # non riesce a printarla per carattere non encodabile
        fromlocal_bag = Bag("%s/test_files/mybag.xml" % current)
        self.assertTrue(isinstance(fromlocal_bag, Bag))
        # uncomment the following test if you are online
        # fromurl=Bag('http://www.plone.org')
        # self.assertTrue(isinstance(fromurl, Bag))
        stringxml = '<?xml version="1.02" encoding="UTF-8"?><a><b name="fuffy"><d>dog</d></b><c/></a>'
        fromstringxml = Bag(stringxml)
        self.assertTrue(isinstance(fromstringxml, Bag))
        fromdirectory = Bag("%s/test_files" % current)
        self.assertTrue(isinstance(fromdirectory, Bag))

    def testmerge(self):
        newbag = Bag()
        newbag.setItem("Henry", self.fullbag["friends.Henry"], role="documentation and tests")
        newbag.setItem("Xavier", "Mr Xavier", role="documentation manager", age=26)
        allflagstrue = self.fullbag["office"].merge(newbag)  # all flags true
        allflagsfalse = self.fullbag["office"].merge(
            newbag, upd_values=False, add_values=False, upd_attr=False, add_attr=False
        )
        self.assertEqual(allflagsfalse.asString(), self.fullbag["office"].asString())
        notupdatevalues = self.fullbag["office"].merge(newbag, upd_values=False)
        self.assertTrue(isinstance(self.fullbag["office.Xavier"], Bag))
        notaddvalues = self.fullbag["office"].merge(newbag, add_values=False)
        self.assertEqual(len(self.fullbag["office"].items()), len(notaddvalues.items()))
        notupdateattrs = self.fullbag["office"].merge(newbag, upd_attr=False)
        self.assertEqual(self.fullbag["office.Xavier?a:role"], notupdateattrs["Xavier?a:role"])
        notaddattrs = self.fullbag["office"].merge(newbag, add_attr=False)
        self.assertFalse(notaddattrs.getAttr("Xavier", "age", default=False))

    def testsum(self):
        numbers = Bag()
        numbers.setItem("first", 20, height=22)
        numbers.setItem("second", 30, height=342)
        self.assertEqual(numbers.sum("#v,#a.height"), [50, 364])
Example #6
0
class TestAttributeBag(unittest.TestCase):
    def setUp(self):
        self.fullbag = Bag({
            'office':
            Bag({
                'John': Bag(),
                'Frank': Bag(),
                'Alexandra': Bag()
            }),
            'friends':
            Bag({
                'Henry': Bag(),
                'Fred': Bag()
            }),
            'relatives':
            Bag({
                'Karla': Bag(),
                'Albert': Bag()
            })
        })
        self.fullbag['office'].setItem('Xavier',
                                       Bag(),
                                       fromdate='9-15-2005',
                                       role='researcher')
        self.fullbag['office'].setAttr('Frank',
                                       fromdate='3-5-1998',
                                       role='developer')
        self.fullbag['office'].setAttr('John',
                                       fromdate='2-1-1990',
                                       role='boss',
                                       age=55)

    def testattributes(self):
        self.assertEqual(self.fullbag['office'].getAttr('Xavier', 'role'),
                         'researcher')
        self.assertEqual(self.fullbag['office.Frank?a:role'], 'developer')
        l = [('Frank', 'developer'), ('John', 'boss'), ('Alexandra', None),
             ('Xavier', 'researcher')]
        self.failUnless(self.fullbag['office'].digest('#k,#a.role') ==
                        self.fullbag['office.?d:#k,#a.role'] == l)
        self.failUnless(
            self.fullbag['office.Xavier'] == self.fullbag['office.#3'] ==
            self.fullbag['office.#role=researcher'])

    def testBagNodes(self):
        self.fullbag.delAttr('office.John', 'age')
        n = self.fullbag.getNode('office.John')
        self.assertTrue(n.hasAttr('role'))
        self.assertFalse(n.hasAttr('age'))
        self.assertEqual(n, self.fullbag.getNodeByAttr('role', 'boss'))

    def testgetNodeByAttr(self):
        researcher = self.fullbag.getNodeByAttr('role', 'researcher')
        self.assertEqual(researcher, self.fullbag.getNode('office.Xavier'))

    def testfromToXml(self):
        self.fullbag['relatives.Karla.birthday'] = datetime.date(1952, 12, 10)
        self.fullbag['relatives.Karla.pierciengs'] = 0
        self.fullbag['relatives.Karla.dogname'] = ''
        self.fullbag.setAttr('relatives.Karla', age=54)
        self.fullbag.toXml('mybag.xml')
        x = self.fullbag['relatives'].toXml()
        b = Bag(x)
        self.assertEqual(b.asString(), self.fullbag['relatives'].asString())

    def testsfromSource(self):
        current = os.getcwd()
        fromlocal_std = Bag('%s/test_files/standardxml.xml' % current)
        self.assertTrue(isinstance(fromlocal_std, Bag))
        #non riesce a printarla per carattere non encodabile
        fromlocal_bag = Bag('%s/test_files/mybag.xml' % current)
        self.assertTrue(isinstance(fromlocal_bag, Bag))
        #uncomment the following test if you are online
        #fromurl=Bag('http://www.plone.org')
        #self.assertTrue(isinstance(fromurl, Bag))
        stringxml = '<?xml version="1.02" encoding="UTF-8"?><a><b name="fuffy"><d>dog</d></b><c/></a>'
        fromstringxml = Bag(stringxml)
        self.assertTrue(isinstance(fromstringxml, Bag))
        fromdirectory = Bag('%s/test_files' % current)
        self.assertTrue(isinstance(fromdirectory, Bag))

    def testmerge(self):
        newbag = Bag()
        newbag.setItem('Henry',
                       self.fullbag['friends.Henry'],
                       role='documentation and tests')
        newbag.setItem('Xavier',
                       'Mr Xavier',
                       role='documentation manager',
                       age=26)
        allflagstrue = self.fullbag['office'].merge(newbag)  #all flags true
        allflagsfalse = self.fullbag['office'].merge(newbag,
                                                     upd_values=False,
                                                     add_values=False,
                                                     upd_attr=False,
                                                     add_attr=False)
        self.assertEqual(allflagsfalse.asString(),
                         self.fullbag['office'].asString())
        notupdatevalues = self.fullbag['office'].merge(newbag,
                                                       upd_values=False)
        self.assertTrue(isinstance(self.fullbag['office.Xavier'], Bag))
        notaddvalues = self.fullbag['office'].merge(newbag, add_values=False)
        self.assertEqual(len(self.fullbag['office'].items()),
                         len(notaddvalues.items()))
        notupdateattrs = self.fullbag['office'].merge(newbag, upd_attr=False)
        self.assertEqual(self.fullbag['office.Xavier?a:role'],
                         notupdateattrs['Xavier?a:role'])
        notaddattrs = self.fullbag['office'].merge(newbag, add_attr=False)
        self.assertFalse(notaddattrs.getAttr('Xavier', 'age', default=False))

    def testsum(self):
        numbers = Bag()
        numbers.setItem('first', 20, height=22)
        numbers.setItem('second', 30, height=342)
        self.assertEqual(numbers.sum('#v,#a.height'), [50, 364])
Example #7
0
    def getStoreBagFromModel(self, model_id, filler = None):
        current_storeBag = Bag()

        if not model_id:
            return None

        model = self.db.table('sm.sm_model').record(model_id).output('bag')

        # model rows and cols
        row_columns = '$code,$description,$row_type,$position'
        model_rows = self.db.table('sm.sm_model_row').query(
                columns = row_columns,
                where = '$sm_model__id=:model__id',
                model__id = model_id,
                order_by = '$position'
                ).fetch()

        col_columns = '$code, $description,$field_type'
        model_cols = self.db.table('sm.sm_model_col').query(
                columns = col_columns,
                where = '$sm_model__id=:model__id',
                model__id = model_id,
                order_by = '$position'
                ).fetch()

        # create bag rows, columns. placeholder for formulas
        for r in model_rows:
            current_storeBag.setItem(r['code'], Bag())
            current_storeBag.setAttr(r['code'], row_type = r['row_type'])
            current_storeBag.setAttr(r['code'], 
                             progressive_version = model['progressive_version'])

            # first 2 columns, fixed: 'code', 'description'
            current_storeBag[r['code']].setItem('code', r['code'])
            current_storeBag[r['code']].setAttr('code', row_type = r['row_type'])
            current_storeBag[r['code']].setItem('description', r['description'])

            for c in model_cols:
                current_storeBag[r['code']].setItem(c['code'], '')
                #current_storeBag[r['code']].setAttr(c['code'], row_type = r['row_type'])
                current_storeBag[r['code']].setAttr(c['code'], field_type = c['field_type'])
                # data, formula or description?
                if (r['row_type'] == 'desc'):
                    # description
                    pass
                elif (r['row_type'] == 'formula'):
                    # formula
                    # self.setStoreBagFormula(model_id, current_storeBag, 
                    #                     r['code'], c['code'],
                    #                     formula = None  # get formula from model
                    #                     )
                    current_storeBag[r['code']][c['code']] = '-'
                elif (r['row_type'] == 'data'):
                    # data
                    self.setStoreBagCellValue(current_storeBag, 
                                        r['code'], c['code'], filler)
                else:
                    # Nespresso, what else?
                    print("ERRORE TIPO:", r['code'], c['code'])

        self.calcStoreBag(model_id, current_storeBag)

        return current_storeBag