Пример #1
0
def test_block_get_and_delete(cbcsdk_mock):
    """Tests a simple load and delete of a block object."""
    cbcsdk_mock.mock_request("GET", "/device_control/v3/orgs/test/blocks/55",
                             USBDEVICE_BLOCK_GET_RESP)
    cbcsdk_mock.mock_request("DELETE",
                             "/device_control/v3/orgs/test/blocks/55",
                             CBCSDKMock.StubResponse(None, scode=204))
    api = cbcsdk_mock.api
    block = USBDeviceBlock(api, 55)
    assert block._model_unique_id == 55
    assert block.policy_id == "6997287"
    block.delete()
Пример #2
0
def test_run_stop_exception(cbcsdk_mock):
    """Testing Run.stop() when response from server is not JSON parsable."""
    api = cbcsdk_mock.api
    cbcsdk_mock.mock_request("GET", "/livequery/v1/orgs/test/runs/run_id",
                             GET_RUN_RESP)
    unparsable_response = CBCSDKMock.StubResponse(
        contents="ThisIsntJSONParsable", scode=200, json_parsable=False)
    cbcsdk_mock.mock_request("PUT",
                             "/livequery/v1/orgs/test/runs/run_id/status",
                             unparsable_response)
    assert unparsable_response._json_parsable is False
    run = Run(api, model_unique_id="run_id")
    with pytest.raises(ServerError):
        run.stop()
Пример #3
0
def test_approval_query_and_delete(cbcsdk_mock):
    """Tests a simple query and delete of an approval object."""
    cbcsdk_mock.mock_request("POST", "/device_control/v3/orgs/test/approvals/_search", USBDEVICE_APPROVAL_QUERY_RESP)
    cbcsdk_mock.mock_request("DELETE", "/device_control/v3/orgs/test/approvals/10373",
                             CBCSDKMock.StubResponse(None, scode=204))
    api = cbcsdk_mock.api
    query = api.select(USBDeviceApproval).where('*')
    results = [result for result in query._perform_query()]
    assert len(results) == 1
    assert query._count() == len(results)
    approval = results[0]
    assert approval._model_unique_id == "10373"
    assert approval.vendor_id == "0x0781"
    assert approval.vendor_name == "SanDisk"
    assert approval.product_id == "0x5581"
    assert approval.product_name == "Ultra"
    assert approval.approval_name == "Example Approval"
    approval.delete()
Пример #4
0
def test_block_get_all_and_fail_delete(cbcsdk_mock):
    """Tests the load of all block objects and a failed delete."""
    cbcsdk_mock.mock_request("GET", "/device_control/v3/orgs/test/blocks",
                             USBDEVICE_BLOCK_GET_ALL_RESP)
    cbcsdk_mock.mock_request(
        "DELETE", "/device_control/v3/orgs/test/blocks/55",
        CBCSDKMock.StubResponse(None,
                                scode=500,
                                text="Blow Up",
                                json_parsable=False))
    api = cbcsdk_mock.api
    query = api.select(USBDeviceBlock)
    assert query._count() == 1
    results = [result for result in query._perform_query()]
    assert len(results) == 1
    block = results[0]
    assert block._model_unique_id == 55
    assert block.policy_id == "6997287"
    with pytest.raises(ServerError):
        block.delete()