@@ -122,6 +122,7 @@ def test_get_node_url():
122122
123123 response = Mock (spec = requests .Response )
124124 response .status_code = 303
125+
125126 resource_id = 'ivo://cadc.nrc.ca/vospace'
126127 session_mock = Mock (spec = requests .Session , get = Mock (return_value = response ))
127128 session_mock .headers = Mock ()
@@ -143,39 +144,28 @@ def test_get_node_url():
143144 order = 'desc' )).query
144145 assert ('order=desc' == unquote (equery ))
145146
146- # test header view
147+ # test files URL
147148 transfer_url = 'https://mystorage.org/minoc/files/abc:VOS/002'
148- client .transfer = Mock (return_value = [transfer_url ])
149- expected_url = transfer_url + '?META=true'
150- assert expected_url == \
149+ response .headers = {'Location' : transfer_url }
150+ mock_session = Mock (spec = requests .Session , get = Mock (return_value = response ))
151+ client .get_session = Mock (return_value = mock_session )
152+ client ._fs_type = False
153+ assert transfer_url == \
151154 client .get_node_url ('vos://cadc.nrc.ca!vospace/auser' ,
152- view = 'header' )[0 ]
155+ view = 'header' )
156+
157+ # test fits header
158+ assert transfer_url + "?META=true" == client ._add_soda_ops (transfer_url , view = 'header' )
153159
154160 # test pixel cutouts
155- transfer_url1 = 'https://mystorage.org/minoc/files/abc:VOS/001'
156- transfer_url2 = 'https://myotherstorage.org/minoc/files/abc:VOS/001'
157- client .transfer = Mock (return_value = [transfer_url1 , transfer_url2 ])
158161 pcutout = '[1][100:125,100:175]'
159- expected_url1 = transfer_url1 + '?SUB=' + pcutout
160- expected_url2 = transfer_url2 + '?SUB=' + pcutout
161- assert expected_url1 == \
162- client .get_node_url ('vos://cadc.nrc.ca!vospace/auser' ,
163- cutout = pcutout , view = 'cutout' )[0 ]
164- assert expected_url2 == \
165- client .get_node_url ('vos://cadc.nrc.ca!vospace/auser' ,
166- cutout = pcutout , view = 'cutout' )[1 ]
162+ assert transfer_url + "?SUB=" + pcutout == client ._add_soda_ops (transfer_url ,
163+ cutout = pcutout )
167164
168165 # test sky coordinates
169- client .transfer = Mock (return_value = [transfer_url1 , transfer_url2 ])
170- scutout = 'CIRCLE=' + urllib .parse .quote ('(1.1 2.2 3.3' )
171- expected_url1 = transfer_url1 + '?' + scutout
172- expected_url2 = transfer_url2 + '?' + scutout
173- assert expected_url1 == \
174- client .get_node_url ('vos://cadc.nrc.ca!vospace/auser' ,
175- cutout = scutout , view = 'cutout' )[0 ]
176- assert expected_url2 == \
177- client .get_node_url ('vos://cadc.nrc.ca!vospace/auser' ,
178- cutout = scutout , view = 'cutout' )[1 ]
166+ scutout = '1.1,2.2,3.3'
167+ assert (transfer_url + "?CIRCLE=" + urllib .parse .quote (scutout ) ==
168+ client ._add_soda_ops (transfer_url , cutout = 'CIRCLE=' + scutout ))
179169
180170
181171class TestClient (unittest .TestCase ):
@@ -444,6 +434,7 @@ def is_remote_file(uri):
444434 os .remove (osLocation )
445435 # copy from vospace
446436 test_client .is_remote_file = is_remote_file
437+ test_client .get_endpoints = Mock ()
447438 test_client .copy (vospaceLocation , osLocation )
448439 get_node_url_mock .assert_called_once_with (vospaceLocation ,
449440 method = 'GET' ,
@@ -488,11 +479,21 @@ def is_remote_file(uri):
488479 response .iter_content .return_value = BytesIO (file_content )
489480 session .get .return_value = response
490481 test_client .get_session = Mock (return_value = session )
482+ # client must be a vault client
483+ test_client ._fs_type = False
491484 test_client .copy ('{}{}' .format (vospaceLocation ,
492485 '[1][10:60]' ), osLocation )
493486 get_node_url_mock .assert_called_once_with (
494487 vospaceLocation , method = 'GET' , cutout = '[1][10:60]' , view = 'cutout' )
495488
489+ # test cavern does not support SODA operations
490+ test_client ._fs_type = True
491+ with pytest .raises (ValueError ):
492+ test_client .copy ('{}{}' .format (vospaceLocation , '[1][10:60]' ), osLocation )
493+ with pytest .raises (ValueError ):
494+ test_client .copy (vospaceLocation , osLocation , head = True )
495+
496+ test_client ._fs_type = False
496497 # copy to vospace when md5 sums are the same -> only update occurs
497498 get_node_url_mock .reset_mock ()
498499 computed_md5_mock .reset_mock ()
@@ -603,8 +604,8 @@ def is_remote_file(uri):
603604
604605 # test GET intermittent exceptions on both URLs
605606 props .get .side_effect = md5sum
606- get_node_url_mock = Mock (
607- return_value = ['http://cadc1.ca/test' , 'http://cadc2.ca/test' ])
607+ # first side effect corresponds to the files end point call, the second to full negotiation
608+ get_node_url_mock = Mock ( side_effect = ['http://cadc1.ca/test' , [ 'http://cadc2.ca/test' ] ])
608609 test_client .get_node_url = get_node_url_mock
609610 get_node_mock .reset_mock ()
610611 response .iter_content .return_value = BytesIO (file_content )
@@ -613,13 +614,13 @@ def is_remote_file(uri):
613614 session .get .side_effect = \
614615 [exceptions .TransferException ()] * 2 * vos .MAX_INTERMTTENT_RETRIES
615616 with pytest .raises (OSError ):
616- test_client .copy (vospaceLocation , osLocation , head = True )
617+ test_client .copy (vospaceLocation , osLocation , head = False )
617618 assert session .get .call_count == 2 * vos .MAX_INTERMTTENT_RETRIES
618619
619620 # test GET Transfer error on one URL and a "permanent" one on the other
620621 props .get .side_effect = md5sum
621622 get_node_url_mock = Mock (
622- return_value = [ 'http://cadc1.ca/test' , 'http://cadc2.ca/test' ])
623+ side_effect = [ None , [ 'http://cadc1.ca/test' , 'http://cadc2.ca/test' ] ])
623624 test_client .get_node_url = get_node_url_mock
624625 get_node_mock .reset_mock ()
625626 response .iter_content .return_value = BytesIO (file_content )
@@ -636,7 +637,7 @@ def is_remote_file(uri):
636637 # test GET both "permanent" errors
637638 props .get .side_effect = md5sum
638639 get_node_url_mock = Mock (
639- return_value = ['http://cadc1.ca/test' , 'http://cadc2.ca/test' ])
640+ side_effect = ['http://cadc1.ca/test' , [ 'http://cadc2.ca/test' ] ])
640641 test_client .get_node_url = get_node_url_mock
641642 get_node_mock .reset_mock ()
642643 response .iter_content .return_value = BytesIO (file_content )
0 commit comments