def test_add_tasks(self): logic = GuiApplicationLogic() logic.customizer = Mock() td = TestGuiApplicationLogicWithClient._get_task_definition() logic.add_task_from_definition(td) self.assertIn("xyz", logic.tasks, "Task was not added") task_state1 = TestGuiApplicationLogicWithClient._get_task_state() task_state2 = TestGuiApplicationLogicWithClient._get_task_state( task_id="abc") task_state3 = TestGuiApplicationLogicWithClient._get_task_state( task_id="def") logic.add_tasks([task_state1, task_state2, task_state3]) self.assertEqual(len(logic.tasks), 3, "Incorrect number of tasks") self.assertIn("xyz", logic.tasks, "Task was not added") self.assertIn("abc", logic.tasks, "Task was not added") self.assertIn("def", logic.tasks, "Task was not added") self.assertEqual(logic.tasks["xyz"].definition.full_task_timeout, 100, "Wrong task timeout") self.assertEqual(logic.tasks["xyz"].definition.subtask_timeout, 50, "Wrong subtask timeout") result = logic.add_tasks([]) self.assertIsNone(result, "Returned value [{}] is not None".format(result)) result = logic.get_test_tasks() self.assertEqual(result, {}, "Returned value is not empty") with self.assertLogs(logger): logic.change_timeouts("invalid", 10, 10) logic.config_changed()
def test_start_task(self): logic = GuiApplicationLogic() logic.customizer = Mock() logic.client = Mock() task_desc = TaskDesc() task_desc.task_state.status = TaskStatus.notStarted task_desc.definition.task_type = "TASKTYPE1" task_type = Mock() task_type.task_builder_type.return_value = TTaskBuilder(self.path) logic.task_types["TASKTYPE1"] = task_type logic.tasks["xyz"] = task_desc logic.start_task("xyz") assert task_desc.task_state.status == TaskStatus.starting assert task_desc.task_state.outputs == [ "output1", "output2", "output3" ]
def test_task_status_changed(self): task_state = TaskState() task_dict = DictSerializer.dump(task_state) logic = GuiApplicationLogic() logic.tasks = dict(task_id=task_state, wrong_task=None) def get_logic_task(task_id): deferred = Deferred() task = logic.tasks.get(task_id) deferred.callback(DictSerializer.dump(task)) return deferred logic.client = Mock() logic.client.query_task_state = Mock() logic.client.query_task_state.side_effect = get_logic_task logic.customizer = Mock() logic.task_status_changed('wrong_task') assert not logic.customizer.update_tasks.called assert logic.client.query_task_state.called logic.client.query_task_state.called = False logic.customizer.current_task_highlighted.definition.task_id = \ str(uuid.uuid4()) logic.task_status_changed(str(uuid.uuid4())) assert not logic.client.query_task_state.called assert not logic.customizer.update_task_additional_info.called logic.customizer.current_task_highlighted.definition.task_id = 'task_id' logic.task_status_changed(str(uuid.uuid4())) assert not logic.client.query_task_state.called assert not logic.customizer.update_task_additional_info.called logic.task_status_changed('task_id') assert logic.client.query_task_state.called assert logic.customizer.update_task_additional_info.called assert not logic.client.delete_task.called task_state.status = task_to_remove_status[0] logic.task_status_changed('task_id') assert logic.client.query_task_state.called assert logic.customizer.update_task_additional_info.called assert logic.client.delete_task.called
def test_get_environments(self): from apps.appsmanager import AppsManager logic = GuiApplicationLogic() logic.customizer = Mock() logic.client = self.client apps_manager = AppsManager() apps_manager.load_apps() for env in apps_manager.get_env_list(): self.client.environments_manager.add_environment(env) environments = sync_wait(logic.get_environments()) assert len(environments) > 0 assert all([bool(env) for env in environments]) assert all([isinstance(env, dict) for env in environments])
def test_change_description(self): logic = GuiApplicationLogic() logic.customizer = Mock() rpc_session = MockRPCSession(self.client, CORE_METHOD_MAP) rpc_client = rpc.session.Client(rpc_session, CORE_METHOD_MAP) description = u"New description" logic.client = rpc_client logic.change_description(description) self.assertEqual(self.client.get_description(), description) p = logic.get_task_presets("Blender") assert p.result == {} logic.save_task_preset("NewPreset", "Blender", "Some data") p = logic.get_task_presets("Blender") assert p.result == {'NewPreset': "Some data"} logic.delete_task_preset("Blender", "NewPreset") p = logic.get_task_presets("Blender") assert p.result == {}
def test_update_payments_view(self): logic = GuiApplicationLogic() logic.client = Mock() logic.customizer = Mock() ether = denoms.ether balance_deferred = Deferred() balance_deferred.result = (3 * ether, 1 * ether, 0.3 * ether) balance_deferred.called = True logic.client.get_balance.return_value = balance_deferred logic.update_payments_view() ui = logic.customizer.gui.ui ui.localBalanceLabel.setText.assert_called_once_with("3.00000000 GNT") ui.reservedBalanceLabel.setText.assert_called_once_with( "2.00000000 GNT") ui.availableBalanceLabel.setText.assert_called_once_with( "1.00000000 GNT") ui.depositBalanceLabel.setText.assert_called_once_with( "0.30000000 ETH")