Esempio n. 1
0
def test_tables(testdb_initialized_tables):
    assert testdb_initialized_tables
    util.verify_testdb()
    sms.setup("2018")

    conn = smc.engine.connect()
    sql = ("SELECT * FROM information_schema.tables "
           "WHERE table_schema = 'public';")
    tables = pandas.read_sql_query(sql, conn)
    assert tables.shape == (19, 12)

    def test_table(table, shape):
        sql = "SELECT * FROM " + table + ";"
        dframe = pandas.read_sql_query(sql, conn)
        assert dframe.shape[0] >= shape[0]  # Check rows
        assert dframe.shape[1] == shape[1]  # Check columns

    test_table("levels", (3, 2))
    test_table("matches", (168, 2))
    test_table("alliances", (3, 2))
    test_table("dates", (1, 3))
    test_table("teams", (1, 7))
    test_table("stations", (4, 2))
    test_table("actors", (7, 2))
    test_table("tasks", (36, 4))
    test_table("measuretypes", (8, 2))
    test_table("phases", (5, 2))
    test_table("attempts", (31, 2))
    test_table("reasons", (4, 2))
    test_table("task_options", (10, 4))
Esempio n. 2
0
def test_upsert_rows(testdb_empty_tables):
    assert testdb_empty_tables
    util.verify_testdb()

    conn = smc.engine.connect()
    smu.upsert_rows("matches", "name", 25, "{0:0>3}-q")
    sql = "SELECT * FROM matches;"
    matches = pandas.read_sql_query(sql, conn)
    assert matches.shape == (24, 2)
    assert matches.name[0] == "001-q"

    # Teardown
    delete_all_rows("matches", conn)
    conn.close()
Esempio n. 3
0
def test_upsert_cols(testdb_empty_tables):
    assert testdb_empty_tables
    util.verify_testdb()

    conn = smc.engine.connect()
    smu.upsert_cols("task_options", {
        "task_name": "na",
        "type": "capability",
        "option_name": "na"
    })
    sql = "SELECT * FROM task_options;"
    tasks = pandas.read_sql_query(sql, conn)
    assert tasks.task_name[0] == "na"
    assert tasks.type[0] == "capability"
    assert tasks.option_name[0] == "na"
    assert tasks.shape == (1, 4)

    # Teardown
    delete_all_rows("task_options", conn)
    conn.close()
Esempio n. 4
0
def test_upsert(testdb_empty_tables):
    assert testdb_empty_tables
    util.verify_testdb()
    conn = smc.engine.connect()

    smu.upsert("actors", "name", "upsert_test1")
    smu.upsert("actors", "name", "upsert_test2")

    sql_count = sqlalchemy.text("SELECT COUNT(*) FROM actors;")
    count = conn.execute(sql_count).scalar()
    assert count == 2

    sql_sel = "SELECT * FROM actors;"
    actors = pandas.read_sql_query(sql_sel, conn)
    assert actors.shape == (2, 2)
    assert actors.name[0] == "upsert_test1"

    # Teardown
    delete_all_rows("actors", conn)
    conn.close()