def test_missing_password_raises(self): """ Test that the Asana hook raises an exception if password not provided in connection. :return: None """ with patch.object(AsanaHook, "get_connection", return_value=Connection(conn_type="asana")): hook = AsanaHook() with self.assertRaises(ValueError): hook.get_conn()
def test_asana_client_retrieved(self): """ Test that we successfully retrieve an Asana client given a Connection with complete information. :return: None """ with patch.object(AsanaHook, "get_connection", return_value=Connection(conn_type="asana", password="******")): hook = AsanaHook() client = hook.get_conn() self.assertEqual(type(client), Client)
def test_merge_project_parameters_override(self): """ Tests that default workspace is successfully overridden :return: """ conn = Connection(conn_type='asana', password='******', extra='{"extra__asana__workspace": "1"}') with patch.object(AsanaHook, "get_connection", return_value=conn): hook = AsanaHook() expected_merged_params = {"workspace": "2"} self.assertEqual( expected_merged_params, hook._merge_project_parameters({"workspace": "2"}), # pylint: disable=W0212 )
def test_merge_project_parameters(self): """ Tests that default workspace is used if not overridden :return: """ conn = Connection(conn_type="asana", password="******", extra='{"extra__asana__workspace": "1"}') with patch.object(AsanaHook, "get_connection", return_value=conn): hook = AsanaHook() expected_merged_params = {"workspace": "1", "name": "name"} self.assertEqual( expected_merged_params, hook._merge_project_parameters({"name": "name"}) # pylint: disable=W0212 )
def test_merge_create_task_parameters_specified_workspace(self): """ Test that merge_create_task_parameters correctly merges the default and method parameters when we do not override the default workspace. :return: None """ conn = Connection(conn_type="asana", password="******", extra='{"extra__asana__workspace": "1"}') with patch.object(AsanaHook, "get_connection", return_value=conn): hook = AsanaHook() expected_merged_params = {"name": "test", "workspace": "1"} self.assertEqual( expected_merged_params, hook._merge_create_task_parameters("test", {}) # pylint: disable=W0212 )
def test_merge_find_task_parameters_specified_project(self): """ Test that merge_find_task_parameters correctly merges the default and method parameters when we do override the default project. :return: None """ conn = Connection(conn_type="asana", password="******", extra='{"extra__asana__project": "1"}') with patch.object(AsanaHook, "get_connection", return_value=conn): hook = AsanaHook() expected_merged_params = {"project": "2"} self.assertEqual( expected_merged_params, hook._merge_find_task_parameters({"project": "2"}), # pylint: disable=W0212 )
def test_merge_find_task_parameters_specified_project_overrides_workspace( self): """ Test that merge_find_task_parameters uses the method parameter project over the default workspace if it is available :return: None """ conn = Connection( conn_type="asana", password="******", extra='{"extra__asana__workspace": "1"}', ) with patch.object(AsanaHook, "get_connection", return_value=conn): hook = AsanaHook() expected_merged_params = {"project": "2"} self.assertEqual( expected_merged_params, hook._merge_find_task_parameters({"project": "2"}), # pylint: disable=W0212 )
def test_merge_create_task_parameters_default_project_overrides_default_workspace( self): """ Test that merge_create_task_parameters uses the default project over the default workspace if it is available :return: None """ conn = Connection( conn_type="asana", password="******", extra= '{"extra__asana__workspace": "1", "extra__asana__project": "1"}', ) with patch.object(AsanaHook, "get_connection", return_value=conn): hook = AsanaHook() expected_merged_params = {"name": "test", "projects": ["1"]} self.assertEqual( expected_merged_params, hook._merge_create_task_parameters("test", {}) # pylint: disable=W0212 )
def execute(self, context: 'Context') -> None: hook = AsanaHook(conn_id=self.conn_id) response = hook.update_task(self.asana_task_gid, self.task_parameters) self.log.info(response)
def execute(self, context: 'Context') -> str: hook = AsanaHook(conn_id=self.conn_id) response = hook.create_task(self.name, self.task_parameters) self.log.info(response) return response["gid"]
def execute(self, context: 'Context') -> list: hook = AsanaHook(conn_id=self.conn_id) response = hook.find_task(self.search_parameters) self.log.info(response) return response
def execute(self, context: 'Context') -> None: hook = AsanaHook(conn_id=self.conn_id) response = hook.delete_task(self.asana_task_gid) self.log.info(response)