Skip to content

Commit ebbd767

Browse files
committed
Refactors integration tests
Signed-off-by: Christopher Grote <cmgrote@users.noreply.github.com>
1 parent f68a99f commit ebbd767

6 files changed

Lines changed: 315 additions & 216 deletions

File tree

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ black==22.10.0
44
types-requests==2.28.11.17
55
pytest==7.3.1
66
pytest-order==1.1.0
7+
retry==0.9.2
78
pre-commit==2.20.0
89
deepdiff==6.2.1
910
pytest-cov==4.0.0
Lines changed: 56 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,84 @@
11
# SPDX-License-Identifier: Apache-2.0
22
# Copyright 2022 Atlan Pte. Ltd.
3-
from typing import Generator
3+
import time
4+
from typing import Generator, Callable
45

56
import pytest
67

78
from pyatlan.cache.classification_cache import ClassificationCache
89
from pyatlan.client.atlan import AtlanClient
10+
from pyatlan.error import AtlanError
911
from pyatlan.model.enums import AtlanClassificationColor, AtlanTypeCategory
1012
from pyatlan.model.typedef import ClassificationDef
1113

14+
from retry import retry
15+
import logging
16+
17+
LOGGER = logging.getLogger(__name__)
18+
19+
1220
CLS_NAME = "psdk-classification"
1321

1422

15-
class ClassificationTest:
16-
@staticmethod
17-
def create_classification(client: AtlanClient, name: str) -> ClassificationDef:
23+
@pytest.fixture(scope="session", autouse=True)
24+
def make_classification(
25+
client: AtlanClient,
26+
) -> Generator[Callable[[str], ClassificationDef], None, None]:
27+
created_names = []
28+
29+
@retry(
30+
AtlanError,
31+
delay=1,
32+
tries=3,
33+
max_delay=5,
34+
backoff=2,
35+
jitter=(0, 1),
36+
logger=LOGGER,
37+
)
38+
def _wait_for_successful_purge(name: str):
39+
client.purge_typedef(name)
40+
41+
def _make_classification(name: str) -> ClassificationDef:
1842
classification_def = ClassificationDef.create(
1943
name=name, color=AtlanClassificationColor.GREEN
2044
)
21-
response = client.create_typedef(classification_def)
22-
assert response
23-
assert len(response.classification_defs) == 1
24-
created = response.classification_defs[0]
25-
assert created.category == AtlanTypeCategory.CLASSIFICATION
26-
assert created.name
27-
assert created.guid
28-
assert created.name != name
29-
assert created.display_name == name
30-
return created
31-
32-
@staticmethod
33-
def delete_classification(client: AtlanClient, cls: ClassificationDef) -> None:
34-
client.purge_typedef(cls.name)
45+
r = client.create_typedef(classification_def)
46+
c = r.classification_defs[0]
47+
created_names.append(c.name)
48+
return c
3549

50+
yield _make_classification
3651

37-
@pytest.fixture(scope="session")
38-
def client() -> AtlanClient:
39-
return AtlanClient()
52+
for n in created_names:
53+
try:
54+
_wait_for_successful_purge(n)
55+
except AtlanError as err:
56+
LOGGER.error(err)
4057

4158

4259
@pytest.fixture(scope="module")
43-
def classification_def(client: AtlanClient) -> Generator[ClassificationDef, None, None]:
44-
c = ClassificationTest.create_classification(client, CLS_NAME)
45-
yield c
46-
ClassificationTest.delete_classification(client, c)
60+
def classification_def(
61+
client: AtlanClient, make_classification: Callable[[str], ClassificationDef]
62+
) -> ClassificationDef:
63+
return make_classification(CLS_NAME)
64+
65+
66+
def test_classification_def(classification_def: ClassificationDef):
67+
assert classification_def
68+
assert classification_def.guid
69+
assert classification_def.display_name == CLS_NAME
70+
assert classification_def.name != CLS_NAME
71+
assert classification_def.options
72+
assert "color" in classification_def.options.keys()
73+
assert (
74+
classification_def.options.get("color") == AtlanClassificationColor.GREEN.value
75+
)
4776

4877

49-
@pytest.mark.usefixtures("classification_def")
50-
def test_classification_cache():
78+
def test_classification_cache(classification_def: ClassificationDef):
5179
cls_id = ClassificationCache.get_id_for_name(CLS_NAME)
5280
assert cls_id
81+
assert cls_id == classification_def.name
5382
cls_name = ClassificationCache.get_name_for_id(cls_id)
5483
assert cls_name
5584
assert cls_name == CLS_NAME

tests/integration/client.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright 2022 Atlan Pte. Ltd.
3+
from typing import Type
4+
5+
import pytest
6+
7+
from pyatlan.client.atlan import AtlanClient
8+
from pyatlan.model.response import A
9+
10+
import logging
11+
12+
LOGGER = logging.getLogger(__name__)
13+
14+
15+
@pytest.fixture(scope="session", autouse=True)
16+
def client() -> AtlanClient:
17+
return AtlanClient()
18+
19+
20+
def delete_asset(client: AtlanClient, asset_type: Type[A], guid: str) -> None:
21+
# These assertions check the cleanup actually worked
22+
r = client.purge_entity_by_guid(guid)
23+
s = r is not None
24+
s = s and len(r.assets_deleted(asset_type)) == 1
25+
s = s and r.assets_deleted(asset_type)[0].guid == guid
26+
if not s:
27+
LOGGER.error(f"Failed to remove {asset_type} with GUID {guid}.")

tests/integration/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pytest_plugins = [
2+
"tests.integration.client",
3+
"tests.integration.glossary_test",
4+
"tests.integration.classification_test",
5+
]

0 commit comments

Comments
 (0)