@ -3,7 +3,7 @@ import json
from typing import List , Tuple
from tests . createAPI . create_delete_tag_category import test_tag_category_entries , list_tag_categories , \
create_tag_categories , delete_category_entries
create_tag_categories , delete_category_entries , delete_tag_category
test_tag_entries = [ { " name " : " tag1 " , " description " : " description1 " , " category_id " : 0 , " id " : None } ,
{ " name " : " tag2 " , " description " : " description2 " , " category_id " : 0 , " id " : None } ,
@ -70,6 +70,27 @@ def update_tag_entries(url: str, port: int):
f " Current: { new_tag [ ' category_id ' ] } Expected: { new_categ } " )
raise Exception ( " Update Tag Entry Test: FAILED " )
def delete_some_tag_entries_via_category ( url : str , port : int , tag_index : int ) :
"""
Delete the tags by deleting their category and expecting that to delete the tags too .
: param url :
: param port :
: param tag_index : an index of test_tag_entries indicating which tag to target
: return :
"""
r = delete_tag_category ( url , port ,
category_id = test_tag_category_entries [ test_tag_entries [ tag_index ] [ " category_id " ] ] [ " id " ] )
if r . status_code != 200 :
print ( f " Deleting a tag category Nr. { 2 } failed with { r . status_code } and reason { r . text } " )
raise Exception ( " Delete Tag via Category Cascade Test: ERROR " )
tag = get_tag_by_ID ( url , port , tag_id = test_tag_entries [ tag_index ] [ " id " ] )
if ' detail ' not in tag . keys ( ) and tag [ " detail " ] == ' No matching tag found! ' :
print ( f " Failed to delete tag via deleting their category with status { r . status_code } and reason { r . text } " )
raise Exception ( " Deleting Tag via Category Cascade Test: FAILED " )
def delete_tag_entries ( url : str , port : int ) :
"""
@ -96,7 +117,7 @@ def get_tag_by_ID(url: str, port: int, tag_id: int):
"""
r = requests . get ( f " http:// { url } : { port } /artnet/metadata/tag?id= { tag_id } " )
if r . status_code != 200 :
if r . status_code != 200 and r . status_code != 404 :
raise Exception ( " Failed querying for tag! " )
return json . loads ( r . text )
@ -169,13 +190,24 @@ def run_tag_test(url: str, port: int):
update_tag_entries ( url , port )
update_tag_result = True
print ( " Finished updating the tags! " )
print ( )
# Delete test
print ( f " Found { len ( list_tags ( url , port ) ) } tag entries! " )
print ( " Deleting the tag entries ... " )
delete_tag_entries ( url , port ) # would throw an exception if an error occurred
delete_tag_result = False if not len ( list_tags ( url , port ) ) == 0 else True
print ( f " Found { len ( list_tags ( url , port ) ) } tag entries! " )
print ( )
# Creating tags for cascade deleting test
print ( " Preparing tag category cascade deletion test ... " )
create_tag_entries ( url , port )
# Delete via Category test
delete_some_tag_entries_via_category ( url , port , tag_index = 0 ) # should delete 3 tags in total, leaving 1 behind
delete_tag_category_cascade_result = False if not len ( list_tags ( url , port ) ) == 1 else True
print ( )
# Clean up
print ( " Cleaning tag categories up ... " )
@ -183,7 +215,8 @@ def run_tag_test(url: str, port: int):
print ( f " Tag test complete with { len ( list_tags ( url , port ) ) } tags and "
f " { len ( list_tag_categories ( url , port ) ) } categories! " )
return create_tag_result , update_tag_result , delete_tag_result # create, update, delete
return create_tag_result , update_tag_result , delete_tag_result , delete_tag_category_cascade_result
# create, update, delete, delete-category-cascade
if __name__ == " __main__ " :