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 2020/03/10 20:07:14 UTC

[GitHub] [airflow] blcksrx opened a new pull request #7689: [AIRFLOW-7038] Cassandra sensors tests

blcksrx opened a new pull request #7689: [AIRFLOW-7038] Cassandra sensors tests
URL: https://github.com/apache/airflow/pull/7689
 
 
   ---
   Issue link: WILL BE INSERTED BY [boring-cyborg](https://github.com/kaxil/boring-cyborg)
   
   Make sure to mark the boxes below before creating PR: [x]
   
   - [x] Description above provides context of the change
   - [x] Commit message/PR title starts with `[AIRFLOW-NNNN]`. AIRFLOW-NNNN = JIRA ID<sup>*</sup>
   - [x] Unit tests coverage for changes (not needed for documentation changes)
   - [x] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
   - [x] Relevant documentation is updated including usage instructions.
   - [x] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
   
   <sup>*</sup> For document-only changes commit message can start with `[AIRFLOW-XXXX]`.
   
   ---
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] nuclearpinguin commented on a change in pull request #7689: [AIRFLOW-7038] Cassandra sensors tests

Posted by GitBox <gi...@apache.org>.
nuclearpinguin commented on a change in pull request #7689: [AIRFLOW-7038] Cassandra sensors tests
URL: https://github.com/apache/airflow/pull/7689#discussion_r392589839
 
 

 ##########
 File path: tests/providers/apache/cassandra/sensors/test_record.py
 ##########
 @@ -0,0 +1,71 @@
+#
+# 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.
+
+import unittest
+
+import pytest
+
+from airflow import DAG
+from airflow.providers.apache.cassandra.hooks.cassandra import CassandraHook
+from airflow.providers.apache.cassandra.sensors.record import CassandraRecordSensor
+from airflow.utils import timezone
+
+DEFAULT_DATE = timezone.datetime(2017, 1, 1)
+
+
+@pytest.mark.integration("cassandra")
+class TestCassandraRecordSensor(unittest.TestCase):
+    def setUp(self) -> None:
+        args = {
+            'owner': 'airflow',
+            'start_date': DEFAULT_DATE
+        }
+
+        self.dag = DAG('test_dag_id', default_args=args)
+
+    def test_poke(self):
+        hook = CassandraHook(cassandra_conn_id="cassandra_default")
+        session = hook.get_conn()
+        cqls = [
+            "DROP TABLE IF EXISTS s.t",
+            "CREATE TABLE s.t (pk1 text, pk2 text, c text, PRIMARY KEY (pk1, pk2))",
+            "INSERT INTO s.t (pk1, pk2, c) VALUES ('foo', 'bar', 'baz')",
+        ]
+        for cql in cqls:
+            session.execute(cql)
 
 Review comment:
   This is not a pure unit test and it has side effects (the table is not dropped in tear down). I would suggest to mock connection with database (this will make the test faster) and add system tests (and example DAG). For example here's system test for PostgresToGCS:
   https://github.com/apache/airflow/blob/master/tests/providers/google/cloud/operators/test_postgres_to_gcs_system.py
   
   System tests are not run regularly but this hopefully will change soon as @potiuk is working on that :)

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] nuclearpinguin commented on a change in pull request #7689: [AIRFLOW-7038] Cassandra sensors tests

Posted by GitBox <gi...@apache.org>.
nuclearpinguin commented on a change in pull request #7689: [AIRFLOW-7038] Cassandra sensors tests
URL: https://github.com/apache/airflow/pull/7689#discussion_r392713867
 
 

 ##########
 File path: tests/providers/apache/cassandra/sensors/test_record.py
 ##########
 @@ -0,0 +1,71 @@
