示例#1
0
def _testCreateDupName(conn):
    logger.log("running CreateDupName")
    _insert_data = { "store_name": "store 1", "store_type": "GitHub", "description": "test data -1"}
    req = requests.post(api_path, data = _insert_data)
    rsp_msg = json.loads(req.text)["message"]
    if not rsp_msg.startswith("Duplicate entry"):
        return logger.failed("CreateDupName expected dup failure, got code:", req.status_code, "message:", req.text)
    db.sql(conn, "rollback")
    return True
示例#2
0
def main(cfg):
    global api_path
    api_path = cfg.api_base + "/catalog/roles"
    logger.log("Testing API on roles, api path: %s", api_path)
    conn = db.connect(cfg)

    # cleanup test data
    for x in xrange(test_recs_count):
        _delete(conn, _role_name(x + 1))

#db.sql(conn, "delete from roles where class = 'test'")
    db.sql(conn, "commit")

    # ---------------------------------------- Create
    id_recs = _testCreateNew(conn, test_recs_count)
    if not id_recs:
        return False

    if not _testCreateDupName(conn):
        return False

    # ---------------------------------------- Read
    #print "++", id_recs
    db_roles = [Role(_read(conn, id_rec["name"])[0]) for id_rec in id_recs]

    logger.log("running Read")
    for db_role in db_roles:
        if not _testRead(db_role):
            return False

    # ---------------------------------------- Update
    time.sleep(1)  # ensure modified_ts has been promoted
    logger.log("running Update")
    if not _testUpdate(conn, 2, db_roles[1]):
        return False

    if not _testUpdateNonExisted(conn, db_roles[0]):
        return False

    # ---------------------------------------- Delete
    logger.log("running Delete")
    for db_role in db_roles:
        if not _testDelete(conn, db_role):
            return False

    if not _testDeleteNonExisted(conn, db_roles[0]):
        return False

    #rows = db.sql(conn, "select 1+%s", 44)
    #logger.log("rows: %s", rows)
    #db.sql(conn, "commit")
    db.disconnect(conn)
    return True
示例#3
0
def _testCreateDupAsset(conn):
    logger.log("running CreateDupName")
    _insert_data = {
        "role_name": _asset_name(1),
        "class": "test",
        "role_schema": _asset_schema(1)
    }
    req = requests.post(api_path, json=_insert_data)
    if req.status_code != 409:
        return logger.failed("CreateDupName expected dup failure, got code:",
                             req.status_code, "message:", req.text)
    db.sql(conn, "rollback")
    return True
示例#4
0
def main(cfg):
    global api_path
    api_path = cfg.api_base + "/catalog/assets"
    logger.log("Testing API on assets, api path: %s", api_path)
    conn = db.connect(cfg)

    # cleanup test data
    for x in xrange(test_rec_count):
        _delete(conn, _asset_name(x + 1))
    db.sql(conn, "commit")

    # ---------------------------------------- Create Asset
    asset_recs = _testCreateAsset(conn, test_rec_count)
    if not asset_recs:
        return False

    if not _testCreateDupAsset(conn):
        return False

    # ---------------------------------------- Read
    #print "++", id_recs
    #asset_recs = [ Role(_read(conn, id_rec["name"])[0]) for id_rec in id_recs ]

    logger.log("running Read")
    for asset_rec in asset_recs:
        if not _testRead(asset_rec):
            return False

    # ---------------------------------------- Update
    time.sleep(1)  # ensure modified_ts has been promoted
    logger.log("running Update")
    if not _testUpdate(conn, 2, asset_recs[1]):
        return False

    if not _testUpdateNonExisted(conn, asset_recs[0]):
        return False

    # ---------------------------------------- Delete
    logger.log("running Delete")
    for asset_rec in asset_recs:
        if not _testDelete(conn, asset_recs):
            return False

    if not _testDeleteNonExisted(conn, asset_recs[0]):
        return False

    #rows = db.sql(conn, "select 1+%s", 44)
    #logger.log("rows: %s", rows)
    #db.sql(conn, "commit")
    db.disconnect(conn)
    return True
