blag commented on code in PR #26358:
URL: https://github.com/apache/airflow/pull/26358#discussion_r973360339


##########
tests/www/views/test_views_dataset.py:
##########
@@ -0,0 +1,281 @@
+# 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 string
+
+import pendulum
+import pytest
+from dateutil.tz import UTC
+
+from airflow import Dataset
+from airflow.models.dataset import DatasetEvent, DatasetModel
+from airflow.operators.empty import EmptyOperator
+from airflow.utils import timezone
+from tests.test_utils.asserts import assert_queries_count
+from tests.test_utils.db import clear_db_datasets
+
+
+class TestDatasetEndpoint:
+
+    default_time = "2020-06-11T18:00:00+00:00"
+
+    @pytest.fixture(autouse=True)
+    def cleanup(self):
+        clear_db_datasets()
+        yield
+        # clear_db_datasets()
+
+
+class TestGetDatasets(TestDatasetEndpoint):
+    def test_should_respond_200(self, admin_client, session):
+        datasets = [
+            DatasetModel(
+                id=i,
+                uri=f"s3://bucket/key/{i}",
+                extra={"foo": "bar"},
+                created_at=timezone.parse(self.default_time),
+                updated_at=timezone.parse(self.default_time),
+            )
+            for i in [1, 2]
+        ]
+        session.add_all(datasets)
+        session.commit()
+        assert session.query(DatasetModel).count() == 2
+
+        with assert_queries_count(8):
+            response = admin_client.get("/object/list_datasets")
+
+        assert response.status_code == 200
+        response_data = response.json
+        assert response_data == {
+            "datasets": [
+                {
+                    "id": 1,
+                    "uri": "s3://bucket/key/1",
+                    "last_dataset_update": None,
+                    "total_updates": 0,
+                    "producing_task_count": 0,
+                    "consuming_dag_count": 0,
+                },
+                {
+                    "id": 2,
+                    "uri": "s3://bucket/key/2",
+                    "last_dataset_update": None,
+                    "total_updates": 0,
+                    "producing_task_count": 0,
+                    "consuming_dag_count": 0,
+                },
+            ],
+            "total_entries": 2,
+        }
+
+    def test_order_by_raises_400_for_invalid_attr(self, admin_client, session):
+        datasets = [
+            DatasetModel(
+                uri=f"s3://bucket/key/{i}",
+                extra={"foo": "bar"},
+                created_at=timezone.parse(self.default_time),
+                updated_at=timezone.parse(self.default_time),

Review Comment:
   > I mean, this test specifically should never even get that far?
   
   A fair point. :+1:
   
   > Plus in general these timestamps on DatasetModel aren't actually used in 
the query at all?
   
   While this is true, I think well written fixtures are also useful for trying 
to catch things that future contributors might mess up. And mistyping something 
to use `DatasetModel.created_at` instead of `DatasetDagRunQueue.created_at`, 
for example, is one of them (`updated_at` less so, but I figure it can't really 
hurt anything other than minute readability of the test code, and something 
else might have an `updated_at` attribute/column added in the future).
   
   But this is also speculative - I'll remove it, here and elsewhere where it 
isn't needed.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to