+#
+# 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.
+
+import unittest
+
+import pytest
+
+from airflow import DAG
+from airflow.providers.apache.cassandra.hooks.cassandra import CassandraHook
+from airflow.providers.apache.cassandra.sensors.record import CassandraRecordSensor
+from airflow.utils import timezone
+
+DEFAULT_DATE = timezone.datetime(2017, 1, 1)
+
+
+@pytest.mark.integration("cassandra")
+class TestCassandraRecordSensor(unittest.TestCase):
+    def setUp(self) -> None:
+        args = {
+            'owner': 'airflow',
+            'start_date': DEFAULT_DATE
+        }
+
+        self.dag = DAG('test_dag_id', default_args=args)
+
+    def test_poke(self):
+        hook = CassandraHook(cassandra_conn_id="cassandra_default")
+        session = hook.get_conn()
+        cqls = [
+            "DROP TABLE IF EXISTS s.t",
+            "CREATE TABLE s.t (pk1 text, pk2 text, c text, PRIMARY KEY (pk1, pk2))",
+            "INSERT INTO s.t (pk1, pk2, c) VALUES ('foo', 'bar', 'baz')",
+        ]
+        for cql in cqls:
+            session.execute(cql)
 
 Review comment:
   I would mock `CassandraHook` and:
   - check if it was initialized with required parameter
   - the `record_exists` of initialized `hook`  was called with expected parameters
   - check if the expected value was returned (mocking it)
   - make sure that all methods I mock are already covered by tests. In this case, I would check tests for `CassandraHook`
   
   At least that is the approach we use for GCP operators / hooks. Once you cover the hook with tests you can mock the hook in operator tests. In my opinion, it's a nice way to separate and highlight what exactly is tested. 
   
   Of course, mocking only asserts that arguments are passed as expected and some methods are called. To check integrity we should use system test (that runs example DAG). It's something still discussed but is easy to do with `SystemTest`:
   https://github.com/apache/airflow/blob/master/TESTING.rst#id24
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] blcksrx commented on a change in pull request #7689: [AIRFLOW-7038] Cassandra sensors tests

Posted by GitBox <gi...@apache.org>.
blcksrx commented on a change in pull request #7689: [AIRFLOW-7038] Cassandra sensors tests
URL: https://github.com/apache/airflow/pull/7689#discussion_r392705089
 
 

 ##########
 File path: tests/providers/apache/cassandra/sensors/test_record.py
 ##########
 @@ -0,0 +1,71 @@
+#
+# 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.
+
+import unittest
+
+import pytest
+
+from airflow import DAG
+from airflow.providers.apache.cassandra.hooks.cassandra import CassandraHook
+from airflow.providers.apache.cassandra.sensors.record import CassandraRecordSensor
+from airflow.utils import timezone
+
+DEFAULT_DATE = timezone.datetime(2017, 1, 1)
+
+
+@pytest.mark.integration("cassandra")
+class TestCassandraRecordSensor(unittest.TestCase):
+    def setUp(self) -> None:
+        args = {
+            'owner': 'airflow',
+            'start_date': DEFAULT_DATE
+        }
+
+        self.dag = DAG('test_dag_id', default_args=args)
+
+    def test_poke(self):
+        hook = CassandraHook(cassandra_conn_id="cassandra_default")
+        session = hook.get_conn()
+        cqls = [
+            "DROP TABLE IF EXISTS s.t",
+            "CREATE TABLE s.t (pk1 text, pk2 text, c text, PRIMARY KEY (pk1, pk2))",
+            "INSERT INTO s.t (pk1, pk2, c) VALUES ('foo', 'bar', 'baz')",
+        ]
+        for cql in cqls:
+            session.execute(cql)
 
 Review comment:
   As far as the sensor uses the hook methods, what's your idea to mock the hook methods? For example, mocking `record_exists` in here:
   ```
   
       def poke(self, context: Dict[str, str]) -> bool:
           self.log.info('Sensor check existence of record: %s', self.keys)
           hook = CassandraHook(self.cassandra_conn_id)
           return hook.record_exists(self.table, self.keys)
   ```

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [airflow] codecov-io commented on issue #7689: [AIRFLOW-7038] Cassandra sensors tests

