@ -9,10 +9,13 @@ from tests.createAPI.create_delete_presence import test_presence_entries, list_p
test_art_entries = [
{ " hash " : " hash1 " , " path " : " artist1/image1 " , " title " : " Image Title 1 " , " link " : " http://localhost/artist1/image1.png " ,
" description " : " description Nr. 1 " ,
" presences " : [ ( test_presence_entries [ 0 ] [ " name " ] , test_presence_entries [ 0 ] [ " domain " ] ) ] } ,
{ " hash " : " hash2 " , " path " : " artist1/image2 " , " title " : " Image Title 2 " , " link " : " http://localhost/artist1/image2.png " ,
" description " : " description Nr. 2 " ,
" presences " : [ ( test_presence_entries [ 1 ] [ " name " ] , test_presence_entries [ 1 ] [ " domain " ] ) ] } ,
{ " hash " : " hash3 " , " path " : " artist2/image1 " , " title " : " Image Title 3 " , " link " : " http://localhost/artist2/image3.png " ,
" description " : " description Nr. 3 " ,
" presences " : [ ( test_presence_entries [ 0 ] [ " name " ] , test_presence_entries [ 0 ] [ " domain " ] ) ,
( test_presence_entries [ 1 ] [ " name " ] , test_presence_entries [ 1 ] [ " domain " ] ) ] } ,
]
@ -42,7 +45,7 @@ def create_art_entries(url: str, port: int):
for i in range ( len ( test_art_entries ) ) :
r = create_art ( url , port , md5_hash = test_art_entries [ i ] [ " hash " ] , path = test_art_entries [ i ] [ " path " ] ,
title = test_art_entries [ i ] [ " title " ] , link = test_art_entries [ i ] [ " link " ] ,
presences = test_art_entries [ i ] [ " presences " ] )
presences = test_art_entries [ i ] [ " presences " ] , description = test_art_entries [ i ] [ " description " ] )
if r . status_code != 200 :
print ( f " Create Art Entry Test Nr. { i } : failed with { r . status_code } and reason { r . text } " )
raise Exception ( " Create Art Entry Test: FAILED " )
@ -57,7 +60,8 @@ def update_art_entries(url: str, port: int):
r = update_art ( url , port , md5_hash = test_art_entries [ i ] [ " hash " ] + " moreHash " ,
path = test_art_entries [ i ] [ " path " ] + " evenBetterPath " ,
title = test_art_entries [ i ] [ " title " ] + " updated " ,
presences = test_art_entries [ i ] [ " presences " ] , art_id = test_art_entries [ i ] [ " ID " ] )
presences = test_art_entries [ i ] [ " presences " ] , art_id = test_art_entries [ i ] [ " ID " ] ,
description = test_art_entries [ i ] [ " description " ] + " evenBetterDescription " )
if r . status_code != 200 :
print ( f " Update Art Entry Test Nr. { i } : failed with { r . status_code } and reason { r . text } " )
@ -65,10 +69,13 @@ def update_art_entries(url: str, port: int):
for i in range ( len ( test_art_entries ) ) :
r = requests . get ( f " http:// { url } : { port } /artnet/metadata/art?id= { urllib . parse . quote ( str ( test_art_entries [ i ] [ ' ID ' ] ) ) } " )
if json . loads ( r . text ) [ " title " ] . split ( " " ) [ - 1 ] != " updated " :
response = json . loads ( r . text )
if response [ " title " ] . split ( " " ) [ - 1 ] != " updated " :
raise Exception ( " Update Art Entry Test: Failed (unexpected or no updated title) " )
if json. loads ( r . text ) [ " link " ] != test_art_entries [ i ] [ " link " ] :
if response [ " link " ] != test_art_entries [ i ] [ " link " ] :
raise Exception ( " Update Art Entry Test: Failed (unexpected link) " )
if response [ " description " ] . split ( " " ) [ - 1 ] != " evenBetterDescription " :
raise Exception ( " Update Art Entry Test: Failed (unexpected description) " )
print ( " Updated art entries: SUCCESS " )
@ -88,16 +95,18 @@ def delete_art_entries(url: str, port: int):
print ( " Deleted art entries: SUCCESS " )
def create_art ( url : str , port : int , md5_hash : str , path : str , title : str , link : str , presences : List [ Tuple [ str , str ] ] ) :
def create_art ( url : str , port : int , md5_hash : str , path : str , title : str , link : str , description : str ,
presences : List [ Tuple [ str , str ] ] ) :
r = requests . post ( f " http:// { url } : { port } /artnet/metadata/art " ,
json = { " hash " : md5_hash , " path " : path , " title " : title , " link " : link ,
" presences " : [ { " name " : presence [ 0 ] , " domain " : presence [ 1 ] } for presence in presences ] } )
" presences " : [ { " name " : presence [ 0 ] , " domain " : presence [ 1 ] } for presence in presences ] ,
" description " : description } )
return r
def update_art ( url : str , port : int , art_id : int , md5_hash : str = None , path : str = None , title : str = None ,
link : str = None , presences: List [ Tuple [ str , str ] ] = None ) :
link : str = None , description: str = None , presences: List [ Tuple [ str , str ] ] = None ) :
body = { }
if md5_hash is not None :
body [ " hash " ] = md5_hash
@ -109,6 +118,8 @@ def update_art(url: str, port: int, art_id: int, md5_hash: str = None, path: str
body [ " link " ] = link
if presences is not None :
body [ " presences " ] = [ { " name " : presence [ 0 ] , " domain " : presence [ 1 ] } for presence in presences ]
if description is not None :
body [ " description " ] = description
r = requests . post ( f " http:// { url } : { port } /artnet/metadata/art?id= { urllib . parse . quote ( str ( art_id ) ) } " ,
json = body )
@ -138,7 +149,7 @@ def run_art_test(url: str, port: int):
print ( )
print ( " ---------------- " )
print ( f " Starting presence test with "
print ( f " Starting art test with "
f " ( { len ( list_artists ( url , port ) ) } ) artists, ( { len ( list_presences ( url , port ) ) } ) presences, "
f " ( { len ( list_art ( url , port ) ) } ) art! " )
print ( " Setting up artist and presences for the art test ... " )