Exemplo n.º 1
0
async def test_update_one_artifact():
    ts = time.perf_counter()
    bprint('Test: Update One Artifact')

    async with PhantomApiClient(
            cfg=f'{getenv("CFG_HOME")}/phantom_api_client.toml') as pac:
        container = generate_container(artifact_count=1)[0]
        artifact = container.artifacts[0]
        rid = artifact.data['request_id']
        artifact.clear()
        artifact.data = {'request_id': rid}
        artifact.name = 'Update Test'

        results = await pac.get_records(
            ArtifactQuery(filter={'_filter_type': '"test"'}))
        ids = [c['id'] for c in results.success]
        aid = choice(ids)
        artifact.update_id(aid)

        print(f'Artifact: {aid}\n\t->{artifact}')

        results = await pac.update_records(requests=[artifact])
        # print(response_results)

        assert type(results) is Results
        assert len(results.success) == 1
        assert not results.failure
        assert results.success
        assert results.success[0]['success']

        tprint(results)

    bprint(f'-> Completed in {(time.perf_counter() - ts):f} seconds.')
Exemplo n.º 2
0
async def test_create_many_artifacts():
    ts = time.perf_counter()
    bprint('Test: Create Many Artifacts')

    async with PhantomApiClient(
            cfg=f'{getenv("CFG_HOME")}/phantom_api_client_prod.toml') as pac:
        container = generate_container(artifact_count=2)
        results = await pac.get_records(
            ContainerQuery(filter={'_filter_tenant': 2}))
        ids = [c['id'] for c in results.success]
        cid = choice(ids)

        print(f'Container: {cid}')

        container[0].update_id(cid)
        response_results, request_results = await pac.create_artifacts(
            container)
        # print(response_results)

        assert type(response_results) is Results
        assert len(request_results) == 1
        assert len(response_results.success) == 2
        assert not response_results.failure
        assert response_results.success[0]['success']

        tprint(response_results, request_results, top=5)

        # todo: check for creation within phantom

    bprint(f'-> Completed in {(time.perf_counter() - ts):f} seconds.')
Exemplo n.º 3
0
async def test_update_one_container():
    ts = time.perf_counter()
    bprint('Test: Update One Container')

    async with PhantomApiClient(
            cfg=f'{getenv("CFG_HOME")}/phantom_api_client.toml') as pac:
        results = await pac.get_records(query=ContainerQuery(
            page=0, page_size=20, filter={'_filter_tenant': 2}))
        old_container = choice(results.success)
        print(f'Container Prior Update\n\t-> {old_container}')

        container = generate_container()[0]
        container.clear()
        container.name = 'Update Test'
        container.update_id(old_container['id'])
        results = await pac.update_records(container)
        # print(response_results)

        assert type(results) is Results
        assert len(results.success) == 1
        assert not results.failure
        assert results.success
        assert results.success[0]['success']

        tprint(results)

        results = await pac.get_records(query=ContainerQuery(
            id=old_container['id']))
        print(f'Container After Update\n\t-> {results.success[0]}')

    bprint(f'-> Completed in {(time.perf_counter() - ts):f} seconds.')
Exemplo n.º 4
0
async def test_create_many_containers():
    ts = time.perf_counter()
    bprint('Test: Create Many Containers')

    async with PhantomApiClient(
            cfg=f'{getenv("CFG_HOME")}/phantom_api_client.toml') as pac:
        response_results, request_results = await pac.create_containers(
            generate_container(container_count=2))
        # print(response_results)

        assert type(response_results) is Results
        assert len(request_results) == 2
        assert len(response_results.success) == 2
        assert not response_results.failure
        assert response_results.success[0]['success']

        tprint(response_results, request_results)

        print('\nVerify Results from Phantom')
        ids = [r['id'] for r in response_results.success]
        results = await pac.get_records(query=ContainerQuery(
            filter={'_filter_id__in': str(ids)}))
        tprint(results)

    bprint(f'-> Completed in {(time.perf_counter() - ts):f} seconds.')
Exemplo n.º 5
0
async def test_update_many_containers():
    ts = time.perf_counter()
    bprint('Test: Update Many Containers')

    async with PhantomApiClient(
            cfg=f'{getenv("CFG_HOME")}/phantom_api_client.toml') as pac:
        results = await pac.get_records(query=ContainerQuery(
            page=0, page_size=50, filter={'_filter_tenant': 2}))

        old_containers = [choice(results.success), choice(results.success)]
        while old_containers[0] == old_containers[1]:
            old_containers[1] = choice(results.success)

        ocp = '\n\t-> '.join([str(d) for d in old_containers])
        print(f'Containers Prior Update\n\t-> {ocp}')

        containers = generate_container(container_count=2)

        [a.clear() for a in containers]
        for i, a in enumerate(containers):
            a.name = f'Update Test: {i}'
            a.update_id(old_containers[i]['id'])

        results = await pac.update_records(containers)

        assert type(results) is Results
        assert len(results.success) == 2
        assert not results.failure
        assert results.success
        assert results.success[0]['success']

        tprint(results)

        results = await pac.get_records(query=ContainerQuery(
            id=[c['id'] for c in old_containers]))
        ucp = '\n\t-> '.join([str(d) for d in results.success])
        print(f'Containers After Update\n\t-> {ucp}')

    bprint(f'-> Completed in {(time.perf_counter() - ts):f} seconds.')
Exemplo n.º 6
0
async def test_update_many_artifacts():
    ts = time.perf_counter()
    bprint('Test: Update Many Artifacts')

    async with PhantomApiClient(
            cfg=f'{getenv("CFG_HOME")}/phantom_api_client.toml') as pac:
        container = generate_container(artifact_count=2)[0]
        artifacts = container.artifacts
        rids = [a.data['request_id'] for a in artifacts]
        [a.clear() for a in artifacts]

        results = await pac.get_records(
            ArtifactQuery(filter={'_filter_type': '"test"'}))
        ids = [c['id'] for c in results.success]
        aids = [choice(ids), choice(ids)]

        while aids[0] == aids[1]:
            aids[1] = choice(ids)

        print(f'Artifacts: {aids}')

        for i, a in enumerate(artifacts):
            a.data = {'request_id': rids[i]}
            a.name = f'Update Test: {i}'
            a.update_id(aids[i])

        results = await pac.update_records(artifacts)
        # print(response_results)

        assert type(results) is Results
        assert len(results.success) == 2
        assert not results.failure
        assert results.success
        assert results.success[0]['success']

        tprint(results)

    bprint(f'-> Completed in {(time.perf_counter() - ts):f} seconds.')
Exemplo n.º 7
0
async def test_create_one_container():
    ts = time.perf_counter()
    bprint('Test: Create One Container')

    async with PhantomApiClient(
            cfg=f'{getenv("CFG_HOME")}/phantom_api_client_prod.toml') as pac:
        response_results, request_results = await pac.create_containers(
            generate_container())
        # print(response_results)

        assert type(response_results) is Results
        assert len(request_results) == 1
        assert len(response_results.success) == 1
        assert not response_results.failure
        assert response_results.success[0]['success']

        tprint(response_results, request_results)

        print('\nVerify Results from Phantom')
        results = await pac.get_records(query=ContainerQuery(
            filter={'_filter_id': response_results.success[0]['id']}))
        tprint(results)

    bprint(f'-> Completed in {(time.perf_counter() - ts):f} seconds.')