Last active
March 13, 2017 15:44
-
-
Save sjparkinson/c7330ae33ea51221f611f5ab16155b76 to your computer and use it in GitHub Desktop.
Scripters code club testing example.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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