Example #1
0
async def test_fortscanner_send_batch(f_asheet_fortscanner):
    data = FortScanner.update_sheet_user_dict(22, "cog is great", "gears")
    fscan = FortScanner(f_asheet_fortscanner)

    await fscan.send_batch(data)

    assert fscan.asheet.batch_update_sent == data
Example #2
0
async def test_fortscanner_users(f_asheet_fortscanner):
    fscan = FortScanner(f_asheet_fortscanner)

    await fscan.update_cells()
    users = fscan.users()

    assert len(users) == 22
    assert users[-1].name == "gears"
Example #3
0
async def test_fortscanner_update_system_column(f_asheet_fortscanner):
    fscan = FortScanner(f_asheet_fortscanner)

    assert not fscan.cells_row_major

    await fscan.update_cells()
    fscan.update_system_column()

    assert fscan.system_col == "G"
Example #4
0
async def test_fortscanner_prep_systems(f_asheet_fortscanner):
    fscan = FortScanner(f_asheet_fortscanner)

    await fscan.update_cells()
    fscan.update_system_column()
    f_systems = fscan.prep_systems()

    assert len(f_systems) == 1
    assert f_systems[-1].name == "Rhea"
    assert f_systems[-1].sheet_col == "D"
Example #5
0
async def test_fortscanner_fort_systems(f_asheet_fortscanner):
    fscan = FortScanner(f_asheet_fortscanner)

    await fscan.update_cells()
    fscan.update_system_column()
    f_systems = fscan.fort_systems()

    assert len(f_systems) == 75
    assert f_systems[-1].name == "Mantxe"
    assert f_systems[-1].sheet_col == "CC"
Example #6
0
def test_fortscanner_drop_db_entries(session, f_asheet_fortscanner,
                                     f_dusers, f_fort_testbed, db_cleanup):
    fscan = FortScanner(f_asheet_fortscanner)
    assert session.query(FortUser).all()
    assert session.query(FortSystem).all()
    assert session.query(FortDrop).all()

    fscan.drop_db_entries(session)

    assert not session.query(FortUser).all()
    assert not session.query(FortSystem).all()
    assert not session.query(FortDrop).all()
Example #7
0
def test_fortscanner_flush_to_db(session, f_asheet_fortscanner,
                                 f_dusers, f_fort_testbed, db_cleanup):
    fscan = FortScanner(f_asheet_fortscanner)
    assert session.query(FortUser).all()
    assert session.query(FortSystem).all()
    assert session.query(FortDrop).all()

    objs = [FortSystem(name='Test')]
    fscan.flush_to_db(session, [objs])

    assert not session.query(FortUser).all()
    assert session.query(FortSystem).all()
    assert not session.query(FortDrop).all()
Example #8
0
async def test_fortscanner_parse_sheet(f_asheet_fortscanner, f_dusers_many, session, db_cleanup):
    fscan = FortScanner(f_asheet_fortscanner)

    assert not session.query(FortSystem).all()
    assert not session.query(FortUser).all()
    assert not session.query(FortDrop).all()

    await fscan.update_cells()
    fscan.parse_sheet(session)

    assert session.query(FortSystem).all()
    assert session.query(FortUser).all()
    assert session.query(FortDrop).all()
Example #9
0
def ocr_update_fort_status(session):
    """
    Iterate every fort in the system and update fort_status, um_status and triggers if needed.
    For any system that is updated generate an update_system_dict to be sent in batch.

    Args:
        session: A session for the database.

    Returns: (cell_updates, warnings)
        cell_updates: A list of FortScanner.update_system_dicts that will update the sheet with OCR changes.
        warnings: A list of warnings about NEWLY undermined systems.
    """
    cell_updates = []

    for sys in session.query(FortSystem):
        if not sys.ocr_tracker:
            continue
        changed = False

        if sys.ocr_tracker.fort > sys.fort_status:
            sys.fort_status = sys.ocr_tracker.fort
            changed = True
        if sys.ocr_tracker.um > sys.um_status:
            sys.um_status = sys.ocr_tracker.um
            changed = True

        if changed:
            cell_updates += FortScanner.update_system_dict(
                sys.sheet_col, sys.fort_status, sys.um_status)

    return cell_updates
Example #10
0
async def test_fortscanner_get_batch(f_asheet_fortscanner):
    fscan = FortScanner(f_asheet_fortscanner)
    f_asheet_fortscanner.batch_get.async_return_value = ['This is a test', 'Message']

    returned_data = await fscan.get_batch(['A1:B2'])
    expected_returned_data = ['This is a test', 'Message']

    assert returned_data == expected_returned_data
Example #11
0
async def test_fortscanner_update_cells(f_asheet_fortscanner):
    fscan = FortScanner(f_asheet_fortscanner)

    assert not fscan.cells_row_major

    await fscan.update_cells()

    assert fscan.cells_row_major[2][0] == "Total Fortification Triggers:"
    assert fscan.cells_col_major[0][2] == "Total Fortification Triggers:"
Example #12
0
def test_fortscanner_drop_db_entries_error(session, f_asheet_fortscanner,
                                           f_dusers, f_fort_testbed, db_cleanup):
    fscan = FortScanner(f_asheet_fortscanner)
    assert session.query(FortUser).all()
    assert session.query(FortSystem).all()
    assert session.query(FortDrop).all()
    session.close()

    # Simulate drop from external source or some critical error!
    sqla.orm.session.close_all_sessions()
    with cogdb.engine.connect() as con:
        con.execute(sqla.sql.text('drop table hudson_fort_merits'))

    with cogdb.session_scope(cogdb.Session) as new_session:
        fscan.drop_db_entries(new_session)

    assert not session.query(FortUser).all()
    assert not session.query(FortSystem).all()
    assert not session.query(FortDrop).all()
Example #13
0
async def test_fortscanner_drops(f_asheet_fortscanner):
    fscan = FortScanner(f_asheet_fortscanner)

    await fscan.update_cells()
    fscan.update_system_column()
    f_users = fscan.users()
    f_systems = fscan.fort_systems()
    f_merits = fscan.drops(f_systems, f_users)

    assert len(f_merits) == 33
    assert f_merits[0].system_id == 1
    assert f_merits[0].user_id == 2
Example #14
0
def test_fortscanner_update_drop_dict():
    data = FortScanner.update_drop_dict("G", 22, 7000)
    assert data == [{"range": "G22:G22", "values": [[7000]]}]
Example #15
0
def test_fortscanner_update_systems_dict():
    data = FortScanner.update_system_dict("G", 5000, 2222)
    assert data == [{"range": "G6:G7", "values": [[5000], [2222]]}]
Example #16
0
def test_fortscanner_update_sheet_user_dict():
    data = FortScanner.update_sheet_user_dict(22, "cog is great", "gears")
    assert data == [{"range": "A22:B22", "values": [["cog is great", "gears"]]}]