def test_update_table_column(): ctx = reload.context() fn = "/tmp/ssd1.csv" fn2 = "/tmp/ssd2.csv" csv1 = [[i, i] for i in range(10)] csv2 = [[i, i + 1] for i in range(1, 11)] n = len(csv1) n2 = len(csv2) write_csv(fn, ["ProposalID", "siteNumber"], csv1) write_csv(fn2, ["ProposalID", "siteNumber"], csv2) try: reload._updateDataIntoTableColumn(ctx, "SiteInformation", "ProposalID", fn, {}) rows = reload.readDataFromTable(ctx, "SiteInformation") assert (bag_contains(rows, [{ "siteNumber": str(row[1]), "ProposalID": str(row[0]) } for row in csv1])) reload._updateDataIntoTableColumn(ctx, "SiteInformation", "ProposalID", fn2, {}) rows = reload.readDataFromTable(ctx, "SiteInformation") assert (bag_contains(rows, [{ "siteNumber": str(row[1]), "ProposalID": str(row[0]) } for row in csv1 if row[0] not in list(map(lambda x: x[0], csv2))] + [{ "siteNumber": str(row[1]), "ProposalID": str(row[0]) } for row in csv2])) finally: reload.clearDatabase(ctx) reload.createTables(ctx) os.unlink(fn) os.unlink(fn2)
def table(tablename): if request.method == "GET": logger.info("get table") return json.dumps(reload.readDataFromTable(ctx, tablename)) elif request.method == "PUT": logger.info("put table") return handleTable(reload.updateDataIntoTable, ctx, tablename) else: logger.info("post table") return handleTable(reload.insertDataIntoTable, ctx, tablename)
def do_test_insert_table(src, kvp, has_comments=False): ctx = reload.context() n = countrows(src, "text/csv") - (1 if has_comments else 0) try: reload.insertDataIntoTable(ctx, "SiteInformation", src, kvp) rows = reload.readDataFromTable(ctx, "SiteInformation") assert (bag_contains(rows, [{ "siteNumber": str(i), **kvp } for i in range(1, n + 1)])) reload.insertDataIntoTable(ctx, "SiteInformation", src, kvp) rows = reload.readDataFromTable(ctx, "SiteInformation") assert (bag_contains(rows, [{ "siteNumber": str(i), **kvp } for i in range(1, n + 1)] * 2)) finally: reload.clearDatabase(ctx) reload.createTables(ctx)