Exemple #1
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
        config = Config()
        config.from_object(obj)

        self.FROZEN = jms_utils.app.FROZEN
        # Grabbing config information
        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_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.root_key = config.get('PUBLIC_KEY', '')
        self.app_key = None

        # Config option to disable tls cert verification
        self.verify = config.get('VERIFY_SERVER_CERT', True)
        self.version_file = settings.VERSION_FILE
        self.key_file = settings.KEY_FILE

        self._setup()
        if refresh is True:
            self.refresh()
Exemple #2
0
def test_prod_bad_atter():
    config = Config()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    assert config.get('DEBUG', None) is not None
Exemple #3
0
def test_dev_config_bad_attr():
    config = Config()
    test_config = DevConfig()
    config.from_object(test_config)
    assert config.get('BAD_ATTR', None) is None
Exemple #4
0
def test_prod_bad_atter():
    config = Config()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    assert config.get('DEBUG', None) is not None
Exemple #5
0
def test_dev_config_bad_attr():
    config = Config()
    test_config = DevConfig()
    config.from_object(test_config)
    assert config.get('BAD_ATTR', None) is None
Exemple #6
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

        """

        # A super dict used to save config info & be dot accessed
        config = Config()
        config.from_object(obj)

        # Boolean: If executing frozen
        self.FROZEN = dsdev_utils.app.FROZEN

        # Grabbing config information
        update_urls = config.get('UPDATE_URLS', [])

        # List of URL to check for update data
        self.update_urls = self._sanatize_update_url(update_urls)

        # Name of the running application
        self.app_name = config.get('APP_NAME', 'PyUpdater')

        # Name of the app author
        self.company_name = config.get('COMPANY_NAME', 'Digital Sapphire')

        # Used in testing to force use of the mac archive
        if test:
            # Making platform deterministic for tests.
            self.data_dir = obj.DATA_DIR
            self.platform = 'mac'
        else:  # pragma: no cover
            # Getting platform specific user data directory
            self.data_dir = appdirs.user_data_dir(self.app_name,
                                                  self.company_name)

            # Used when parsing the update manifest
            self.platform = dsdev_utils.system.get_system()

        # Folder to house update archives
        self.update_folder = os.path.join(self.data_dir,
                                          settings.UPDATE_FOLDER)

        # The root public key to verify the app signing private key
        self.root_key = config.get('PUBLIC_KEY', '')

        # We'll get the app_key later in _get_signing_key
        # That's if we verify the keys manifest
        self.app_key = None

        # Used to disable TLS cert verification
        self.verify = config.get('VERIFY_SERVER_CERT', True)

        # The name of the version file to download
        self.version_file = settings.VERSION_FILE_FILENAME

        # The name of the key file to download
        self.key_file = settings.KEY_FILE_FILENAME

        # Creating data & update directories
        self._setup()

        if refresh is True:
            self.refresh()