Skip to content

Commit b8439c5

Browse files
committed
update to test_project. still leaving as skip as there is an issue with tag fetching. also updated resource creation code for better error messaging
1 parent 0cc92fa commit b8439c5

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

labelbox/schema/organization.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import TYPE_CHECKING, List, Optional
2+
from typing import TYPE_CHECKING, List, Optional, Dict
33

44
from labelbox.exceptions import LabelboxError
55
from labelbox import utils
@@ -129,7 +129,7 @@ def remove_user(self, user: "User") -> None:
129129
updateUser(where: {id: $%s}, data: {deleted: true}) { id deleted }
130130
}""" % (user_id_param, user_id_param), {user_id_param: user.uid})
131131

132-
def create_resource_tag(self, tag=None) -> ResourceTag:
132+
def create_resource_tag(self, tag: Dict[str, str]) -> ResourceTag:
133133
"""
134134
Creates a resource tag.
135135
>>> tag = {'text': 'tag-1', 'color': 'ffffff'}
@@ -148,9 +148,13 @@ def create_resource_tag(self, tag=None) -> ResourceTag:
148148
query.results_query_part(ResourceTag))
149149

150150
params = {
151-
tag_text_param: tag.get("text", ""),
152-
tag_color_param: tag.get("color", "")
151+
tag_text_param: tag.get("text", None),
152+
tag_color_param: tag.get("color", None)
153153
}
154+
if not all(params.values()):
155+
raise ValueError(
156+
f"tag must contain 'text' and 'color' keys. received: {tag}")
157+
154158
res = self.client.execute(query_str, params)
155159
return ResourceTag(self.client, res['createResourceTag'])
156160

tests/integration/test_project.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from re import A
23
import time
34
import os
45

@@ -45,10 +46,22 @@ def test_project(client, rand_gen):
4546

4647

4748
@pytest.mark.skip(
48-
reason="this will fail if run multiple times, limit is defaulted to 3 per org"
49-
"add this back in when either all test orgs have unlimited, or we delete all tags befoer running"
50-
)
49+
reason="""Querying for resource tag intermittently not working.\n
50+
Additionally, unsure if this should be resourceTag or resourceTags, but Tags causes
51+
'Internal server error' """)
5152
def test_update_project_resource_tags(client, rand_gen):
53+
54+
def delete_tag(tag_id: str):
55+
"""Deletes a tag given the tag uid. Currently internal use only so this is not public"""
56+
res = client.execute(
57+
"""mutation deleteResourceTagPyApi($tag_id: String!) {
58+
deleteResourceTag(input: {id: $tag_id}) {
59+
id
60+
}
61+
}
62+
""", {"tag_id": tag_id})
63+
return res
64+
5265
before = list(client.get_projects())
5366
for o in before:
5467
assert isinstance(o, Project)
@@ -92,6 +105,9 @@ def test_update_project_resource_tags(client, rand_gen):
92105
assert len(project_resource_tag) == 1
93106
assert project_resource_tag[0].uid == tagA.uid
94107

108+
delete_tag(tagA.uid)
109+
delete_tag(tagB.uid)
110+
95111

96112
def test_project_filtering(client, rand_gen):
97113
name_1 = rand_gen(str)

0 commit comments

Comments
 (0)