示例#5
0
def main(cfg):
    global api_path
    api_path = cfg.api_base + "/admin/data/script_stores"
    logger.log("Testing CRUD operations on script_stores, API path: %s", api_path)
    conn = db.connect(cfg)

    # cleanup test data
    for x in xrange(test_recs_count):
        _delete(conn, "store "+str(x+1))
    db.sql(conn, "commit")

    # ---------------------------------------- Create
    apiStoreIds = _testCreateNew(conn, test_recs_count)
    if not apiStoreIds:
        return False

    if not _testCreateDupName(conn):
        return False

    # ---------------------------------------- Read
    dbStores = [ ScriptStore(_read(conn, apiStoreId["uuid_pk"])[0]) for apiStoreId in apiStoreIds]

    logger.log("running Read")
    for dbStore in dbStores:
        if not _testRead(conn, dbStore):
            return False

    # ---------------------------------------- Update
    time.sleep(1)  # ensure modified_ts is greater
    logger.log("running Update")
    for dbStore in dbStores:
        if not _testUpdate(conn, dbStore):
            return False

    if not _testUpdateNonExisted(conn, dbStores[0]):
        return False

    # ---------------------------------------- Delete
    logger.log("running Delete")
    for dbStore in dbStores:
        if not _testDelete(conn, dbStore):
            return False

    if not _testDeleteNonExisted(conn, dbStores[0]):
        return False

    #rows = db.sql(conn, "select 1+%s", 44)
    #logger.log("rows: %s", rows)
    #db.sql(conn, "commit")
    db.disconnect(conn)
    return True
示例#6
0
def _read(conn, pk):
    recs = db.sql(
        conn, """
        select hex(asset_id), name, description, created_by, created_ts, modified_by, modified_ts
          from assets
         where asset_id = %s""", pk.bytes)
    if recs == 0:
        return None
    asset_record = AssetRecord(Asset(recs[0]))
    recs = db.sql(
        conn, """
        select hex(asset_id), role_name, asset_vals, created_by, created_ts, modified_by, modified_ts
          from asset_role_values
         where asset_id = %s""", pk.bytes)
    asset_record.asset_role_values_arr = [AssetRoleValues(r) for r in recs]
    return asset_record
示例#7
0
def _read(conn, pk):
    return db.sql(
        conn, """
        select name, class, role_schema, description,
               created_by, created_ts, modified_by, modified_ts
          from roles
         where name = %s""", pk)
示例#8
0
def _testCreateNew(conn, how_many):
    logger.log("running CreateNew for %d entities", how_many)
    identities = []
    for k in xrange(how_many):
        ks = str(k+1)
        _insert_data = { "store_name": "store "+ks, "store_type": "LocalFile", "description": "test data "+ks}
        req = requests.post(api_path, data = _insert_data)
        if not req.ok:
            return logger.failed("CreateNew expected {200, OK}, got code:", req.status_code, "response:", req.text)
        rsp_msg = json.loads(req.text)["message"]
        id_obj = {
            "script_store_id": str(rsp_msg["pk"]["script_store_id"]),
            "modified_ts":     str(rsp_msg["optLock"]["modified_ts"]),
            "uuid_pk":         uuid.UUID(str(rsp_msg["pk"]["script_store_id"]))
        }
        identities.append(id_obj)

    db.sql(conn, "commit")
    return identities
示例#9
0
def _testCreateAsset(conn, how_many):
    logger.log("running CreateAsset for %d entities", how_many)
    identities = []
    for k in xrange(how_many):
        role_name = _asset_name(k + 1)
        _insert_data = {
            "role_name": role_name,
            "class": "test",
            "role_schema": _asset_schema(k + 1),
            "description": "test role " + str(k + 1)
        }
        req = requests.post(api_path, json=_insert_data)
        if not req.ok:
            return logger.failed("CreateNew expected {200, OK}, got code:",
                                 req.status_code, "response:", req.text)
        rsp_msg = json.loads(req.text)
        id_obj = {
            "name": str(rsp_msg["pk"]["role_name"]),
            "modified_ts": str(rsp_msg["optLock"]["modified_ts"])
        }
        identities.append(id_obj)

    db.sql(conn, "commit")
    return identities
示例#10
0
def _delete(conn, asset_name):
    db.sql(
        conn, """delete from asset_role_values where asset_id in
            (select asset_id from assets where name = %s)""" % asset_name)
    db.sql(conn, """delete from assets where name = %s)""" % asset_name)
示例#11
0
def _delete(conn, role_name):
    return db.sql(conn, "delete from roles where name = '%s'" % role_name)
def _delete(conn, asset_name):
    db.sql(
        conn, """delete from asset_role_values where asset_id in
            (select asset_id from assets where name = '%s')""" % asset_name)
    db.sql(conn, """delete from assets where name = '%s'""" % asset_name)
    conn.commit()
示例#13
0
def _delete(conn, store_name):
    return db.sql(conn,"""delete from script_stores where store_name = %s""", store_name)
示例#14
0
def _read(conn, pk):
    return db.sql(conn,"""
        select hex(script_store_id), store_name, store_type, description,
               created_by, created_ts, modified_by, modified_ts
          from script_stores
         where script_store_id = %s""", pk.bytes)