You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/11/24 21:42:37 UTC

[GitHub] [airflow] malthe commented on a change in pull request #19806: Psrp advanced options

malthe commented on a change in pull request #19806:
URL: https://github.com/apache/airflow/pull/19806#discussion_r756436789



##########
File path: tests/providers/microsoft/psrp/hooks/test_psrp.py
##########
@@ -29,43 +30,67 @@
 CONNECTION_ID = "conn_id"
 
 
-class TestPSRPHook(unittest.TestCase):
-    @patch(
-        f"{PSRPHook.__module__}.{PSRPHook.__name__}.get_connection",
-        return_value=Connection(
-            login='username',
-            password='password',
-            host='remote_host',
-        ),
-    )
-    @patch(f"{PSRPHook.__module__}.WSMan")
-    @patch(f"{PSRPHook.__module__}.PowerShell")
-    @patch(f"{PSRPHook.__module__}.RunspacePool")
-    @patch("logging.Logger.info")
-    def test_invoke_powershell(self, log_info, runspace_pool, powershell, ws_man, get_connection):
-        with PSRPHook(CONNECTION_ID) as hook:
-            ps = powershell.return_value = MagicMock()
-            ps.state = PSInvocationState.RUNNING
-            ps.output = []
-            ps.streams.debug = []
-            ps.streams.information = []
-            ps.streams.error = []
+def mock_powershell():

Review comment:
       I could change it to something like:
   ```python
   class MockPowerShellFactory(MagicMock):
       def __init__(self, *args, **kwargs):
           super().__init__(*args, **kwargs)
           ps = self.return_value = MagicMock()
           ps.state = PSInvocationState.NOT_STARTED
   
           def poll_invoke():
               ps.output.append("<output>")
               ps.streams.debug.append(MagicMock(spec=InformationRecord, message_data="<message>"))
               ps.state = PSInvocationState.COMPLETED
   
           def begin_invoke():
               ps.state = PSInvocationState.RUNNING
               ps.output = []
               ps.streams.debug = []
               ps.streams.information = []
               ps.streams.error = []
   
           def end_invoke():
               while ps.state == PSInvocationState.RUNNING:
                   poll_invoke()
               ps.streams.error = []
   
           ps.poll_invoke.side_effect = poll_invoke
           ps.begin_invoke.side_effect = begin_invoke
           ps.end_invoke.side_effect = end_invoke
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org