Skip to content

Commit b1300f6

Browse files
committed
[tests] Removed redundant current_client() fixtures from unit tests
1 parent 493ae52 commit b1300f6

15 files changed

+88
-314
lines changed

tests/unit/conftest.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,36 @@
22

33
import pytest
44

5+
from pyatlan.client.atlan import AtlanClient
6+
57

68
@pytest.fixture()
79
def mock_role_cache():
8-
with patch("pyatlan.cache.role_cache.RoleCache") as cache:
10+
with patch.object(AtlanClient, "role_cache") as cache:
911
yield cache
1012

1113

1214
@pytest.fixture()
1315
def mock_user_cache():
14-
with patch("pyatlan.cache.user_cache.UserCache") as cache:
16+
with patch.object(AtlanClient, "user_cache") as cache:
1517
yield cache
1618

1719

1820
@pytest.fixture()
1921
def mock_group_cache():
20-
with patch("pyatlan.cache.group_cache.GroupCache") as cache:
22+
with patch.object(AtlanClient, "group_cache") as cache:
2123
yield cache
2224

2325

2426
@pytest.fixture()
2527
def mock_custom_metadata_cache():
26-
with patch("pyatlan.cache.custom_metadata_cache.CustomMetadataCache") as cache:
28+
with patch.object(AtlanClient, "custom_metadata_cache") as cache:
2729
yield cache
2830

2931

3032
@pytest.fixture()
3133
def mock_tag_cache():
32-
with patch("pyatlan.cache.atlan_tag_cache.AtlanTagCache") as cache:
34+
with patch.object(AtlanClient, "atlan_tag_cache") as cache:
3335
yield cache
3436

3537

tests/unit/model/badge_test.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from unittest.mock import MagicMock
2-
31
import pytest
42

53
from pyatlan.client.atlan import AtlanClient
@@ -37,22 +35,6 @@ def client():
3735
return AtlanClient()
3836

3937

