1+ import pytest
12from unittest import TestCase
23from urllib .parse import urlparse , parse_qs
34
@@ -26,9 +27,11 @@ def test_basic_archive(self):
2627 assert out == out2 , (out , out2 )
2728
2829 def test_basic_archive_with_checksum (self ):
29- checksum_ = "banana"
30- out = self .archive .archive_file (self .file , checksum_ )
31- assert checksum_ == out , (checksum_ , out )
30+ with pytest .raises (ValueError ):
31+ self .archive .archive_file (self .file , content_hash = "banana" )
32+
33+ out = self .archive .archive_file (self .file , content_hash = "01234567890abcdef" )
34+ assert out == "01234567890abcdef"
3235
3336 def test_generate_url (self ):
3437 content_hash = self .archive .archive_file (self .file )
@@ -60,12 +63,29 @@ def test_publish_file(self):
6063 assert "https://foo.s3.amazonaws.com/self.py" in url , url
6164
6265 def test_load_file (self ):
66+ # Invalid content hash
67+ with pytest .raises (ValueError ):
68+ self .archive .load_file ("banana" )
69+
70+ # Valid content hash, but file does not exist
71+ path = self .archive .load_file ("01234567890abcdef" )
72+ assert path is None
73+
74+ # Valid content hash, file exists
6375 out = self .archive .archive_file (self .file )
6476 path = self .archive .load_file (out )
6577 assert path is not None , path
6678 assert path .is_file (), path
6779
6880 def test_cleanup_file (self ):
81+ # Invalid content hash
82+ with pytest .raises (ValueError ):
83+ self .archive .cleanup_file ("banana" )
84+
85+ # File does not exist
86+ assert self .archive .cleanup_file ("01234567890abcdef" ) is None
87+
88+ # Valid content hash, file exists
6989 out = self .archive .archive_file (self .file )
7090 self .archive .cleanup_file (out )
7191 path = self .archive .load_file (out )
@@ -86,6 +106,14 @@ def test_list_files(self):
86106 assert len (keys ) == 0 , keys
87107
88108 def test_delete_file (self ):
109+ # Invalid content hash
110+ with pytest .raises (ValueError ):
111+ self .archive .delete_file ("banana" )
112+
113+ # File does not exist
114+ assert self .archive .delete_file ("01234567890abcdef" ) is None
115+
116+ # Valid content hash, file exists
89117 out = self .archive .archive_file (self .file )
90118 path = self .archive .load_file (out )
91119 assert path is not None , path
0 commit comments