Example #1
0
 def get_audit_ids_by_date(cls, target_type, target_id, date):
     db = DBSession()
     rs = db.query(cls.audit_id).filter(
         cls.target_id == target_id,
         cls.target_type == target_type,
         cast(cls.created_at, DATE) == date
     )
     return sorted((r[0] for r in rs), reverse=True)
Example #2
0
 def get_audit_ids(cls, instance_type, application_id, cluster_name,
                   instance_key):
     """Get ids of :class:`.audit.AuditLog` by instance information.
     Regardless of cluster if the ``cluster_name`` is ``None``
     """
     db = DBSession()
     rs = db.query(cls.audit_id).filter_by(
         instance_type=instance_type, application_id=application_id,
         cluster_name=cluster_name, instance_key=instance_key)
     return sorted((r[0] for r in rs), reverse=True)
Example #3
0
def test_upsert(team_point, mocker):
    session = DBSession()

    assert session.query(team_point.__class__.id).all() == [
        (team_point.id,),
    ]

    session.execute(core_db.Upsert(team_point.__table__).values(
        id=team_point.id, team_name='666'))

    assert session.query(team_point.__class__.id).all() == [
        (team_point.id,),
    ]

    session.execute(core_db.Upsert(team_point.__table__).values(
        id=team_point.id + 1, team_name='888'))

    assert session.query(team_point.__class__.id).all() == [
        (team_point.id,),
        (team_point.id + 1,),
    ]

    columns = Team.__table__.primary_key.columns

    class Mocked(object):
        def __len__(self):
            return 0

        def __getattr__(self, item):
            return getattr(columns, item)

    with mocker.patch.object(
        Team.__table__.primary_key, 'columns',
            mocker.MagicMock(return_value=Mocked)):
        session.execute(core_db.Upsert(team_point.__table__).values(
            id=team_point.id + 2, team_name='999'))
Example #4
0
 def get_audit_ids(cls, target_type, target_id):
     db = DBSession()
     rs = db.query(cls.audit_id).filter_by(
         target_id=target_id, target_type=target_type)
     return sorted((r[0] for r in rs), reverse=True)
Example #5
0
def check_mysql():
    if is_minimal_mode():
        print('minimal mode detected')
        return
    db = DBSession()
    assert db.query(func.count(ApplicationAuth.id)).scalar(), 'mysql not ok'