|
15 | 15 |
|
16 | 16 | import datetime
|
17 | 17 |
|
18 |
| -import pytest |
19 | 18 | from sagemaker.lineage import association
|
20 | 19 |
|
21 | 20 |
|
22 |
| -@pytest.mark.skip(reason="Not in CMH yet") |
23 | 21 | def test_create_delete(association_obj):
|
24 | 22 | # fixture does create and then delete, this test ensures it happens at least once
|
25 | 23 | assert association_obj.source_arn
|
26 | 24 |
|
27 | 25 |
|
28 |
| -@pytest.mark.skip(reason="Not in CMH yet") |
29 | 26 | def test_list(association_objs, sagemaker_session):
|
30 | 27 | slack = datetime.timedelta(minutes=1)
|
31 | 28 | now = datetime.datetime.now(datetime.timezone.utc)
|
32 | 29 | association_keys = [
|
33 |
| - assoc_obj.source_arn + ":" + assoc_obj.destination_arn for assoc_obj in association_objs |
| 30 | + assoc_obj.source_arn + ":" + assoc_obj.destination_arn |
| 31 | + for assoc_obj in association_objs |
34 | 32 | ]
|
35 | 33 |
|
36 | 34 | for sort_order in ["Ascending", "Descending"]:
|
37 | 35 | association_keys_listed = []
|
| 36 | + source_arn = [assoc_obj.source_arn for assoc_obj in association_objs][0] |
38 | 37 | listed = association.Association.list(
|
| 38 | + source_arn=source_arn, |
39 | 39 | created_after=now - slack,
|
40 | 40 | created_before=now + slack,
|
41 | 41 | sort_by="CreationTime",
|
42 | 42 | sort_order=sort_order,
|
43 | 43 | sagemaker_session=sagemaker_session,
|
44 | 44 | )
|
| 45 | + |
45 | 46 | for assoc in listed:
|
46 | 47 | key = assoc.source_arn + ":" + assoc.destination_arn
|
47 | 48 | if key in association_keys:
|
48 | 49 | association_keys_listed.append(key)
|
49 | 50 |
|
50 | 51 | if sort_order == "Descending":
|
51 | 52 | association_names_listed = association_keys_listed[::-1]
|
52 |
| - assert association_keys == association_names_listed |
| 53 | + assert association_keys[::-1] == association_names_listed |
53 | 54 | # sanity check
|
54 | 55 | assert association_keys_listed
|
55 | 56 |
|
56 | 57 |
|
57 |
| -@pytest.mark.skip(reason="Not in CMH yet") |
58 | 58 | def test_set_tag(association_obj, sagemaker_session):
|
59 | 59 | tag = {"Key": "foo", "Value": "bar"}
|
60 | 60 | association_obj.set_tag(tag)
|
61 |
| - assert association_obj.get_tag() == tag |
| 61 | + |
| 62 | + while True: |
| 63 | + actual_tags = sagemaker_session.sagemaker_client.list_tags( |
| 64 | + ResourceArn=association_obj.source_arn |
| 65 | + )["Tags"] |
| 66 | + if actual_tags: |
| 67 | + break |
| 68 | + assert len(actual_tags) == 1 |
| 69 | + assert actual_tags[0] == tag |
| 70 | + |
| 71 | + |
| 72 | +def test_tags(association_obj, sagemaker_session): |
| 73 | + tags = [{"Key": "foo1", "Value": "bar1"}] |
| 74 | + association_obj.set_tags(tags) |
| 75 | + |
| 76 | + while True: |
| 77 | + actual_tags = sagemaker_session.sagemaker_client.list_tags( |
| 78 | + ResourceArn=association_obj.source_arn |
| 79 | + )["Tags"] |
| 80 | + if actual_tags: |
| 81 | + break |
| 82 | + assert len(actual_tags) == 1 |
| 83 | + assert actual_tags == tags |
0 commit comments