1616from tornado .testing import gen_test
1717
1818from tests import BaseS3TestCase
19- from thumbor_aws .loader import load
19+ import thumbor_aws .loader
2020from thumbor_aws .storage import Storage
2121
2222
@@ -41,23 +41,31 @@ async def test_can_load_file_from_s3(self):
4141 exists = await storage .exists (filepath )
4242 expect (exists ).to_be_true ()
4343
44- result = await load (self .context , filepath )
44+ result = await thumbor_aws . loader . load (self .context , filepath )
4545
4646 expect (result .successful ).to_be_true ()
4747 expect (result .buffer ).to_equal (expected )
4848 expect (result .metadata ["size" ]).to_equal (len (expected ))
4949 expect (result .metadata ["updated_at" ]).not_to_be_null ()
5050
51+ @gen_test
52+ async def test_result_false_when_file_not_in_s3 (self ):
53+ """
54+ Verifies that result is false when image not present in S3
55+ """
56+ await self .ensure_bucket ()
57+ filepath = f"/test/can_put_file_{ uuid4 ()} "
58+
59+ result = await thumbor_aws .loader .load (self .context , filepath )
60+
61+ expect (result .successful ).to_be_false ()
62+
5163
5264@pytest .mark .usefixtures ("test_images" )
5365class LoaderCompatibilityModeTestCase (LoaderTestCase ):
5466 def get_config (self ) -> Config :
5567 return self .get_compatibility_config ()
5668
57- @property
58- def _prefix (self ):
59- return "/test-compat-st"
60-
6169 @property
6270 def bucket_name (self ):
6371 """Name of the bucket to put test files in"""
@@ -66,10 +74,10 @@ def bucket_name(self):
6674
6775@pytest .mark .usefixtures ("test_images" )
6876class EmptyBucketConfigLoaderTestCase (BaseS3TestCase ):
69- @ property
70- def bucket_name ( self ):
71- """Name of the bucket to put test files in" ""
72- return self . context . config . AWS_LOADER_BUCKET_NAME
77+ def get_config ( self ) -> Config :
78+ cfg = super (). get_config ()
79+ cfg . AWS_LOADER_BUCKET_NAME = ""
80+ return cfg
7381
7482 @gen_test
7583 async def test_can_load_file_from_s3 (self ):
@@ -86,14 +94,25 @@ async def test_can_load_file_from_s3(self):
8694 expect (exists ).to_be_true ()
8795
8896 filepath_with_bucket = (
89- f"/{ self .context .config .AWS_LOADER_BUCKET_NAME } { filepath } "
97+ f"/{ self .context .config .AWS_STORAGE_BUCKET_NAME } { filepath } "
9098 )
9199
92- self . context . config . AWS_LOADER_BUCKET_NAME = ""
93-
94- result = await load ( self . context , filepath_with_bucket )
100+ result = await thumbor_aws . loader . load (
101+ self . context , filepath_with_bucket
102+ )
95103
96104 expect (result .successful ).to_be_true ()
97105 expect (result .buffer ).to_equal (expected )
98106 expect (result .metadata ["size" ]).to_equal (len (expected ))
99107 expect (result .metadata ["updated_at" ]).not_to_be_null ()
108+
109+
110+ @pytest .mark .usefixtures ("test_images" )
111+ class LoaderNoPrefixTestCase (LoaderTestCase ):
112+ def get_config (self ) -> Config :
113+ cfg = super ().get_config ()
114+ cfg .AWS_LOADER_BUCKET_NAME = "test-bucket-loader-no-prefix"
115+ cfg .AWS_STORAGE_BUCKET_NAME = "test-bucket-loader-no-prefix"
116+ cfg .AWS_LOADER_ROOT_PATH = ""
117+ cfg .AWS_STORAGE_ROOT_PATH = ""
118+ return cfg
0 commit comments