Posted by GitBox <gi...@apache.org>.
codecov-io commented on issue #7689: [AIRFLOW-7038] Cassandra sensors tests
URL: https://github.com/apache/airflow/pull/7689#issuecomment-597755068
 
 
   # [Codecov](https://codecov.io/gh/apache/airflow/pull/7689?src=pr&el=h1) Report
   > Merging [#7689](https://codecov.io/gh/apache/airflow/pull/7689?src=pr&el=desc) into [master](https://codecov.io/gh/apache/airflow/commit/fcfc2aa7317916b402340e223b4431f87d9d6d6f?src=pr&el=desc) will **decrease** coverage by `0.16%`.
   > The diff coverage is `100%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/airflow/pull/7689/graphs/tree.svg?width=650&token=WdLKlKHOAU&height=150&src=pr)](https://codecov.io/gh/apache/airflow/pull/7689?src=pr&el=tree)
   
   ```diff
   @@            Coverage Diff             @@
   ##           master    #7689      +/-   ##
   ==========================================
   - Coverage   86.98%   86.82%   -0.17%     
   ==========================================
     Files         904      904              
     Lines       43736    43736              
   ==========================================
   - Hits        38045    37972      -73     
   - Misses       5691     5764      +73
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/airflow/pull/7689?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [airflow/utils/dag\_processing.py](https://codecov.io/gh/apache/airflow/pull/7689/diff?src=pr&el=tree#diff-YWlyZmxvdy91dGlscy9kYWdfcHJvY2Vzc2luZy5weQ==) | `88.33% <100%> (ø)` | :arrow_up: |
   | [airflow/kubernetes/volume\_mount.py](https://codecov.io/gh/apache/airflow/pull/7689/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3ZvbHVtZV9tb3VudC5weQ==) | `44.44% <0%> (-55.56%)` | :arrow_down: |
   | [airflow/kubernetes/volume.py](https://codecov.io/gh/apache/airflow/pull/7689/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3ZvbHVtZS5weQ==) | `52.94% <0%> (-47.06%)` | :arrow_down: |
   | [airflow/kubernetes/pod\_launcher.py](https://codecov.io/gh/apache/airflow/pull/7689/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3BvZF9sYXVuY2hlci5weQ==) | `47.18% <0%> (-45.08%)` | :arrow_down: |
   | [...viders/cncf/kubernetes/operators/kubernetes\_pod.py](https://codecov.io/gh/apache/airflow/pull/7689/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvY25jZi9rdWJlcm5ldGVzL29wZXJhdG9ycy9rdWJlcm5ldGVzX3BvZC5weQ==) | `69.69% <0%> (-25.26%)` | :arrow_down: |
   | [airflow/kubernetes/refresh\_config.py](https://codecov.io/gh/apache/airflow/pull/7689/diff?src=pr&el=tree#diff-YWlyZmxvdy9rdWJlcm5ldGVzL3JlZnJlc2hfY29uZmlnLnB5) | `50.98% <0%> (-23.53%)` | :arrow_down: |
   | [...flow/providers/apache/cassandra/hooks/cassandra.py](https://codecov.io/gh/apache/airflow/pull/7689/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvYXBhY2hlL2Nhc3NhbmRyYS9ob29rcy9jYXNzYW5kcmEucHk=) | `96.2% <0%> (+2.53%)` | :arrow_up: |
   | [airflow/utils/process\_utils.py](https://codecov.io/gh/apache/airflow/pull/7689/diff?src=pr&el=tree#diff-YWlyZmxvdy91dGlscy9wcm9jZXNzX3V0aWxzLnB5) | `86.04% <0%> (+12.79%)` | :arrow_up: |
   | [...rflow/providers/apache/cassandra/sensors/record.py](https://codecov.io/gh/apache/airflow/pull/7689/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvYXBhY2hlL2Nhc3NhbmRyYS9zZW5zb3JzL3JlY29yZC5weQ==) | `100% <0%> (+100%)` | :arrow_up: |
   | [...irflow/providers/apache/cassandra/sensors/table.py](https://codecov.io/gh/apache/airflow/pull/7689/diff?src=pr&el=tree#diff-YWlyZmxvdy9wcm92aWRlcnMvYXBhY2hlL2Nhc3NhbmRyYS9zZW5zb3JzL3RhYmxlLnB5) | `100% <0%> (+100%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/airflow/pull/7689?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/airflow/pull/7689?src=pr&el=footer). Last update [fcfc2aa...0a0d6df](https://codecov.io/gh/apache/airflow/pull/7689?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services