Skip to content

Instantly share code, notes, and snippets.

@sjparkinson
Last active March 13, 2017 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjparkinson/c7330ae33ea51221f611f5ab16155b76 to your computer and use it in GitHub Desktop.
Save sjparkinson/c7330ae33ea51221f611f5ab16155b76 to your computer and use it in GitHub Desktop.
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