Пример #1
0
    def test_connect(self):
        '''Create schema, add, delete. Test the add and the delete'''
        insp = Inspire(lname='The Dude',
                       subject='On Peace',
                       name='The Dude',
                       who='THE authority on life',
                       quote='This aggression will not stand, man.')
        ModelBase.connect(new_session=True, con_str=self.con_str)
        ModelBase.createAll()
        session = ModelBase.session
        session.add(insp)
        session.commit()
        session.close()

        ModelBase.connect(new_session=True, con_str=self.con_str)
        session = ModelBase.session
        q = session.query(Inspire).all()
        self.assertEqual(q[0].quote, 'This aggression will not stand, man.')
        self.assertEqual(len(q), 1)

        session.delete(q[0])
        session.commit()
        session.close()

        ModelBase.connect(new_session=True, con_str=self.con_str)
        session = ModelBase.session
        q = session.query(Inspire).all()
        self.assertEqual(len(q), 0)
        session.close()
Пример #2
0
    def getTableNames(self):
        if not ModelBase.engine:
            ModelBase.connect(new_session=True)
            ModelBase.createAll()
        inspector = inspect(ModelBase.engine)

        tns = inspector.get_table_names()
        return tns
Пример #3
0
 def createTables(self):
     ModelBase.connect(new_session=True, db='structjourDb')
     ModelBase.createAll()
     try:
         Source.addSource('default', 1)
         Source.addSource('user', 2)
         Source.addSource('contrib', 3)
         logging.info('Creating standard Strategy Source entries')
     except Exception:
         logging.info('Standard Strategy Source entries have already been created')
Пример #4
0
    def createTables(self):
        '''
        Creates the api_keys if it doesnt exist then adds a row for each api that requires a key
        if they dont exist
        '''
        ModelBase.connect(new_session=True)

        ModelBase.createAll()
        curapis = ['fh', 'av', 'bc', 'tgo']      # When this info changes, Use the apisettings control to abstract the data
        addit = False
        for api in curapis:
            key = ApiKey.getKey(api, keyonly=False)
            if not key:
                ApiKey.addKey(api)
Пример #5
0
    def setUpClass(cls):
        bu = Backup()
        bu.backup()
        print(
            f'Files have been backed up. Most recent back is {bu.mostRecent()}'
        )
        settings = QSettings('zero_substance', 'structjour')
        tdb = settings.value('tradeDb')
        # if tdb and os.path.exists(tdb):
        #     os.remove(tdb)
        # sdb = settings.value('structjourDb')
        # if sdb and os.path.exists(sdb):
        #     os.remove(sdb)

        ModelBase.connect(new_session=True)
        ModelBase.createAll()
Пример #6
0
    def loadQuotes(cls, inspireQuote):
        '''
        This is a one-off to load the quotes in the inspiration.inspire.Inspire class.
        Its a one-off becasue we have to seperate 2 fields from one. If the quote
        already exists, leave it and skip it.
        '''
        ModelBase.connect(new_session=True)
        session = ModelBase.session
        ModelBase.createAll()
        for i, row in inspireQuote.df.iterrows():
            # print(row['name'])
            test = row['who'].split(", ")
            if len(test) != 2:
                msg = f"ERROR: bad data in quote: {row}"
                logging.error(msg)
                print(msg)
                continue
            name, who = test

            q = ModelBase.session.query(Inspire).filter_by(
                quote=row['quote']).first()
            if q:
                print(f'found a duplicate for quote: {q.quote}')
                continue
            qte = Inspire(lname=row['name'],
                          subject=row['on'],
                          name=name,
                          who=who,
                          quote=row['quote'])

            session.add(qte)

            try:
                session.commit()
            except:
                pass
        session.close()
class Migration:
    min_version = '0.9.92a002'
    version = version
    dependencies = [
        TradeSum,
    ]

    # Better, more central location to call createAll? Have to accomodate migrations that use Sessions
    # and migrations that use engine.connect
    operations = [
        ModelBase.connect(new_session=True),
        ModelBase.createAll(),
        ModelBase.checkVersion(min_version, version),
        Migrate.doUpdate()
    ]
Пример #8
0
 def createTable(self):
     '''create db table'''
     ModelBase.connect(new_session=True, db=self.db)
     ModelBase.createAll()
Пример #9
0
 def createTable(self):
     ModelBase.connect(new_session=True)
     ModelBase.createAll()