1414import subprocess
1515import sys
1616import urllib .request
17+ import unittest
1718
18- elasticurl_path = sys .argv [ 1 ]
19+ elasticurl_path = sys .argv . pop ()
1920shell = sys .platform .startswith ('win' )
2021
2122if elasticurl_path == None :
2526def run_command (args ):
2627 subprocess .check_call (args , shell = shell )
2728
29+
30+ class SimpleTests (unittest .TestCase ):
2831#make a simple GET request and make sure it succeeds
29- simple_get_args = [elasticurl_path , '-v' , 'TRACE' , 'example.com' ]
30- run_command (simple_get_args )
32+ def test_simple_get (self ):
33+ simple_get_args = [elasticurl_path , '-v' , 'TRACE' , 'http://example.com' ]
34+ run_command (simple_get_args )
3135
3236#make a simple POST request to make sure sending data succeeds
33- simple_post_args = [elasticurl_path , '-v' , 'TRACE' , '-P' , '-H' , 'content-type: application/json' , '-i' , '-d' , '\" {\' test\' :\' testval\' }\" ' , 'http://httpbin.org/post' ]
34- run_command (simple_post_args )
37+ def test_simple_post (self ):
38+ simple_post_args = [elasticurl_path , '-v' , 'TRACE' , '-P' , '-H' , 'content-type: application/json' , '-i' , '-d' , '\" {\' test\' :\' testval\' }\" ' , 'http://httpbin.org/post' ]
39+ run_command (simple_post_args )
3540
3641#download a large file and compare the results with something we assume works (e.g. urllib)
37- elasticurl_download_args = [elasticurl_path , '-v' , 'TRACE' , '-o' , 'elastigirl.png' , 'https://s3.amazonaws.com/code-sharing-aws-crt/elastigirl.png' ]
38- run_command (elasticurl_download_args )
42+ def test_simple_download (self ):
43+ elasticurl_download_args = [elasticurl_path , '-v' , 'TRACE' , '-o' , 'elastigirl.png' , 'https://s3.amazonaws.com/code-sharing-aws-crt/elastigirl.png' ]
44+ run_command (elasticurl_download_args )
3945
40- urllib .request .urlretrieve ('https://s3.amazonaws.com/code-sharing-aws-crt/elastigirl.png' , 'elastigirl_expected.png' )
46+ urllib .request .urlretrieve ('https://s3.amazonaws.com/code-sharing-aws-crt/elastigirl.png' , 'elastigirl_expected.png' )
4147
42- if not filecmp .cmp ('elastigirl.png' , 'elastigirl_expected.png' ):
43- print ('downloaded files do not match, exiting with error....' )
44- sys .exit (- 1 )
48+ if not filecmp .cmp ('elastigirl.png' , 'elastigirl_expected.png' , shallow = False ):
49+ raise RuntimeError ('downloaded files do not match' )
50+
51+ if __name__ == '__main__' :
52+ unittest .main ()
0 commit comments