示例#1
0
def test_write_config(cleandir):
    config = ConfigDict()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    l = Loader()
    l._write_config_py(config)
    assert 'client_config.py' in os.listdir(os.getcwd())
 def test_process_packages(self):
     data_dir = os.getcwd()
     t_config = TConfig()
     t_config.DATA_DIR = data_dir
     t_config.UPDATE_PATCHES = False
     config = ConfigDict()
     config.from_object(t_config)
     p = PackageHandler(config)
     p.process_packages()
 def test_init(self):
     data_dir = os.getcwd()
     t_config = TConfig()
     t_config.DATA_DIR = data_dir
     config = ConfigDict()
     config.from_object(t_config)
     p = PackageHandler(config)
     assert p.files_dir == os.path.join(data_dir, s_dir, 'files')
     assert p.deploy_dir == os.path.join(data_dir, s_dir, 'deploy')
示例#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
        config = ConfigDict()
        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()
示例#5
0
class Core(object):
    """Processes, signs & uploads updates

        Kwargs:

            config (obj): config object
    """
    def __init__(self, config=None):
        self.config = ConfigDict()
        self.db = Storage()
        # Important to keep this before updating config
        if config is not None:
            self.update_config(config)

    def update_config(self, config):
        """Updates internal config

        Args:

            config (obj): config object
        """
        if not hasattr(config, 'DATA_DIR'):
            config.DATA_DIR = None
        if config.DATA_DIR is None:
            config.DATA_DIR = os.getcwd()
        self.config.from_object(config)
        self._update(self.config)

    def _update(self, config):
        self.kh = KeyHandler(config)
        self.key_importer = KeyImporter()
        self.ph = PackageHandler(config)
        self.up = Uploader(config)

    def setup(self):
        "Sets up root dir with required PyUpdater folders"
        self.ph.setup()

    def process_packages(self):
        """Creates hash for updates & adds information about update to
        version file
        """
        self.ph.process_packages()

    def set_uploader(self, requested_uploader):
        """Sets upload destination

        Args:

            requested_uploader (str): upload service. i.e. s3, scp
        """
        self.up.set_uploader(requested_uploader)

    def upload(self):
        "Uploads files in deploy folder"
        self.up.upload()

    def import_keypack(self):
        "Creates signing keys"
        self.key_importer.start()

    def sign_update(self):
        "Signs version file with signing key"
        self.kh.sign_update()
示例#6
0
 def test_dev_dir_none(self):
     myconfig = TConfig()
     myconfig.APP_NAME = None
     updater = ConfigDict()
     updater.from_object(myconfig)
     assert updater['APP_NAME'] == 'PyUpdater App'
示例#7
0
def test_prod_bad_atter():
    config = ConfigDict()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    assert config.get('DEBUG', None) is not None
示例#8
0
def test_prod_config():
    config = ConfigDict()
    prod_config = ProdConfig()
    config.from_object(prod_config)
    assert config['MORE_INFO'] == 'Yes Please'
示例#9
0
def test_dev_config_bad_attr():
    config = ConfigDict()
    test_config = DevConfig()
    config.from_object(test_config)
    assert config.get('BAD_ATTR', None) is None
示例#10
0
def test_dev_config():
    config = ConfigDict()
    test_config = DevConfig()
    config.from_object(test_config)
    assert config['TESTING'] is True