Exemple #1
0
class AmazonMediaStoragePutAndDeleteTest(TestCase):
    def setUp(self):
        self.amazon = AmazonMediaStorage(self.app)

    def test_put_and_delete(self):
        """
        If the environment variables have a Amazon secret key set then assume that we can attempt to put and delete
        into s3
        :return:
        """
        if self.app.config['AMAZON_SECRET_ACCESS_KEY']:
            id = self.amazon.put('test', content_type='text/plain')
            self.assertIsNot(id, None)
            self.assertTrue(self.amazon.exists(id))
            fromS3 = self.amazon.get(id)
            self.assertEqual(fromS3.read().decode('utf-8'), 'test')
            self.amazon.delete(id)
            self.assertFalse(self.amazon.exists(id))
        else:
            self.assertTrue(True)
Exemple #2
0
class AmazonMediaStoragePutAndDeleteTest(TestCase):
    def setUp(self):
        self.amazon = AmazonMediaStorage(self.app)

    def test_put_and_delete(self):
        """Test amazon if configured.

        If the environment variables have a Amazon secret key set then assume
        that we can attempt to put and delete into s3

        :return:
        """
        if self.app.config['AMAZON_SECRET_ACCESS_KEY']:
            id = self.amazon.put('test', content_type='text/plain')
            self.assertIsNot(id, None)
            self.assertTrue(self.amazon.exists(id))
            fromS3 = self.amazon.get(id)
            self.assertEqual(fromS3.read().decode('utf-8'), 'test')
            self.amazon.delete(id)
            self.assertFalse(self.amazon.exists(id))
        else:
            self.assertTrue(True)

    def test_put_into_folder(self):
        data = b'test data'
        folder = 's3test'
        filename = 'abc123.zip'
        content_type = 'text/plain'
        self.amazon.client.put_object = Mock()
        self.amazon.media_id = Mock(return_value=filename)
        self.amazon._check_exists = Mock(return_value=False)

        self.amazon.put(data, filename, content_type, folder=folder)

        kwargs = {
            'Key': '{}/{}'.format(folder, filename),
            'Body': data,
            'Bucket': self.amazon.container_name,
            'ContentType': content_type
        }
        self.amazon.client.put_object.assert_called_once_with(**kwargs)