def test_db_visit_and_update(create_db):
    """this is the same as test_00_insert_update
    but using visit_summary triggers"""
    lsql = lncdSql(None, conn=ph(create_db.connection))
    time = dt.datetime.now()
    newtime = time + dt.timedelta(days=3)
    fake_visit = {
        'pid': 1,
        'study': 'AStudy',
        'vtimestamp': time,
        'vtype': 'Scan',
        'cohort': 'control',
        'ra': 'ra1',
        'notes': None
    }
    lsql.insert('visit_summary', fake_visit)
    assert create_db.connection.\
        execute('select vtimestamp from visit where vid = 1').\
        scalar() == time

    lsql.update(table_name='visit',
                new_column='vtimestamp',
                id_value=1,
                new_value=newtime,
                id_column='vid')

    assert create_db.connection.\
        execute('select vtimestamp from visit where vid = 1').\
        scalar() == newtime
Ejemplo n.º 2
0
def test_getuser(create_db):
    """test that fullnames gets to addperson when buttons clicked"""

    sql = lncdSql(config=None, conn=ph(create_db.connection))
    assert sql.db_user is not None
    # test db user is always postgres
    assert sql.db_user == 'postgres'
def test_db_visit_and_note(create_db):
    """ add a note with visit_summary
    tests json insert with sqlalchemy"""
    lsql = lncdSql(None, conn=ph(create_db.connection))
    time = dt.datetime.now()
    fake_visit = {
        'pid': 1,
        'study': 'AStudy',
        'vtimestamp': time,
        'vtype': 'Scan',
        'cohort': 'control',
        'ra': 'ra1',
        'notes': ['test Note']
    }
    lsql.insert('visit_summary', fake_visit)

    # added visit
    assert create_db.connection.\
        execute('select vtimestamp from visit where vid = 1').\
        scalar() == time

    # added note
    assert create_db.connection.\
        execute('select vid from note where vid = 1').\
        scalar() == 1
Ejemplo n.º 4
0
def test_list_ras(create_db):
    """
    check query.list_ras()
     -- by itself, not that useful. But guide for testing other sql tests
    (create_db in conftest.py, autoloaded by pytest)
    """
    ras = lncdSql(None, conn=ph(create_db.connection)).\
        query.list_ras()
    check_column(0, ras, ['ra1', 'ra2', 'ra3', 'ra4'])
def test_lsql_tblinsert(create_db):
    """ test with with lsql """
    lsql = lncdSql(None, conn=ph(create_db.connection))
    fake_contact = {'pid': 2, 'cid': 6,
                    'ctype': 'address', 'cvalue': 'nowhere',
                    'who': 'PersonPlaceThing', 'relation': 'None'}
    lsql.insert('contact', fake_contact)
    nowhere = create_db.\
        connection.execute('select cvalue from contact where cid = 6').scalar()
    assert nowhere == 'nowhere'
def test_sqla_tblins(create_db):
    """ test with without lsql """
    import sqlalchemy as sqla
    lsql = lncdSql(None, conn=ph(create_db.connection))
    tbl = sqla.Table('contact', lsql.sqlmeta, autoload=True,
                     autoload_with=lsql.conn.connection)
    fake_contact = {'pid': 1, 'cid': 5,
                    'ctype': 'address', 'cvalue': 'nowhere',
                    'who': 'PersonPlaceThing', 'relation': 'None'}
    ins = tbl.insert(fake_contact)
    lsql.conn.execute(ins)
def test_lsql_update(create_db):
    """ test with with lsql """
    lsql = lncdSql(None, conn=ph(create_db.connection))
    fake_contact = {'pid': 2, 'cid': 7,
                    'ctype': 'address', 'cvalue': 'nowhere',
                    'who': 'PersonPlaceThing', 'relation': 'None'}
    lsql.insert('contact', fake_contact)
    lsql.update(table_name='contact', new_column='cvalue', id_value=7,
                new_value='everywhere', id_column='cid')
    assert create_db.\
        connection.execute('select cvalue from contact where cid = 7').\
        scalar() == 'everywhere'
Ejemplo n.º 8
0
def lncdapp(create_db):
    """
    creates db when used as param in any 'test_fucntion'
    returns transacted_postgresql_db so it doesn't also have to be included
    expects `sql/` directory to be available
    """
    from schedule import ScheduleApp
    win = ScheduleApp(sql_obj=ph(create_db.connection), cal_obj='Not Used')
    win.pgtest = create_db

    # give back the window
    return win
def test_lsql_update_dict(create_db):
    """ test updating with a dictionary """
    lsql = lncdSql(None, conn=ph(create_db.connection))
    fake_contact = {'pid': 2, 'cid': 7,
                    'ctype': 'address', 'cvalue': 'nowhere',
                    'who': 'PersonPlaceThing', 'relation': 'None'}
    lsql.insert('contact', fake_contact)
    lsql.update_columns(table_name='contact', id_column='cid', id_value=7,
                        update_dict={'cvalue': '555', 'ctype': 'phone'})
    assert create_db.\
        connection.execute('select cvalue from contact where cid = 7').\
        scalar() == '555'
    assert create_db.\
        connection.execute('select ctype from contact where cid = 7').\
        scalar() == 'phone'