Skip to content

Commit 3722c7f

Browse files
Add unit tests for auth manager login datamodels (#72265) (#75544)
1 parent c84db2f commit 3722c7f

4 files changed

Lines changed: 107 additions & 2 deletions

File tree

‎airflow-core/tests/unit/always/test_project_structure.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ def test_providers_modules_should_have_tests(self):
6161
# A long-standing bug in the test below allowed modules without tests to go undetected.
6262
# This list tracks those modules and should shrink to zero as tests are added.
6363
OVERLOOKED_TESTS = [
64-
"providers/amazon/tests/unit/amazon/aws/auth_manager/datamodels/test_login.py",
6564
"providers/amazon/tests/unit/amazon/aws/executors/batch/test_batch_executor_config.py",
6665
"providers/amazon/tests/unit/amazon/aws/executors/ecs/test_ecs_executor_config.py",
6766
"providers/amazon/tests/unit/amazon/aws/executors/aws_lambda/test_utils.py",
@@ -77,7 +76,6 @@ def test_providers_modules_should_have_tests(self):
7776
"providers/cncf/kubernetes/tests/unit/cncf/kubernetes/test_python_kubernetes_script.py",
7877
"providers/cncf/kubernetes/tests/unit/cncf/kubernetes/utils/test_delete_from.py",
7978
"providers/common/compat/tests/unit/common/compat/standard/test_utils.py",
80-
"providers/fab/tests/unit/fab/auth_manager/api_fastapi/datamodels/test_login.py",
8179
"providers/fab/tests/unit/fab/migrations/test_env.py",
8280
"providers/fab/tests/unit/fab/www/extensions/test_init_appbuilder.py",
8381
"providers/fab/tests/unit/fab/www/extensions/test_init_jinja_globals.py",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
from __future__ import annotations
19+
20+
import pytest
21+
22+
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
23+
24+
if not AIRFLOW_V_3_0_PLUS:
25+
pytest.skip("AWS auth manager is only compatible with Airflow >= 3.0.0", allow_module_level=True)
26+
27+
from pydantic import ValidationError
28+
29+
from airflow.providers.amazon.aws.auth_manager.datamodels.login import LoginResponse
30+
31+
32+
class TestLoginResponse:
33+
def test_login_response_valid(self):
34+
token = "test_aws_jwt_access_token_12345"
35+
response = LoginResponse(access_token=token)
36+
assert response.access_token == token
37+
assert response.model_dump() == {"access_token": token}
38+
39+
def test_login_response_from_dict(self):
40+
data = {"access_token": "valid_token"}
41+
response = LoginResponse.model_validate(data)
42+
assert response.access_token == "valid_token"
43+
44+
def test_login_response_missing_access_token(self):
45+
with pytest.raises(ValidationError):
46+
LoginResponse.model_validate({})
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
from __future__ import annotations
18+
19+
import pytest
20+
21+
from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS
22+
23+
if not AIRFLOW_V_3_0_PLUS:
24+
pytest.skip("FAB auth manager is only compatible with Airflow >= 3.0.0", allow_module_level=True)
25+
26+
from pydantic import ValidationError
27+
28+
from airflow.providers.fab.auth_manager.api_fastapi.datamodels.login import LoginResponse
29+
30+
31+
class TestLoginResponse:
32+
def test_login_response_valid(self):
33+
token = "test_fab_jwt_access_token_67890"
34+
response = LoginResponse(access_token=token)
35+
assert response.access_token == token
36+
assert response.model_dump() == {"access_token": token}
37+
38+
def test_login_response_from_dict(self):
39+
data = {"access_token": "valid_token"}
40+
response = LoginResponse.model_validate(data)
41+
assert response.access_token == "valid_token"
42+
43+
def test_login_response_missing_access_token(self):
44+
with pytest.raises(ValidationError):
45+
LoginResponse.model_validate({})

0 commit comments

Comments
 (0)