Skip to content

Instantly share code, notes, and snippets.

@sjparkinson sjparkinson/example.py
Last active Mar 13, 2017

Embed
What would you like to do?
Scripters code club testing example.
#!/usr/bin/env python
import boto3
# Standard boilerplate to call the main() function to begin
# the program.
if __name__ == '__main__':
key = 'jif.gif'
body = open(filename, 'rb')
s3.Bucket('hello-world').put_object(Key=key, Body=body)
#!/usr/bin/env python
import pytest
from upload import upload
def test_upload():
# Fill in the blanks.
#
# 1. Assert we're uploading the given file
# 2. Assert the filename doesn't include the path
# 3. Assert we call put_object on the s3 client
#!/usr/bin/env python
import boto3
import os
def upload(body, path, bucket, s3):
key = os.path.basename(path)
s3.Bucket(bucket).put_object(Key=key, Body=body)
def main():
body = open(sys.argv[1], 'rb')
path = sys.argv[1]
bucket = 'hello-example-bucket'
s3 = boto3.resource('s3')
upload(body, path, bucket, s3)
# Standard boilerplate to call the main() function to begin
# the program.
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.