40-
@pytest.fixture()
41-
def current_client(client, monkeypatch):
42-
monkeypatch.setattr(
43-
AtlanClient,
44-
"get_current_client",
45-
lambda: client,
46-
)
47-
48-
49-
@pytest.fixture()
50-
def mock_cm_cache(current_client, monkeypatch):
51-
mock_cache = MagicMock()
52-
monkeypatch.setattr(AtlanClient, "custom_metadata_cache", mock_cache)
53-
return mock_cache
54-
55-
5638
@pytest.mark.parametrize(
5739
"name, cm_name, cm_attribute, badge_conditions, message",
5840
[
@@ -78,9 +60,9 @@ def test_create_when_required_parameters_are_missing_raises_value_error(
7860
)
7961

8062

81-
def test_create(mock_cm_cache, client: AtlanClient):
82-
mock_cm_cache.get_attr_id_for_name.return_value = CM_ATTR_ID
83-
mock_cm_cache.get_id_for_name.return_value = CM_ID
63+
def test_create(mock_custom_metadata_cache, client: AtlanClient):
64+
mock_custom_metadata_cache.get_attr_id_for_name.return_value = CM_ATTR_ID
65+
mock_custom_metadata_cache.get_id_for_name.return_value = CM_ID
8466

8567
badge = Badge.create(
8668
client=client,

tests/unit/model/connection_test.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import List, Optional
2-
from unittest.mock import MagicMock, patch
2+
from unittest.mock import patch
33

44
import pytest
55

@@ -21,36 +21,6 @@ def client():
2121
return AtlanClient()
2222

2323

24-
@pytest.fixture()
25-
def current_client(client, monkeypatch):
26-
monkeypatch.setattr(
27-
AtlanClient,
28-
"get_current_client",
29-
lambda: client,
30-
)
31-
32-
33-
@pytest.fixture()
34-
def mock_group_cache(current_client, monkeypatch):
35-
mock_cache = MagicMock()
36-
monkeypatch.setattr(AtlanClient, "group_cache", mock_cache)
37-
return mock_cache
38-
39-
40-
@pytest.fixture()
41-
def mock_user_cache(current_client, monkeypatch):
42-
mock_cache = MagicMock()
43-
monkeypatch.setattr(AtlanClient, "user_cache", mock_cache)
44-
return mock_cache
45-
46-
47-
@pytest.fixture()
48-
def mock_role_cache(current_client, monkeypatch):
49-
mock_cache = MagicMock()
50-
monkeypatch.setattr(AtlanClient, "role_cache", mock_cache)
51-
return mock_cache
52-
53-
5424
@pytest.mark.parametrize(
5525
"name, connector_type, admin_users, admin_groups, admin_roles, message",
5626
[

tests/unit/model/data_product_test.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ def client():
3434
return AtlanClient()
3535

3636

37-
@pytest.fixture()
38-
def current_client(client, monkeypatch):
39-
monkeypatch.setattr(
40-
AtlanClient,
41-
"get_current_client",
42-
lambda: client,
43-
)
44-
45-
4637
def load_json(respones_dir, filename):
4738
with (respones_dir / filename).open() as input_file:
4839
return load(input_file)

tests/unit/test_atlan_tag_name.py

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from pydantic.v1 import parse_obj_as
55

66
import pyatlan.cache.atlan_tag_cache
7-
from pyatlan.client.atlan import AtlanClient
87
from pyatlan.model.assets import Purpose
98
from pyatlan.model.core import AtlanTagName
109

@@ -13,28 +12,8 @@
1312
GOOD_ATLAN_TAG_NAME = "PII"
1413

1514

16-
@pytest.fixture(autouse=True)
17-
def set_env(monkeypatch):
18-
monkeypatch.setenv("ATLAN_BASE_URL", "https://test.atlan.com")
19-
monkeypatch.setenv("ATLAN_API_KEY", "test-api-key")
20-
21-
22-
@pytest.fixture()
23-
def client():
24-
return AtlanClient()
25-
26-
2715
@pytest.fixture()
28-
def current_client(client, monkeypatch):
29-
monkeypatch.setattr(
30-
AtlanClient,
31-
"get_current_client",
32-
lambda: client,
33-
)
34-
35-
36-
@pytest.fixture()
37-
def good_atlan_tag(current_client: AtlanClient, monkeypatch):
16+
def good_atlan_tag(monkeypatch):
3817
def get_id_for_name(_, value):
3918
return ATLAN_TAG_ID
4019

@@ -46,7 +25,7 @@ def get_id_for_name(_, value):
4625
return AtlanTagName(GOOD_ATLAN_TAG_NAME)
4726

4827

49-
def test_init_with_good_name(current_client: AtlanClient, monkeypatch):
28+
def test_init_with_good_name(monkeypatch):
5029
def get_id_for_name(_, value):
5130
assert value == GOOD_ATLAN_TAG_NAME
5231
return GOOD_ATLAN_TAG_NAME
@@ -70,9 +49,7 @@ def test_convert_to_display_text_when_atlan_tag_passed_returns_same_atlan_tag(
7049
assert good_atlan_tag is AtlanTagName._convert_to_tag_name(good_atlan_tag)
7150

7251

73-
def test_convert_to_display_text_when_bad_string(
74-
current_client: AtlanClient, monkeypatch
75-
):
52+
def test_convert_to_display_text_when_bad_string(monkeypatch):
7653
def get_name_for_id(_, __):
7754
return None
7855

@@ -85,7 +62,7 @@ def get_name_for_id(_, __):
8562
assert AtlanTagName._convert_to_tag_name("bad").__repr__() == "AtlanTagName('bad')"
8663

8764

88-
def test_convert_to_tag_name(current_client: AtlanClient, monkeypatch):
65+
def test_convert_to_tag_name(monkeypatch):
8966
sut = AtlanTagName._convert_to_tag_name(ATLAN_TAG_ID)
9067

9168
assert str(sut) == ATLAN_TAG_ID
@@ -95,7 +72,7 @@ def test_convert_to_tag_name(current_client: AtlanClient, monkeypatch):
9572
# assert AtlanTagName.json_encode_atlan_tag(good_atlan_tag) == ATLAN_TAG_ID
9673

9774

98-
def test_asset_tag_name_field_deserialization(current_client: AtlanClient, monkeypatch):
75+
def test_asset_tag_name_field_deserialization(monkeypatch):
9976
def get_name_for_id(_, __):
10077
return None
10178

tests/unit/test_client.py

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from json import load, loads
77
from pathlib import Path
88
from re import escape
9-
from unittest.mock import DEFAULT, MagicMock, Mock, call, patch
9+
from unittest.mock import DEFAULT, Mock, call, patch
1010

1111
import pytest
1212
from pydantic.v1 import ValidationError
@@ -138,30 +138,6 @@ def client():
138138
return AtlanClient()
139139

140140

141-
@pytest.fixture()
142-
def current_client(client, monkeypatch):
143-
monkeypatch.setattr(
144-
AtlanClient,
145-
"get_current_client",
146-
lambda: client,
147-
)
148-
149-
150-
@pytest.fixture()
151-
def mock_cm_cache(current_client, monkeypatch):
152-
mock_cache = MagicMock()
153-
mock_cache.get_name_for_id.return_value = CM_NAME
154-
monkeypatch.setattr(AtlanClient, "custom_metadata_cache", mock_cache)
155-
return mock_cache
156-
157-
158-
@pytest.fixture()
159-
def mock_role_cache(current_client, monkeypatch):
160-
mock_cache = MagicMock()
161-
monkeypatch.setattr(AtlanClient, "role_cache", mock_cache)
162-
return mock_cache
163-
164-
165141
@pytest.fixture
166142
def group_client(mock_api_caller):
167143
return GroupClient(client=mock_api_caller)
@@ -1878,7 +1854,6 @@ def test_asset_retrieve_minimal_without_asset_type(
18781854

18791855

18801856
def test_user_create(
1881-
current_client,
18821857
mock_api_caller,
18831858
mock_role_cache,
18841859
):
@@ -1901,9 +1876,7 @@ def test_user_create(
19011876
mock_api_caller.reset_mock()
19021877

19031878

1904-
def test_user_create_with_info(
1905-
current_client, mock_api_caller, mock_role_cache, user_list_json
1906-
):
1879+
def test_user_create_with_info(mock_api_caller, mock_role_cache, user_list_json):
19071880
test_role_id = "role-guid-123"
19081881
client = UserClient(mock_api_caller)
19091882
mock_api_caller._call_api.side_effect = [
@@ -2724,7 +2697,7 @@ def test_get_all_sorting(group_client, mock_api_caller):
27242697
mock_api_caller.reset_mock()
27252698

27262699

2727-
def test_get_by_guid_asset_not_found_fluent_search(current_client):
2700+
def test_get_by_guid_asset_not_found_fluent_search():
27282701
guid = "123"
27292702
asset_type = Table
27302703

@@ -2745,9 +2718,7 @@ def test_get_by_guid_asset_not_found_fluent_search(current_client):
27452718
mock_execute.assert_called_once()
27462719

27472720

2748-
def test_get_by_guid_type_mismatch_fluent_search(
2749-
current_client: AtlanClient, mock_api_caller
2750-
):
2721+
def test_get_by_guid_type_mismatch_fluent_search(mock_api_caller):
27512722
guid = "123"
27522723
expected_asset_type = Table
27532724
returned_asset_type = View
@@ -2772,9 +2743,7 @@ def test_get_by_guid_type_mismatch_fluent_search(
27722743
mock_execute.assert_called_once()
27732744

27742745

2775-
def test_get_by_qualified_name_type_mismatch(
2776-
current_client: AtlanClient, mock_api_caller
2777-
):
2746+
def test_get_by_qualified_name_type_mismatch(mock_api_caller):
27782747
qualified_name = "example_qualified_name"
27792748
expected_asset_type = Table
27802749
returned_asset_type = View
@@ -2798,9 +2767,7 @@ def test_get_by_qualified_name_type_mismatch(
27982767
mock_execute.assert_called_once()
27992768

28002769

2801-
def test_get_by_qualified_name_asset_not_found(
2802-
current_client: AtlanClient, mock_api_caller
2803-
):
2770+
def test_get_by_qualified_name_asset_not_found(mock_api_caller):
28042771
qualified_name = "example_qualified_name"
28052772
asset_type = Table
28062773

tests/unit/test_connection_cache.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,14 @@ def client():
2222

2323

2424
@pytest.fixture()
25-
def current_client(client, monkeypatch):
26-
monkeypatch.setattr(
27-
AtlanClient,
28-
"get_current_client",
29-
lambda: client,
30-
)
31-
32-
33-
@pytest.fixture()
34-
def mock_connection_cache(current_client, monkeypatch):
35-
mock_cache = ConnectionCache(current_client)
25+
def mock_connection_cache(client, monkeypatch):
26+
mock_cache = ConnectionCache(client)
3627
monkeypatch.setattr(AtlanClient, "connection_cache", mock_cache)
3728
return mock_cache
3829

3930

40-
def test_get_by_guid_with_not_found_error(current_client):
41-
connection_cache = ConnectionCache(current_client)
31+
def test_get_by_guid_with_not_found_error(client):
32+
connection_cache = ConnectionCache(client)
4233
with pytest.raises(InvalidRequestError, match=ErrorCode.MISSING_ID.error_message):
4334
connection_cache.get_by_guid("")
4435

tests/unit/test_core.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,8 @@ def client():
2424

2525

2626
@pytest.fixture()
27-
def current_client(client, monkeypatch):
28-
monkeypatch.setattr(
29-
AtlanClient,
30-
"get_current_client",
31-
lambda: client,
32-
)
33-
34-
35-
@pytest.fixture()
36-
def mock_tag_cache(current_client, monkeypatch):
37-
mock_cache = MagicMock(current_client)
27+
def mock_tag_cache(client, monkeypatch):
28+
mock_cache = MagicMock(client)
3829
monkeypatch.setattr(AtlanClient, "atlan_tag_cache", mock_cache)
3930
return mock_cache
4031

0 commit comments

Comments
 (0)