Skip to content
This repository has been archived by the owner on Apr 21, 2021. It is now read-only.

Commit

Permalink
Clear group image test
Browse files Browse the repository at this point in the history
  • Loading branch information
brew committed Jul 3, 2015
1 parent 1a49176 commit 10af959
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions ckanext/s3filestore/tests/test_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,41 @@ def test_group_image_upload(self):
# test the key exists
assert_true(bucket.lookup(key))

@mock_s3
def test_group_image_upload_then_clear(self):
'''Test that clearing an upload removes the S3 key'''

sysadmin = factories.Sysadmin(apikey="my-test-key")

file_path = os.path.join(os.path.dirname(__file__), 'data.csv')

img_uploader = Uploader("somename.png", file=open(file_path))

with mock.patch('ckanext.s3filestore.uploader.datetime') as mock_date:
mock_date.datetime.utcnow.return_value = \
datetime.datetime(2001, 1, 29)
context = {'user': sysadmin['name']}
helpers.call_action('group_create', context=context,
name="my-group",
image_upload=img_uploader,
image_url="somename.png")

key = '{0}/storage/uploads/group/2001-01-29-000000somename.png' \
.format(config.get('ckanext.s3filestore.aws_storage_path'))

conn = boto.connect_s3()
bucket = conn.get_bucket('my-bucket')
# test the key exists
assert_true(bucket.lookup(key))

# clear upload
helpers.call_action('group_update', context=context,
id='my-group', name='my-group',
image_url="http://asdf", clear_upload=True)

# key shouldn't exist
assert_false(bucket.lookup(key))


class TestS3ResourceUploader(helpers.FunctionalTestBase):

Expand Down

0 comments on commit 10af959

Please sign in to comment.