示例#1
0
 def test_convert_to_list_default(self):
     assert isinstance(convert_to_list({}, default=[]), list)
示例#2
0
 def test_convert_to_list(self):
     assert isinstance(convert_to_list('test'), list)
     assert isinstance(convert_to_list(('test', 'test2')), list)
     assert isinstance(convert_to_list(['test']), list)
示例#3
0
    def init_app(self, obj, refresh=False, test=False):
        """Sets up client with config values from obj

        Args:

            obj (instance): config object

        Kwargs:

            refresh (bool) Meaning:

            True: Refresh update manifest on object initialization

            False: Don't refresh update manifest on object initialization

        """
        # Used to add missing required information
        # i.e. APP_NAME
        pyi_config = TransistionDict()
        pyi_config.from_object(obj)
        config = pyi_config.copy()

        self.FROZEN = jms_utils.app.FROZEN
        # Grabbing config information
        update_url = config.get('UPDATE_URL')
        update_urls = config.get('UPDATE_URLS')

        # Here we combine all urls & add trailing / if one isn't present
        self.update_urls = self._sanatize_update_url(update_url, update_urls)
        self.app_name = config.get('APP_NAME', 'PyUpdater')
        self.company_name = config.get('COMPANY_NAME', 'Digital Sapphire')
        if test:
            # Making platform deterministic for tests.
            # No need to test for other platforms at the moment
            self.data_dir = obj.DATA_DIR
            self.platform = 'mac'
        else:  # pragma: no cover
            # Getting platform specific application directory
            self.data_dir = appdirs.user_data_dir(self.app_name,
                                                  self.company_name,
                                                  roaming=True)
            # Setting the platform to pass when requesting updates
            self.platform = jms_utils.system.get_system()
        # Creating update folder. Using settings to ease change in future
        self.update_folder = os.path.join(self.data_dir,
                                          settings.UPDATE_FOLDER)
        # Attempting to sanitize incorrect inputs types
        self.public_keys = convert_to_list(config.get('PUBLIC_KEYS'),
                                           default=list())
        if len(self.public_keys) == 0:
            log.warning('May have passed an incorrect data type to '
                        'PUBLIC_KEYS or an empty list was passed')

        # Ensuring only one occurrence of a public key is present
        # Would be a waste to test a bad key twice
        self.public_keys = list(set(self.public_keys))
        # Config option to disable tls cert verification
        self.verify = config.get('VERIFY_SERVER_CERT', True)
        self.version_file = settings.VERSION_FILE

        self._setup()
        if refresh is True:
            self.refresh()
示例#4
0
    def init_app(self, obj, refresh=False, test=False):
        """Sets up client with config values from obj

        Args:

            obj (instance): config object

        Kwargs:

            refresh (bool) Meaning:

            True: Refresh update manifest on object initialization

            False: Don't refresh update manifest on object initialization

        """
        # Used to add missing required information
        # i.e. APP_NAME
        pyi_config = TransistionDict()
        pyi_config.from_object(obj)
        config = pyi_config.copy()

        self.FROZEN = jms_utils.app.FROZEN
        # Grabbing config information
        update_url = config.get('UPDATE_URL')
        update_urls = config.get('UPDATE_URLS')

        # Here we combine all urls & add trailing / if one isn't present
        self.update_urls = self._sanatize_update_url(update_url, update_urls)
        self.app_name = config.get('APP_NAME', 'PyUpdater')
        self.company_name = config.get('COMPANY_NAME', 'Digital Sapphire')
        if test:
            # Making platform deterministic for tests.
            # No need to test for other platforms at the moment
            self.data_dir = obj.DATA_DIR
            self.platform = 'mac'
        else:  # pragma: no cover
            # Getting platform specific application directory
            self.data_dir = appdirs.user_data_dir(self.app_name,
                                                  self.company_name,
                                                  roaming=True)
            # Setting the platform to pass when requesting updates
            self.platform = jms_utils.system.get_system()
        # Creating update folder. Using settings to ease change in future
        self.update_folder = os.path.join(self.data_dir,
                                          settings.UPDATE_FOLDER)
        # Attempting to sanitize incorrect inputs types
        self.public_keys = convert_to_list(config.get('PUBLIC_KEYS'),
                                           default=list())
        if len(self.public_keys) == 0:
            log.warning('May have passed an incorrect data type to '
                        'PUBLIC_KEYS or an empty list was passed')

        # Ensuring only one occurrence of a public key is present
        # Would be a waste to test a bad key twice
        self.public_keys = list(set(self.public_keys))
        # Config option to disable tls cert verification
        self.verify = config.get('VERIFY_SERVER_CERT', True)
        self.version_file = settings.VERSION_FILE

        self._setup()
        if refresh is True:
            self.refresh()
示例#5
0
 def test_convert_to_list_default(self):
     assert isinstance(convert_to_list({}, default=[]), list)
示例#6
0
 def test_convert_to_list(self):
     assert isinstance(convert_to_list('test'), list)
     assert isinstance(convert_to_list(('test', 'test2')), list)
     assert isinstance(convert_to_list(['test']), list)