uranusjr commented on code in PR #70225: URL: https://github.com/apache/airflow/pull/70225#discussion_r3793111207
########## providers/standard/tests/unit/standard/conftest.py: ########## @@ -0,0 +1,185 @@ +# 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. +""" +Shared fixtures for the database-backed asset sensor tests. + +The :class:`AssetEventSensor` always fetches through the Task SDK +:class:`~airflow.sdk.execution_time.context.InletEventsAccessor`, which talks to +``SUPERVISOR_COMMS`` (normally a socket to the supervisor, which calls the execution API, which +queries the DB). There is no supervisor in a unit test, so :class:`_DBBackedComms` replaces only +that transport seam: it runs the *real* execution-API SQL against the test metadata DB, so the +partition-key / extra / time-range / limit filters execute for real. ``process_result`` and the +count check then run unmocked on the returned events. +""" + +from __future__ import annotations + +from datetime import datetime, timezone +from typing import Any + +import pytest + +ASSET_NAME = "my_asset" +ASSET_URI = "s3://bucket/key" +ALIAS_NAME = "my_alias" + + +def event_timestamp(day: int) -> datetime: + return datetime(2024, 1, day, tzinfo=timezone.utc) + + +class _DBBackedComms: Review Comment: Please use `mock_supervisor_comms` instead and feed prepared `AssetEventsResult`s. The filter tests are asserting SQL semantics that are already covered by `test_asset_events.py`; what the sensor owes is it builds the right message, so assert on `send.assert_called_once_with(GetAssetEventByAsset(...))`. As a bonus, we’ll also be able to drop `db_test`. -- 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]
