Skip to content

Commit f0cdbbd

Browse files
committed
add tests
1 parent 0a355cd commit f0cdbbd

File tree

5 files changed

+69
-17
lines changed

5 files changed

+69
-17
lines changed

labelbox/client.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,3 +906,27 @@ def create_feature_schema(self, normalized):
906906
# But the features are the same so we just grab the feature schema id
907907
res['id'] = res['normalized']['featureSchemaId']
908908
return Entity.FeatureSchema(self, res)
909+
910+
def create_resource_tag(self, tag=None):
911+
"""
912+
Creates a resource tag.
913+
>>> tag = {'text': 'tag-1', 'color': 'ffffff'}
914+
915+
Args:
916+
tag (dict): A resource tag {'text': 'tag-1', 'color': 'fffff'}
917+
Returns:
918+
The created resource tag.
919+
"""
920+
tag_text_param = "text"
921+
tag_color_param = "color"
922+
923+
query_str = """mutation CreateResourceTagPyApi($text:String!,$color:String!) {
924+
createResourceTag(input:{text:$%s,color:$%s}) {id,text,color}}
925+
""" % (tag_text_param, tag_color_param)
926+
927+
params = {
928+
tag_text_param: tag.get("text", ""),
929+
tag_color_param: tag.get("color", "")
930+
}
931+
res = self.execute(query_str, params)
932+
return Entity.ResourceTag(self, res['createResourceTag'])

labelbox/schema/organization.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,7 @@ def get_resource_tags(self) -> List["ResourceTag"]:
131131
"""
132132
Returns all resource tags for an organization
133133
"""
134-
res = self.client.execute(
135-
"""query {
136-
organization {
137-
resourceTag {
138-
id,
139-
text,
140-
color
141-
}
142-
}
143-
}""")
134+
res = self.client.execute("""query GetOrganizationResourceTagsPyApi{organization{resourceTag{id,text,color}}}""")
144135

145136
return res['organization']['resourceTag']
146137

labelbox/schema/project.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,8 @@ def create_project_resource_tags(self, resource_tag_ids: List[str]) -> List[str]
132132
project_id_param = "projectId"
133133
tag_ids_param = "resourceTagIds"
134134

135-
query_str = """mutation AttatchProjectResourceTags($%s: ID!, $%s: [String!]) {
136-
project(where:{id:$%s}){updateProjectResourceTags(input:{%s:$%s}){id}}
137-
}""" % (
135+
query_str = """mutation AttatchProjectResourceTagsPyApi($%s:ID!,$%s:[String!]) {
136+
project(where:{id:$%s}){updateProjectResourceTags(input:{%s:$%s}){id}}}""" % (
138137
project_id_param,
139138
tag_ids_param,
140139
project_id_param,

labelbox/schema/resource_tag.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
from labelbox.orm.db_object import DbObject
1+
from labelbox.orm.db_object import DbObject, Updateable
22
from labelbox.orm.model import Field, Relationship
33

4-
class ResourceTag(DbObject):
4+
class ResourceTag(DbObject, Updateable):
55
""" Resource tag to label and identify your labelbox resources easier.
66
77
Attributes:

tests/integration/test_project.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,47 @@ def test_project(client, rand_gen):
4242
assert project not in final
4343
assert set(final) == set(before)
4444

45-
# TODO this should raise ResourceNotFoundError, but it doesn't
46-
project = client.get_project(project.uid)
45+
def test_create_project_resource_tags(client, rand_gen):
46+
before = list(client.get_projects())
47+
for o in before:
48+
assert isinstance(o, Project)
49+
50+
colorA = "#ffffff"
51+
textA = rand_gen(str)
52+
tag = {"text": textA, "color": colorA}
53+
54+
colorB = colorA
55+
textB = rand_gen(str)
56+
tagB = {"text": textB, "color": colorB}
57+
58+
project_name = rand_gen(str)
59+
60+
tagA = client.create_resource_tag(tag)
61+
assert tagA.text == textA
62+
assert '#' + tagA.color == colorA
63+
assert tagA.uid is not None
64+
65+
org = client.get_organization()
66+
tags = org.get_resource_tags()
67+
lenA = len(tags)
68+
assert lenA > 0
69+
70+
tagB = client.create_resource_tag(tagB)
71+
assert tagB.text == textB
72+
assert '#' + tagB.color == colorB
73+
assert tagB.uid is not None
74+
75+
tags = org.get_resource_tags()
76+
lenB = len(tags)
77+
assert lenB > 0
78+
assert lenB > lenA
79+
80+
p1 = client.create_project(name=project_name)
81+
assert p1.uid is not None
4782

83+
project_resource_tag = p1.create_project_resource_tags([tagA.uid])
84+
assert len(project_resource_tag) == 1
85+
assert project_resource_tag[0].get("id") == tagA.uid
4886

4987
def test_project_filtering(client, rand_gen):
5088
name_1 = rand_gen(str)

0 commit comments

Comments
 (0)