Beispiel #1
0
    def test_with_no_given_bucket(self):
        self.app.conf.s3_access_key_id = 'somekeyid'
        self.app.conf.s3_secret_access_key = 'somesecret'
        self.app.conf.s3_bucket = None

        with pytest.raises(ImproperlyConfigured, match='Missing bucket name'):
            S3Backend(app=self.app)
Beispiel #2
0
    def test_with_no_credentials_in_config_attempts_to_load_credentials(self, mock_load_credentials):
        self.app.conf.s3_access_key_id = None
        self.app.conf.s3_secret_access_key = None
        self.app.conf.s3_bucket = 'bucket'

        S3Backend(app=self.app)
        mock_load_credentials.assert_called_once()
Beispiel #3
0
    def test_with_credentials_in_config_does_not_search_for_credentials(self, mock_load_credentials):
        self.app.conf.s3_access_key_id = 'somekeyid'
        self.app.conf.s3_secret_access_key = 'somesecret'
        self.app.conf.s3_bucket = 'bucket'

        S3Backend(app=self.app)
        mock_load_credentials.assert_not_called()
Beispiel #4
0
    def test_with_missing_aws_credentials(self, mock_load_credentials):
        self.app.conf.s3_access_key_id = None
        self.app.conf.s3_secret_access_key = None
        self.app.conf.s3_bucket = 'bucket'

        mock_load_credentials.return_value = None

        with pytest.raises(ImproperlyConfigured, match="Missing aws s3 creds"):
            S3Backend(app=self.app)
Beispiel #5
0
    def test_it_creates_an_aws_s3_resource(self, mock_boto3, endpoint_url):
        self.app.conf.s3_access_key_id = 'somekeyid'
        self.app.conf.s3_secret_access_key = 'somesecret'
        self.app.conf.s3_bucket = 'bucket'
        self.app.conf.s3_endpoint_url = endpoint_url

        S3Backend(app=self.app)
        mock_boto3.Session().resource.assert_called_once_with(
            's3', endpoint_url=endpoint_url)
Beispiel #6
0
    def test_set_and_get_a_key(self, key):
        self._mock_s3_resource()

        self.app.conf.s3_access_key_id = 'somekeyid'
        self.app.conf.s3_secret_access_key = 'somesecret'
        self.app.conf.s3_bucket = 'bucket'

        s3_backend = S3Backend(app=self.app)
        s3_backend.set(key, 'another_status')

        assert s3_backend.get(key) == 'another_status'
Beispiel #7
0
    def test_it_creates_an_aws_s3_connection(self, mock_boto3, aws_region):
        self.app.conf.s3_access_key_id = 'somekeyid'
        self.app.conf.s3_secret_access_key = 'somesecret'
        self.app.conf.s3_bucket = 'bucket'
        self.app.conf.s3_region = aws_region

        S3Backend(app=self.app)
        mock_boto3.Session.assert_called_once_with(
            aws_access_key_id='somekeyid',
            aws_secret_access_key='somesecret',
            region_name=aws_region)
Beispiel #8
0
    def test_get_a_missing_key(self):
        self._mock_s3_resource()

        self.app.conf.s3_access_key_id = 'somekeyid'
        self.app.conf.s3_secret_access_key = 'somesecret'
        self.app.conf.s3_bucket = 'bucket'

        s3_backend = S3Backend(app=self.app)
        result = s3_backend.get('uuidddd')

        assert result is None
Beispiel #9
0
    def test_with_a_non_existing_bucket(self):
        self._mock_s3_resource()

        self.app.conf.s3_access_key_id = 'somekeyid'
        self.app.conf.s3_secret_access_key = 'somesecret'
        self.app.conf.s3_bucket = 'bucket_not_exists'

        s3_backend = S3Backend(app=self.app)

        with pytest.raises(ClientError,
                           match=r'.*The specified bucket does not exist'):
            s3_backend.set('uuid', 'another_status')
Beispiel #10
0
    def test_set_and_get_a_result(self):
        self._mock_s3_resource()

        self.app.conf.result_serializer = 'pickle'
        self.app.conf.s3_access_key_id = 'somekeyid'
        self.app.conf.s3_secret_access_key = 'somesecret'
        self.app.conf.s3_bucket = 'bucket'

        s3_backend = S3Backend(app=self.app)
        s3_backend.store_result('foo', 'baar', 'STARTED')
        value = s3_backend.get_result('foo')
        assert value == 'baar'
Beispiel #11
0
    def test_delete_a_key(self):
        self._mock_s3_resource()

        self.app.conf.s3_access_key_id = 'somekeyid'
        self.app.conf.s3_secret_access_key = 'somesecret'
        self.app.conf.s3_bucket = 'bucket'

        s3_backend = S3Backend(app=self.app)
        s3_backend.set('uuid', 'another_status')
        assert s3_backend.get('uuid') == 'another_status'

        s3_backend.delete('uuid')

        assert s3_backend.get('uuid') is None
Beispiel #12
0
    def test_with_error_while_getting_key(self, mock_boto3):
        error = ClientError({'Error': {'Code': '403',
                                       'Message': 'Permission denied'}},
                            'error')
        mock_boto3.Session().resource().Object().load.side_effect = error

        self.app.conf.s3_access_key_id = 'somekeyid'
        self.app.conf.s3_secret_access_key = 'somesecret'
        self.app.conf.s3_bucket = 'bucket'

        s3_backend = S3Backend(app=self.app)

        with pytest.raises(ClientError):
            s3_backend.get('uuidddd')
Beispiel #13
0
    def test_delete_a_key(self, key):
        self._mock_s3_resource()

        self.app.conf.s3_access_key_id = 'somekeyid'
        self.app.conf.s3_secret_access_key = 'somesecret'
        self.app.conf.s3_bucket = 'bucket'

        s3_backend = S3Backend(app=self.app)
        s3_backend._set_with_state(key, 'another_status', states.SUCCESS)
        assert s3_backend.get(key) == 'another_status'

        s3_backend.delete(key)

        assert s3_backend.get(key) is None
Beispiel #14
0
    def test_with_missing_aws_credentials(self):
        self.app.conf.s3_access_key_id = None
        self.app.conf.s3_secret_access_key = None

        with pytest.raises(ImproperlyConfigured, match="Missing aws s3 creds"):
            S3Backend(app=self.app)