14
14
import subprocess
15
15
import sys
16
16
import urllib .request
17
+ import unittest
17
18
18
- elasticurl_path = sys .argv [ 1 ]
19
+ elasticurl_path = sys .argv . pop ()
19
20
shell = sys .platform .startswith ('win' )
20
21
21
22
if elasticurl_path == None :
25
26
def run_command (args ):
26
27
subprocess .check_call (args , shell = shell )
27
28
29
+
30
+ class SimpleTests (unittest .TestCase ):
28
31
#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 )
31
35
32
36
#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 )
35
40
36
41
#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 )
39
45
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' )
41
47
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