ashb commented on a change in pull request #4952: [AIRFLOW-4008] add envFrom 
for Kubernetes Executor
URL: https://github.com/apache/airflow/pull/4952#discussion_r270368052
 
 

 ##########
 File path: 
tests/contrib/kubernetes/kubernetes_request_factory/test_kubernetes_request_factory.py
 ##########
 @@ -0,0 +1,384 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from airflow.contrib.kubernetes.kubernetes_request_factory.\
+    kubernetes_request_factory import KubernetesRequestFactory
+from airflow.contrib.kubernetes.pod import Pod, Resources
+from airflow.contrib.kubernetes.secret import Secret
+import unittest
+
+
+class TestKubernetesRequestFactory(unittest.TestCase):
+
+    def setUp(self) -> None:
+        self.kubernetes_request_factory = KubernetesRequestFactory()
+
+        self.req = {
+            'apiVersion': 'v1',
+            'kind': 'Pod',
+            'metadata': {
+                'name': 'name'
+            },
+            'spec': {
+                'restartPolicy': 'Never',
+                'containers': [{
+                    'name': 'base',
+                    'image': 'airflow-worker:latest',
+                    'command': [
+                        "/usr/local/airflow/entrypoint.sh",
+                        "/bin/bash sleep 25"
+                    ],
+                }]
+            }
+        }
+
+    def test_extract_image(self):
+        input_req = self.req.copy()
+        reference = self.req.copy()
+        image = 'v3.14'
+        pod = Pod(image, {}, [])
+        self.kubernetes_request_factory.extract_image(pod, input_req)
+        reference['spec']['containers'][0]['image'] = image
+        self.assertDictEqual(input_req, reference)
+
+    def test_extract_image_pull_policy(self):
 
 Review comment:
   I wonder if all of these tests which have a (None and "set X to something") 
could be done using parameterized?
   
   ```python
       @parameterized.expand([
           (None,),
           ('IfNotPresent',),
       ])
       def test_extract_image_pull_policy(self, pull_policy):
           input_req = self.req.copy()
           expected = self.req
           pod = Pod('v3.14', {}, [], image_pull_policy=pull_policy)
   
           self.kubernetes_request_factory.extract_image_pull_policy(pod, 
input_req)
           reference['spec']['containers'][0]['imagePullPolicy'] = pull_policy
           self.assertDictEqual(input_req, reference)
   ```
   
   Except in this particular example I note 
https://github.com/apache/airflow/blob/master/airflow/contrib/kubernetes/pod.py#L87
 IfNotPresent is the default when not passed, so I'm not sure why the "None" 
case in this function passed without modifying the reference spec?
   
   (It may be slightly more complex than the example I gave to set the right 
value in the expected/reference object, but I think this drys up the tests 
nicely)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to