예제 #1
0
파일: cli.py 프로젝트: wohamid/mythx-cli
def group_list(ctx, number):
    """Get a list of analysis groups.
    \f

    :param ctx: Click context holding group-level parameters
    :param number: The number of analysis groups to display
    :return:
    """

    client: Client = ctx["client"]
    result = GroupListResponse(groups=[], total=0)
    offset = 0
    while True:
        resp = client.group_list(offset=offset)
        if not resp.groups:
            break
        offset += len(resp.groups)
        result.groups.extend(resp.groups)
        if len(result.groups) >= number:
            break

    # trim result to desired result number
    LOGGER.debug(resp.total)
    result = GroupListResponse(groups=result[:number], total=resp.total)
    write_or_print(FORMAT_RESOLVER[ctx["fmt"]].format_group_list(result))
def group_list(ctx, number: int) -> None:
    """Get a list of analysis groups.

    \f

    :param ctx: Click context holding group-level parameters
    :param number: The number of analysis groups to display
    :return:
    """

    client: Client = ctx["client"]
    result = GroupListResponse(groups=[], total=0)
    offset = 0
    while True:
        LOGGER.debug(f"Fetching groups with offset {offset}")
        resp = client.group_list(offset=offset)
        if not resp.groups:
            LOGGER.debug("Received empty group list response")
            break
        offset += len(resp.groups)
        result.groups.extend(resp.groups)
        if len(result.groups) >= number:
            LOGGER.debug(f"Received {len(result.groups)} groups")
            break

    # trim result to desired result number
    LOGGER.debug(f"Got {len(result.groups)} analyses, trimming to {number}")
    result = GroupListResponse(groups=result[:number], total=resp.total)
    write_or_print(FORMAT_RESOLVER[ctx["fmt"]].format_group_list(result))
예제 #3
0
    def format_group_list(resp: GroupListResponse) -> str:
        """Format a group list response as compressed JSON."""

        return resp.to_json()
예제 #4
0
def test_from_valid_dict():
    resp = GroupListResponse.from_dict(DICT_DATA)
    assert len(resp.groups) == 2
    for i, group in enumerate(resp.groups):
        assert_response_data(DICT_DATA["groups"][i], group)
예제 #5
0
import pytest
from dateutil.tz import tzutc

from mythx_models.response import (
    Group,
    GroupListResponse,
    GroupState,
    GroupStatistics,
    VulnerabilityStatistics,
)

from .common import get_test_case

JSON_DATA, DICT_DATA = get_test_case("testdata/group-list-response.json")
OBJ_DATA = GroupListResponse.from_json(JSON_DATA)


def assert_response_data(expected, g: Group):
    assert g.identifier == expected["id"]
    assert g.name == expected["name"]
    assert g.created_at == datetime(2019, 11, 4, 13, 38, 23, tzinfo=tzutc())
    assert g.created_by == "test"
    assert g.completed_at == datetime(2019, 11, 4, 13, 38, 23, tzinfo=tzutc())
    assert g.progress == 0
    assert g.status == GroupState.OPENED
    assert g.main_source_files == ["test"]
    assert g.analysis_statistics == GroupStatistics(total=0,
                                                    queued=0,
                                                    running=0,
                                                    failed=0,
def test_serde(response):
    obj = GroupListResponse(**response)
    assert obj.dict(by_alias=True) == response