import boto3

from os import path
from lambda_uploader import uploader, config
from moto import mock_s3

EX_CONFIG = path.normpath(path.join(path.dirname(__file__),
                          '../test/configs'))


@mock_s3
def test_s3_upload():
    mock_bucket = 'mybucket'
    conn = boto3.resource('s3')
    conn.create_bucket(Bucket=mock_bucket)

    conf = config.Config(path.dirname(__file__),
                         config_file=path.join(EX_CONFIG, 'lambda.json'))
    conf.set_s3(mock_bucket)
    upldr = uploader.PackageUploader(conf, None)

    upldr._upload_s3(path.join(path.dirname(__file__), 'dummyfile'))

import boto3

from os import path
from lambda_uploader import uploader, config
from moto import mock_s3

EX_CONFIG = path.normpath(path.join(path.dirname(__file__),
                          '../test/configs'))


@mock_s3
def test_s3_upload():
    mock_bucket = 'mybucket'
    conn = boto3.resource('s3')
    conn.create_bucket(Bucket=mock_bucket)

    conf = config.Config(path.dirname(__file__),
                         config_file=path.join(EX_CONFIG, 'lambda.json'))
    conf.set_s3(mock_bucket)
    upldr = uploader.PackageUploader(conf, None)

    upldr._upload_s3(path.join(path.dirname(__file__), 'dummyfile'))

    # fetch the contents back out, be sure we truly uploaded the dummyfile
    retrieved_bucket = conn.Object(
        mock_bucket,
        conf.s3_package_name()
        ).get()['Body']
    found_contents = str(retrieved_bucket.read()).rstrip()
    assert found_contents == 'dummy data'

Add additional assertion that the file we uploaded is correct
Add additional assertion that the file we uploaded is correct

We should pull back down the S3 bucket file and be sure it's the same, proving we used the boto3 API correctly. We should probably, at some point, also upload a _real_ zip file and not just a plaintext file.

  import boto3
  
  from os import path
  from lambda_uploader import uploader, config
  from moto import mock_s3
  
  EX_CONFIG = path.normpath(path.join(path.dirname(__file__),
                            '../test/configs'))
  
  
  @mock_s3
  def test_s3_upload():
      mock_bucket = 'mybucket'
      conn = boto3.resource('s3')
      conn.create_bucket(Bucket=mock_bucket)
  
      conf = config.Config(path.dirname(__file__),
                           config_file=path.join(EX_CONFIG, 'lambda.json'))
      conf.set_s3(mock_bucket)
      upldr = uploader.PackageUploader(conf, None)
  
      upldr._upload_s3(path.join(path.dirname(__file__), 'dummyfile'))
  
+     # fetch the contents back out, be sure we truly uploaded the dummyfile
+     retrieved_bucket = conn.Object(
+         mock_bucket,
+         conf.s3_package_name()
+         ).get()['Body']
+     found_contents = str(retrieved_bucket.read()).rstrip()
+     assert found_contents == 'dummy data'
+ 
Add additional assertion that the file we uploaded is correct
## Code Before:
import boto3

from os import path
from lambda_uploader import uploader, config
from moto import mock_s3

EX_CONFIG = path.normpath(path.join(path.dirname(__file__),
                          '../test/configs'))


@mock_s3
def test_s3_upload():
    mock_bucket = 'mybucket'
    conn = boto3.resource('s3')
    conn.create_bucket(Bucket=mock_bucket)

    conf = config.Config(path.dirname(__file__),
                         config_file=path.join(EX_CONFIG, 'lambda.json'))
    conf.set_s3(mock_bucket)
    upldr = uploader.PackageUploader(conf, None)

    upldr._upload_s3(path.join(path.dirname(__file__), 'dummyfile'))

## Instruction:
Add additional assertion that the file we uploaded is correct
## Code After:
import boto3

from os import path
from lambda_uploader import uploader, config
from moto import mock_s3

EX_CONFIG = path.normpath(path.join(path.dirname(__file__),
                          '../test/configs'))


@mock_s3
def test_s3_upload():
    mock_bucket = 'mybucket'
    conn = boto3.resource('s3')
    conn.create_bucket(Bucket=mock_bucket)

    conf = config.Config(path.dirname(__file__),
                         config_file=path.join(EX_CONFIG, 'lambda.json'))
    conf.set_s3(mock_bucket)
    upldr = uploader.PackageUploader(conf, None)

    upldr._upload_s3(path.join(path.dirname(__file__), 'dummyfile'))

    # fetch the contents back out, be sure we truly uploaded the dummyfile
    retrieved_bucket = conn.Object(
        mock_bucket,
        conf.s3_package_name()
        ).get()['Body']
    found_contents = str(retrieved_bucket.read()).rstrip()
    assert found_contents == 'dummy data'
