Esempio n. 1
0
async def test_fetch(table: Table, table_name: str,
                     table_columns_names: List[str],
                     table_records: List[RecordType], is_mysql: bool,
                     db_uri: URL, event_loop: AbstractEventLoop) -> None:
    table_records_dicts = records_to_dicts(records=table_records, table=table)
    insert(records_dicts=table_records_dicts, table=table, db_uri=db_uri)

    async with get_connection(db_uri=db_uri,
                              is_mysql=is_mysql,
                              loop=event_loop) as connection:
        records = await fetch(table_name=table_name,
                              columns_names=table_columns_names,
                              is_mysql=is_mysql,
                              connection=connection)

    assert all(table_record in records for table_record in table_records)

    with pytest.raises(ValueError):
        async with get_connection(db_uri=db_uri,
                                  is_mysql=is_mysql,
                                  loop=event_loop) as connection:
            await fetch(table_name=table_name,
                        columns_names=[],
                        is_mysql=is_mysql,
                        connection=connection)
Esempio n. 2
0
async def test_group_wise_fetch(table: Table, table_name: str,
                                table_columns_names: List[str],
                                table_non_unique_columns_names: List[str],
                                table_primary_key: str,
                                table_similar_records: List[RecordType],
                                is_group_wise_maximum: bool, is_mysql: bool,
                                db_uri: URL,
                                event_loop: AbstractEventLoop) -> None:
    target_function = max if is_group_wise_maximum else min
    target_primary_key_value = target_function(
        record[0] for record in table_similar_records)

    table_similar_records_dicts = records_to_dicts(
        records=table_similar_records, table=table)
    insert(records_dicts=table_similar_records_dicts,
           table=table,
           db_uri=db_uri)

    async with get_connection(db_uri=db_uri,
                              is_mysql=is_mysql,
                              loop=event_loop) as connection:
        records = await group_wise_fetch(
            table_name=table_name,
            columns_names=table_columns_names,
            target_column_name=table_primary_key,
            groupings=table_non_unique_columns_names,
            is_maximum=is_group_wise_maximum,
            is_mysql=is_mysql,
            connection=connection)

    assert all(record in table_similar_records for record in records)
    assert len(records) == 1
    group_wise_maximum_record, = records
    group_wise_maximum_record_primary_key_value = group_wise_maximum_record[0]
    assert group_wise_maximum_record_primary_key_value == target_primary_key_value

    with pytest.raises(ValueError):
        async with get_connection(db_uri=db_uri,
                                  is_mysql=is_mysql,
                                  loop=event_loop) as connection:
            await group_wise_fetch(table_name=table_name,
                                   columns_names=[],
                                   target_column_name=table_primary_key,
                                   groupings=table_non_unique_columns_names,
                                   is_mysql=is_mysql,
                                   connection=connection)

    with pytest.raises(ValueError):
        async with get_connection(db_uri=db_uri,
                                  is_mysql=is_mysql,
                                  loop=event_loop) as connection:
            await group_wise_fetch(table_name=table_name,
                                   columns_names=table_columns_names,
                                   target_column_name=table_primary_key,
                                   groupings=[],
                                   is_mysql=is_mysql,
                                   connection=connection)
Esempio n. 3
0
async def test_fetch_records_count(table: Table, table_name: str,
                                   table_records: List[RecordType],
                                   is_mysql: bool, db_uri: URL,
                                   event_loop: AbstractEventLoop) -> None:
    table_records_dicts = records_to_dicts(records=table_records, table=table)
    insert(records_dicts=table_records_dicts, table=table, db_uri=db_uri)

    async with get_connection(db_uri=db_uri,
                              is_mysql=is_mysql,
                              loop=event_loop) as connection:
        records_count = await fetch_records_count(table_name=table_name,
                                                  is_mysql=is_mysql,
                                                  connection=connection)

    assert records_count == len(table_records)
Esempio n. 4
0
async def test_update(table: Table, table_name: str,
                      table_records_updates: UpdatesType,
                      table_records: List[RecordType], is_mysql: bool,
                      db_uri: URL, event_loop: AbstractEventLoop) -> None:
    table_records_dicts = records_to_dicts(records=table_records, table=table)
    insert(records_dicts=table_records_dicts, table=table, db_uri=db_uri)
    async with get_connection(db_uri=db_uri,
                              is_mysql=is_mysql,
                              loop=event_loop) as connection:
        await update(table_name=table_name,
                     updates=table_records_updates,
                     is_mysql=is_mysql,
                     connection=connection)

    records = fetch(table=table, db_uri=db_uri)
    records_dicts = records_to_dicts(records=records, table=table)
    assert all(
        is_sub_dictionary(sub_dictionary=table_records_updates,
                          super_dictionary=record_dict)
        for record_dict in records_dicts)
Esempio n. 5
0
async def test_group_wise_fetch_records_count(
        table: Table, table_name: str,
        table_non_unique_columns_names: List[str], table_primary_key: str,
        table_similar_records: List[RecordType], is_group_wise_maximum: bool,
        is_mysql: bool, db_uri: URL, event_loop: AbstractEventLoop) -> None:
    table_similar_records_dicts = records_to_dicts(
        records=table_similar_records, table=table)
    insert(records_dicts=table_similar_records_dicts,
           table=table,
           db_uri=db_uri)

    async with get_connection(db_uri=db_uri,
                              is_mysql=is_mysql,
                              loop=event_loop) as connection:
        records_count = await group_wise_fetch_records_count(
            table_name=table_name,
            target_column_name=table_primary_key,
            groupings=table_non_unique_columns_names,
            is_maximum=is_group_wise_maximum,
            is_mysql=is_mysql,
            connection=connection)

    assert records_count == 1