Exemple #1
0
    def test_get_boto_with_args(self, mock_boto):
        """
        get_boto correctly passes the arguments to Boto contructor
        """
        get_boto(self.args, self.logger, self.stats)

        mock_boto.assert_called_once_with(
            log_level=self.args.boto_log_level,
            access_key=self.args.boto_access_key,
            secret_key=self.args.boto_secret_key,
            region=self.args.boto_region,
            logger=self.logger,
            stats=self.stats,
        )
Exemple #2
0
    def test_get_boto_with_args(self, mock_boto):
        """
        get_boto() correctly passes the arguments to Boto contructor
        """
        get_boto(self.args, self.logger, self.stats)

        mock_boto.assert_called_once_with(
            log_level=self.args.boto_log_level,
            access_key=self.args.boto_access_key,
            secret_key=self.args.boto_secret_key,
            region=self.args.boto_region,
            logger=self.logger,
            stats=self.stats,
        )
Exemple #3
0
    def __init__(self, name=NAME):
        # Call to the superclass to bootstrap.
        super(Application, self).__init__(name=name)

        self.boto = get_boto(self.args, self.logger, self.stats)

        self.boto3 = get_boto3(self.args, self.logger, self.stats)
Exemple #4
0
    def __init__(self, name=NAME):
        # Call to the superclass to bootstrap.
        super(Application, self).__init__(name=name)

        self.boto = get_boto(self.args, self.logger, self.stats)

        self.boto3 = get_boto3(self.args, self.logger, self.stats)
Exemple #5
0
def get_s3(args=None, logger=None, stats=None):
    """
    Return a usable S3 object without creating a class around it.

    In the context of a krux.cli (or similar) interface the 'args', 'logger'
    and 'stats' objects should already be present. If you don't have them,
    however, we'll attempt to provide usable ones for the SQS setup.

    (If you omit the add_s3_cli_arguments() call during other cli setup,
    the Boto object will still work, but its cli options won't show up in
    --help output)

    (This also handles instantiating a Boto object on its own.)
    """
    if not args:
        parser = get_parser()
        add_s3_cli_arguments(parser)
        # Parse only the known arguments added by add_boto_cli_arguments().
        # We only need those arguments to create Boto object, nothing else.
        # parse_known_args() return (Namespace, list of unknown arguments),
        # we only care about the Namespace object here.
        args = parser.parse_known_args()[0]

    if not logger:
        logger = get_logger(name=NAME)

    if not stats:
        stats = get_stats(prefix=NAME)

    return S3(
        boto=get_boto(args, logger, stats),
        logger=logger,
        stats=stats,
    )
Exemple #6
0
    def test_get_boto_without_args(self, mock_get_stats, mock_get_logger, mock_boto):
        """
        get_boto correctly parses the CLI arguments and pass them to Boto contructor
        """
        mock_get_stats.return_value = self.stats
        mock_get_logger.return_value = self.logger

        get_boto()

        mock_boto.assert_called_once_with(
            log_level=self.args.boto_log_level,
            access_key=self.args.boto_access_key,
            secret_key=self.args.boto_secret_key,
            region=self.args.boto_region,
            logger=self.logger,
            stats=self.stats,
        )
    def test_get_boto_without_args(self, mock_get_stats, mock_get_logger, mock_boto):
        """
        get_boto() correctly parses the CLI arguments and pass them to Boto contructor
        """
        mock_get_stats.return_value = self.stats
        mock_get_logger.return_value = self.logger

        get_boto()

        mock_boto.assert_called_once_with(
            log_level=self.args.boto_log_level,
            access_key=self.args.boto_access_key,
            secret_key=self.args.boto_secret_key,
            region=self.args.boto_region,
            logger=self.logger,
            stats=self.stats,
        )
Exemple #8
0
    def __init__(self, name=NAME, *args, **kwargs):
        self._VERSIONS[NAME] = self._VERSION

        # Call to the superclass to bootstrap.
        super(Application, self).__init__(name=name)

        self.boto = get_boto(self.args, self.logger, self.stats)

        self.boto3 = get_boto3(self.args, self.logger, self.stats)
Exemple #9
0
    def test_get_boto_no_args(self, mock_boto):
        """
        get_boto() correctly handles when CLI arguments are not present
        """
        args = MagicMock(spec=[''])
        environ = {
            REGION: self.FAKE_REGION,
            ACCESS_KEY: self.FAKE_ACCESS_KEY,
            SECRET_KEY: self.FAKE_SECRET_KEY,
        }

        with patch.dict('krux_boto.boto.os.environ', environ):
            get_boto(args=args, logger=self.logger, stats=self.stats)

        mock_boto.assert_called_once_with(
            log_level=DEFAULT['log_level'](),
            access_key=self.FAKE_ACCESS_KEY,
            secret_key=self.FAKE_SECRET_KEY,
            region=self.FAKE_REGION,
            logger=self.logger,
            stats=self.stats,
        )
Exemple #10
0
    def test_get_boto_no_args(self, mock_boto):
        """
        get_boto() correctly handles when CLI arguments are not present
        """
        args = MagicMock(spec=[''])
        environ = {
            REGION: self.FAKE_REGION,
            ACCESS_KEY: self.FAKE_ACCESS_KEY,
            SECRET_KEY: self.FAKE_SECRET_KEY,
        }

        with patch.dict('krux_boto.boto.os.environ', environ):
            get_boto(args=args, logger=self.logger, stats=self.stats)

        mock_boto.assert_called_once_with(
            log_level=DEFAULT['log_level'](),
            access_key=self.FAKE_ACCESS_KEY,
            secret_key=self.FAKE_SECRET_KEY,
            region=self.FAKE_REGION,
            logger=self.logger,
            stats=self.stats,
        )
Exemple #11
0
    def __init__(self, name=NAME, *args, **kwargs):
        # Usually, a VERSION constant should be set in __init__.py and be imported.
        # However, krux-boto adds some basic classes to __init__.py and importing VERSION constant here
        # causes a dependency circle. Thus, set VERSION constant in version.json and import it.
        # path.dirname() gives current file's parent dir, calling twice would give us the correct path to version.json
        # under the root folder.
        _VERSION_PATH = path.join(path.dirname(path.dirname(__file__)), 'version.json')
        with open(_VERSION_PATH, 'r') as f:
            self._VERSION = json.load(f).get('VERSION')

        self._VERSIONS[NAME] = self._VERSION

        # Call to the superclass to bootstrap.
        super(Application, self).__init__(name=name)

        self.boto = get_boto(self.args, self.logger, self.stats)

        self.boto3 = get_boto3(self.args, self.logger, self.stats)