def test_task_phone_actions_iter(): request = mock.Mock(return_value={ "total_count": 2, "items": ["phone_action23", "phone_action42"] }) with mock.patch("vxcube_api.raw_api.VxCubeApiRequest.request", new=request): raw_api = VxCubeRawApi(base_url="http://test", version=2.0) task = Task(id=42, _raw_api=raw_api) phone_actions = list( task.phone_actions_iter(count_per_request=23, search="lost")) assert len(phone_actions) == 2 assert phone_actions[0] == "phone_action23" assert phone_actions[1] == "phone_action42" request.assert_called_with( method="get", url="http://test/api-2.0/tasks/42/phone_actions", params={}, headers={}, json={ "count": 23, "offset": 0, "search": "lost" })
def test_task_restart_processing_task(): request = mock.Mock(return_value=None) with mock.patch("vxcube_api.raw_api.VxCubeApiRequest.request", new=request): raw_api = VxCubeRawApi(base_url="http://test", version=2.0) task = Task(id=42, status="processing", _raw_api=raw_api) assert not task.restart() request.assert_not_called()
def test_task_is_android(): task = Task(platform_code="winxpx86") assert not task.is_android task = Task(platform_code="android4.3") assert task.is_android task = Task(platform_code="android7.1") assert task.is_android
def test_task_android_cureit(): request = mock.Mock(return_value={"status": "processing", "retries": None}) with mock.patch("vxcube_api.raw_api.VxCubeApiRequest.request", new=request): raw_api = VxCubeRawApi(base_url="http://test", version=2.0) task = Task(id=42, platform_code="android4.3", _raw_api=raw_api) cureit = task.cureit() assert cureit is None request.assert_not_called()
def test_task_download_report(): request = mock.Mock(return_value=None) with mock.patch("vxcube_api.raw_api.VxCubeApiRequest.request", new=request): raw_api = VxCubeRawApi(base_url="http://test", version=2.0) task = Task(id=42, _raw_api=raw_api) task.download_report(output_file="test_output") request.assert_called_with(method="get", url="http://test/api-2.0/tasks/42/report", params={}, headers={}, output_file="test_output")
def test_task_restart(): request = mock.Mock(return_value={"status": "processing"}) with mock.patch("vxcube_api.raw_api.VxCubeApiRequest.request", new=request): raw_api = VxCubeRawApi(base_url="http://test", version=2.0) task = Task(id=42, status="deleted", _raw_api=raw_api) assert task.restart() assert task.status == "processing" request.assert_called_with(method="post", url="http://test/api-2.0/tasks/42/restart", params={}, headers={})
def test_task_storage_list(): return_storage = {"files": [], "folders": []} request = mock.Mock(return_value=return_storage) with mock.patch("vxcube_api.raw_api.VxCubeApiRequest.request", new=request): raw_api = VxCubeRawApi(base_url="http://test", version=2.0) task = Task(id=42, _raw_api=raw_api) storage = task.storage_lists() assert storage is return_storage request.assert_called_with( method="get", url="http://test/api-2.0/tasks/42/archive_storage", params={}, headers={})
def test_task_download_from_storage(): return_storage = {"files": [], "folders": []} request = mock.Mock(return_value=return_storage) with mock.patch("vxcube_api.raw_api.VxCubeApiRequest.request", new=request): raw_api = VxCubeRawApi(base_url="http://test", version=2.0) task = Task(id=42, _raw_api=raw_api) task.download_storage_file(path="test_path", output_file="test_output") request.assert_called_with( method="get", url="http://test/api-2.0/tasks/42/archive_storage", params={}, headers={}, json={"path": "test_path"}, output_file="test_output")
def test_task_windows_cureit(): request = mock.Mock(return_value={"status": "processing", "retries": None}) with mock.patch("vxcube_api.raw_api.VxCubeApiRequest.request", new=request): raw_api = VxCubeRawApi(base_url="http://test", version=2.0) task = Task(id=42, platform_code="winxpx86", _raw_api=raw_api) cureit = task.cureit() assert cureit.task_id == 42 assert cureit.status == "processing" assert cureit.retries is None assert cureit._raw_api is raw_api request.assert_called_with(method="get", url="http://test/api-2.0/tasks/42/cureit", params={}, headers={})
def test_task_intents(): request = mock.Mock(return_value=["intent23", "intent42"]) with mock.patch("vxcube_api.raw_api.VxCubeApiRequest.request", new=request): raw_api = VxCubeRawApi(base_url="http://test", version=2.0) task = Task(id=42, _raw_api=raw_api) intents = task.intents(23, 42, "lost") assert len(intents) == 2 assert intents[0] == "intent23" assert intents[1] == "intent42" request.assert_called_with(method="get", url="http://test/api-2.0/tasks/42/intents", params={}, headers={}, json={ "count": 23, "offset": 42, "search": "lost" })
def test_task(): values = dict( # base id=1, status="successful", platform_code="winxpx86", start_date="2018-04-08T15:16:23.420000+00:00", end_date="2018-04-08T15:16:23.420000+00:00", maliciousness=3, # processing message="test_message", progress=99, # finished verdict="guilty", rules={"neutral": ["Hugo wins the lottery"]}, ) task = Task(**values) assert task.id == 1 assert task.status == "successful" assert task.platform_code == "winxpx86" assert task.start_date == datetime.datetime(2018, 4, 8, 15, 16, 23, 420000, tzinfo=tzutc()) assert task.end_date == datetime.datetime(2018, 4, 8, 15, 16, 23, 420000, tzinfo=tzutc()) assert task.maliciousness == 3 assert task.message == "test_message" assert task.progress == 99 assert task.verdict == "guilty" assert task.rules == {"neutral": ["Hugo wins the lottery"]}
def test_task_update(): values = dict( # base id=1, status="successful", platform_code="winxpx86", start_date="2018-04-08T15:16:23.420000+00:00", end_date="2018-04-08T15:16:23.420000+00:00", suspicion=3, ) task = Task(**values) assert task.id == 1 assert task.status == "successful" assert task.message is None assert task.progress is None assert task.verdict is None assert task.rules is None values.update( dict( status="processing", message="test_message", progress=99, )) task.update(**values) assert task.message == "test_message" assert task.progress == 99 assert task.verdict is None assert task.rules is None del values["message"] del values["progress"] values.update( dict( status="finished", verdict="guilty", rules={"neutral": ["Hugo wins the lottery"]}, )) task.update(**values) assert task.message is None assert task.progress is None assert task.verdict == "guilty" assert task.rules == {"neutral": ["Hugo wins the lottery"]}
def test_task_status(status, state): task = Task(status=status) for attr in state: assert getattr(task, attr) == state[attr]