Skip to content

Commit 68bd9a8

Browse files
authored
Add S3 Put Object With Checksum Keyword with test and update boto3 minimum version
Merge pull request #65 from JJediny/update-boto3 - Added the S3 Put Object with Checksum keyword and associated test. - Updated the minimum boto3 version in requirements.txt
2 parents 8a57f6a + 9ef44bb commit 68bd9a8

5 files changed

Lines changed: 41 additions & 2 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@ log/
6161

6262
# localstack
6363
localstack/.localstack/
64+
65+
# VS Code
66+
.vscode/
67+
68+
# Results
69+
results/

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
robotframework>=6.1.1
2-
boto3>=1.34.125
2+
boto3>=1.40.30
33
robotframework-pythonlibcore>=4.4.1

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ def readme():
2525
],
2626
packages=find_packages('src'),
2727
package_dir={'': 'src'},
28-
install_requires=['boto3 >= 1.34.125', 'robotframework >= 6.1.1', 'robotframework-pythonlibcore>=4.4.1']
28+
install_requires=['boto3 >= 1.40.30', 'robotframework >= 6.1.1', 'robotframework-pythonlibcore>=4.4.1']
2929
)

src/AWSLibrary/keywords/s3.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,32 @@ def s3_upload_file(self, bucket, key, local_path):
333333
except botocore.exceptions.ClientError as e:
334334
raise Exception(e)
335335

336+
@keyword('S3 Put Object With Checksum')
337+
def s3_put_object_with_checksum(self, bucket, key, body, checksum_algorithm='SHA256'):
338+
""" Put an object to the bucket with checksum validation for integrity.
339+
340+
| =Arguments= | =Description= |
341+
| ``bucket`` | <str> The bucket name. |
342+
| ``key`` | <str> Complete s3 filepath. |
343+
| ``body`` | <str> The object data. |
344+
| ``checksum_algorithm`` | <str> The checksum algorithm (SHA256, SHA1, CRC32, CRC32C). Default: SHA256. |
345+
346+
*Examples:*
347+
| S3 Put Object With Checksum | bucket_name | s3_file.txt | ${data} |
348+
| S3 Put Object With Checksum | bucket_name | s3_file.txt | ${data} | CRC32 |
349+
"""
350+
client = self.library.session.client('s3', endpoint_url=self.endpoint_url)
351+
try:
352+
response = client.put_object(
353+
Bucket=bucket,
354+
Key=key,
355+
Body=body,
356+
ChecksumAlgorithm=checksum_algorithm
357+
)
358+
logger.info(response)
359+
except botocore.exceptions.ClientError as e:
360+
raise Exception(e)
361+
336362
@keyword('S3 Key Should Exist')
337363
def s3_key_should_exist(self, bucket, key):
338364
""" Check if the s3 object exist inside the bucket

tests/robot/s3.robot

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,10 @@ Test Metadata
7676
Dictionary Should Contain Key ${metadata}[ResponseMetadata] RequestId
7777
Dictionary Should Contain Key ${metadata}[ResponseMetadata][HTTPHeaders] last-modified
7878
[Teardown] S3 Delete File ${BUCKET_NAME} s3_file_metadata.txt
79+
80+
Test Put Object With Checksum
81+
[Tags] s3
82+
${data}= Get File ${CURDIR}/data/local_file.txt
83+
S3 Put Object With Checksum ${BUCKET_NAME} s3_file_checksum.txt ${data} SHA256
84+
S3 Key Should Exist ${BUCKET_NAME} s3_file_checksum.txt
85+
[Teardown] S3 Delete File ${BUCKET_NAME} s3_file_checksum.txt

0 commit comments

Comments
 (0)