Beispiel #1
0
    def unsetenv(self, key):
        if environ.get(key) is not None:
            environ.pop(key)

        if WINDOWS:
            keyrm = "%s=" % key
            self.msvcrt._putenv(keyrm.encode("utf-8"))
Beispiel #2
0
    def __init__(self,
                 host,
                 port,
                 user,
                 passwd,
                 wsdlDir: Path = Path(__file__).parent.parent / 'wsdl',
                 encrypt=True,
                 adjust_time=False,
                 transport=None):
        environ.pop('http_proxy', None)
        environ.pop('https_proxy', None)
        self.host = host
        self.port = int(port)
        self.user = user
        self.passwd = passwd
        self.wsdlDir = wsdlDir
        self.encrypt = encrypt
        self.adjustTime = adjust_time
        self.transport = transport
        self.xaddrs = {}
        self.wsse = None

        # Active service client container
        self.services = {}
        self.servicesLock = RLock()
    def test_adds_authorization_header_to_response_with_cookie(self):
        environ['MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_auth_settings'

        class TestResource(ListResourceMixin):

            def list(self, request):
                request.environ['session']['test'] = 'test'
                return Response()

        self.test_client = self.client(
            WSGIDispatcher(resources=[TestResource]), Response
        )

        session_store = locate(settings.SESSION_STORE)()
        session = session_store.new()
        session_store.save(session)

        response = self.test_client.get(
            '/', headers=[('Cookie', 'session_id={0}'.format(session.sid))]
        )

        self.assertIn('HTTP_AUTHORIZATION', response.headers)
        self.assertEqual(
            response.headers.get('HTTP_AUTHORIZATION'), 'Token {0}'.format(session.sid)
        )

        environ.pop('MONGOREST_SETTINGS_MODULE')
Beispiel #4
0
def _fixmanpager(auto=False):
    """If MANPAGER is set to the vim plugin manpager.vim, this screws up the builtin help(...) function when run in a shell (see pydoc.py and https://bugs.python.org/issue8637).
    """
    from os import environ as __environ

    mp = 'MANPAGER'
    pp = 'PYDOCPAGER'

    # if PYDOCPAGER has been explicitly set, sub for MANPAGER
    if pp in __environ:
        __environ[mp] = __environ[pp]

        return True
    elif mp in __environ:
        # look for the word 'vim'
        vimix = __environ[mp].find(' vim ')

        if vimix and __environ[mp].find(mp):
            # if MANPAGER follows vim, assume manpager.vim is being used
            if auto:
                # set MANPAGER to pydocpager.vim
                __environ[mp] = 'vim --not-a-term +PYDOCPAGER -'
            else:
                # just unset MANPAGER
                __environ.pop(mp)

            return True
    else:
        return False
Beispiel #5
0
    def unsetenv(self, key):
        if environ.get(key) is not None:
            environ.pop(key)

        if WINDOWS:
            keyrm = "%s=" % key
            self.msvcrt._putenv(keyrm.encode("utf-8"))
Beispiel #6
0
    def testMusicBrainz(self):
        # output from mb-submit-disc:
        # https://musicbrainz.org/cdtoc/attach?toc=1+12+195856+150+
        # 15687+31841+51016+66616+81352+99559+116070+133243+149997+161710+
        # 177832&tracks=12&id=KnpGsLhvH.lPrNc1PBL21lb9Bg4-
        # however, not (yet) in MusicBrainz database

        # setup to test if MusicBrainz submit URL is hardcoded to use https
        env_original = environ.get('XDG_CONFIG_HOME')
        tmp_conf = mkdtemp(suffix='.config')
        # HACK: hijack env var to avoid overwriting user's whipper config file
        # This works because directory.config_path() builds the location where
        # whipper's conf will reside based on the value of env XDG_CONFIG_HOME
        environ['XDG_CONFIG_HOME'] = tmp_conf
        self.config = config.Config()
        self.config._parser.add_section('musicbrainz')
        self.config._parser.set('musicbrainz', 'server',
                                'http://musicbrainz.org')
        self.config.write()
        self.assertEqual(self.table.getMusicBrainzSubmitURL(),
                         "http://musicbrainz.org/cdtoc/attach?toc=1+12+1958"
                         "56+150+15687+31841+51016+66616+81352+99559+116070+13"
                         "3243+149997+161710+177832&tracks=12&id=KnpGsLhvH.lPr"
                         "Nc1PBL21lb9Bg4-")
        # HACK: continuation - restore original env value (if defined)
        if env_original is not None:
            environ['XDG_CONFIG_HOME'] = env_original
        else:
            environ.pop('XDG_CONFIG_HOME', None)
        self.assertEqual(self.table.getMusicBrainzDiscId(),
                         "KnpGsLhvH.lPrNc1PBL21lb9Bg4-")
        rmtree(tmp_conf)
Beispiel #7
0
    def _get_info(self):
        old_lang = environ.get('LANG')
        environ['LANG'] = 'C'

        sys_profiler_process = Popen(
            ["system_profiler", "SPBluetoothDataType"],
            stdout=PIPE
        )

        stdout = sys_profiler_process.communicate()[0].decode('utf-8')
        output = stdout.splitlines()

        lines = []
        for line in output:
            if 'Bluetooth Power' not in line:
                continue
            lines.append(line)

        if old_lang is None:
            environ.pop('LANG')
        else:
            environ['LANG'] = old_lang

        if output and len(lines) == 1:
            return lines[0].split()[2]
        else:
            return None
Beispiel #8
0
def reload_settings():
    from os import environ
    global _cached_config

    for s in _cached_config:
        environ.pop(s, None)
    _cached_config = load_config()
Beispiel #9
0
def _stop_acceptance_cluster():
    """
    Stop the Flocker cluster configured for the acceptance tests.

    XXX https://clusterhq.atlassian.net/browse/FLOC-1563
    Flocker doesn't support using flocker-deploy along-side flocker-control and
    flocker-agent. Since flocker-deploy (in it's SSH using incarnation) is
    going away, we do the hack of stopping the cluster before running tests
    that use flocker-deploy. This introduces an order dependency on the
    acceptance test-suite.

    This also removes the environment variables associated with the cluster, so
    that tests attempting to use it will be skipped.

    :return: A ``Deferred`` which fires when the cluster is stopped.
    """
    control_node = environ.pop("FLOCKER_ACCEPTANCE_CONTROL_NODE", None)
    agent_nodes_env_var = environ.pop("FLOCKER_ACCEPTANCE_AGENT_NODES", "")
    agent_nodes = filter(None, agent_nodes_env_var.split(':'))

    if control_node and agent_nodes:
        return succeed(sync_perform(
            dispatcher,
            stop_cluster(control_node, agent_nodes)
        ))
    else:
        return succeed(None)
Beispiel #10
0
    def test_settings_default_values(self):
        environ.pop('MONGOREST_SETTINGS_MODULE', None)

        self.assertEqual(settings.AUTH_COLLECTION, '')

        self.assertIsNotNone(settings.CORS)
        self.assertEqual(settings.CORS['Access-Control-Allow-Origin'], '*')
        self.assertEqual(settings.CORS['Access-Control-Allow-Methods'],
                         'GET,POST,PUT,PATCH,DELETE,OPTIONS')
        self.assertEqual(
            settings.CORS['Access-Control-Allow-Headers'],
            'Accept,Accept-Encoding,Authorization,Content-Length,Content-Type,'
            'Origin,User-Agent,X-CSRFToken,X-Requested-With')
        self.assertEqual(settings.CORS['Access-Control-Allow-Credentials'],
                         'true')

        self.assertEqual(settings.MIDDLEWARES, [])

        self.assertIsNotNone(settings.MONGODB)
        self.assertEqual(settings.MONGODB['URI'], '')
        self.assertEqual(settings.MONGODB['USERNAME'], '')
        self.assertEqual(settings.MONGODB['PASSWORD'], '')
        self.assertEqual(settings.MONGODB['HOST'], 'localhost')
        self.assertEqual(settings.MONGODB['HOSTS'], [])
        self.assertEqual(settings.MONGODB['PORT'], 27017)
        self.assertEqual(settings.MONGODB['PORTS'], [])
        self.assertEqual(settings.MONGODB['DATABASE'], 'mongorest')
        self.assertEqual(settings.MONGODB['OPTIONS'], [])

        self.assertEqual(settings.RETRY_LIMIT, 5)
        self.assertEqual(settings.BASE_RETRY_TIME, 2)
        self.assertEqual(settings.LINEAR_RETRIES, False)

        self.assertEqual(settings.SESSION_STORE, '')
def install_module(mod_name: str,
                   pkg_name: str = None,
                   global_name: str = None):
    if pkg_name is None:
        pkg_name = mod_name
    if global_name is None:
        global_name = mod_name

    prev_python_user_base: str = environ.pop('PYTHONUSERBASE', None)
    prev_pip_target: str = environ.pop('PIP_TARGET', None)
    environ['PYTHONUSERBASE'] = dependency_install_dir
    environ['PIP_TARGET'] = dependency_install_dir

    if not exists(dependency_install_dir):
        makedirs(dependency_install_dir)
    run(pip + [
        'install', '--target', dependency_install_dir, '--upgrade',
        '--force-reinstall', pkg_name
    ],
        env=environ)

    if prev_python_user_base is not None:
        environ['PYTHONUSERBASE'] = prev_python_user_base
    if prev_pip_target is not None:
        environ['PIP_TARGET'] = prev_pip_target

    # Invalidate the finder caches as a module has been installed since the python interpreter began
    invalidate_caches()

    # Check that the import worked.
    test_module_available(mod_name)
Beispiel #12
0
def test_init_basic_auth_env():
    environ['COURIER_AUTH_TOKEN'] = "abcd"
    environ.pop('COURIER_AUTH_TOKEN')
    environ['COURIER_AUTH_USERNAME'] = '******'
    environ['COURIER_AUTH_PASSWORD'] = '******'
    c = Courier()
    assert 'Authorization' in c.session.headers
    def test_authentication_middleware_adds_authorization_header_to_response_authorized_with_cookie(
            self):
        environ[
            'MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_auth_settings'

        class TestResource(ListResourceMixin):
            def list(self, request):
                request.environ['session']['test'] = 'test'
                request.environ['collection'] = 'collection'
                return Response()

        self.test_client = self.client(
            WSGIDispatcher(resources=[TestResource]), Response)

        session_store = locate(settings.SESSION_STORE)()
        session = session_store.new()
        session_store.save(session)

        response = self.test_client.get(
            '/', headers=[('Cookie', 'session_id={0}'.format(session.sid))])

        self.assertIn('HTTP_AUTHORIZATION', response.headers)
        self.assertEqual(response.headers.get('HTTP_AUTHORIZATION'),
                         'Token {0}'.format(session.sid))

        environ.pop('MONGOREST_SETTINGS_MODULE')
Beispiel #14
0
    def __set_mode(mode: str) -> None:
        # Remove potentially set environments.
        COMPLUS_ENVIRONMENTS = [
            'COMPlus_JITMinOpts',
            'COMPlus_ReadyToRun',
            'COMPlus_TieredCompilation',
            'COMPlus_ZapDisable',
        ]
        for complus_environment in COMPLUS_ENVIRONMENTS:
            if complus_environment in environ:
                environ.pop(complus_environment)

        # Configure .NET Runtime
        if mode == CompilationAction.TIERED:
            environ['COMPlus_TieredCompilation'] = '1'
        elif mode == CompilationAction.NO_TIERING:
            environ['COMPlus_TieredCompilation'] = '0'
        elif mode == CompilationAction.FULLY_JITTED_NO_TIERING:
            environ['COMPlus_ReadyToRun'] = '0'
            environ['COMPlus_TieredCompilation'] = '0'
            environ['COMPlus_ZapDisable'] = '1'
        elif mode == CompilationAction.MIN_OPT:
            environ['COMPlus_JITMinOpts'] = '1'
            environ['COMPlus_TieredCompilation'] = '0'
        elif mode != CompilationAction.DEFAULT:
            raise ArgumentTypeError('Unknown mode: {}'.format(mode))
Beispiel #15
0
def _stop_acceptance_cluster():
    """
    Stop the Flocker cluster configured for the acceptance tests.

    XXX https://clusterhq.atlassian.net/browse/FLOC-1563
    Flocker doesn't support using flocker-deploy along-side flocker-control and
    flocker-agent. Since flocker-deploy (in it's SSH using incarnation) is
    going away, we do the hack of stopping the cluster before running tests
    that use flocker-deploy. This introduces an order dependency on the
    acceptance test-suite.

    This also removes the environment variables associated with the cluster, so
    that tests attempting to use it will be skipped.

    :return: A ``Deferred`` which fires when the cluster is stopped.
    """
    control_node = environ.pop("FLOCKER_ACCEPTANCE_CONTROL_NODE", None)
    agent_nodes_env_var = environ.pop("FLOCKER_ACCEPTANCE_AGENT_NODES", "")
    agent_nodes = filter(None, agent_nodes_env_var.split(':'))

    if control_node and agent_nodes:
        return succeed(
            sync_perform(dispatcher, stop_cluster(control_node, agent_nodes)))
    else:
        return succeed(None)
Beispiel #16
0
 def _sanitize(self):
     self.token = None
     sess_var_name = 'OP_SESSION_{}'.format(self.account_shorthand)
     try:
         env.pop(sess_var_name)
     except KeyError:
         pass
Beispiel #17
0
 async def run(self):
     """
     If includes is specified, then only sync those,else try to sync all other packages
     """
     # TODO Change Bandersnatch internal API to take proxy settings in from config parameters
     if self.remote.proxy_url:
         environ['http_proxy'] = self.remote.proxy_url
     # local & global timeouts defaults to 10secs and 5 hours
     async with Master(self.remote.url) as master:
         if self.remote.proxy_url:
             environ.pop('http_proxy')
         deferred_download = self.remote.policy != Remote.IMMEDIATE
         workers = self.remote.download_concurrency or self.remote.DEFAULT_DOWNLOAD_CONCURRENCY
         with ProgressReport(
             message="Fetching Project Metadata", code="sync.fetching.project"
         ) as p:
             pmirror = PulpMirror(
                 serial=0,  # Serial currently isn't supported by Pulp
                 master=master,
                 workers=workers,
                 deferred_download=deferred_download,
                 python_stage=self,
                 progress_report=p,
             )
             packages_to_sync = None
             if self.remote.includes:
                 packages_to_sync = [
                     Requirement(pkg).name for pkg in self.remote.includes
                 ]
             await pmirror.synchronize(packages_to_sync)
Beispiel #18
0
def call_unset(args):
    """
    Call unset built_in function
    @param: args: arguments of unset funtion
    """
    for arg in args:
        if arg in environ.keys():
            environ.pop(arg)
Beispiel #19
0
    def test_a_default_setting_can_be_overwritten(self):
        environ.pop('MONGOREST_SETTINGS_MODULE', None)

        self.assertEqual(settings.MONGODB['URI'], '')

        environ['MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.settings_test_settings'

        self.assertEqual(settings.MONGODB['URI'], 'test')
Beispiel #20
0
    def unsetenv(self, key):
        if environ.get(key) is not None:
            environ.pop(key)

        if WINDOWS:
            keyrm = "%s=" % key
            # pylint: disable=protected-access
            self.msvcrt._putenv(keyrm.encode("utf-8"))
Beispiel #21
0
def set_env(key, value):
    old = environ.get(key)
    environ[key] = value
    yield
    if old is None:
        environ.pop(key)
    else:
        environ[key] = old
def instance_path():
    """Fixture for creating an instance path."""
    path = tempfile.mkdtemp()
    environ.update(
        INVENIO_INSTANCE_PATH=environ.get('INSTANCE_PATH', path),
    )
    yield path
    environ.pop('INVENIO_INSTANCE_PATH', None)
    shutil.rmtree(path)
Beispiel #23
0
    def test_a_default_setting_can_be_overwritten(self):
        environ.pop('MONGOREST_SETTINGS_MODULE', None)

        self.assertEqual(settings.MONGODB['URI'], '')

        environ[
            'MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.settings_test_settings'

        self.assertEqual(settings.MONGODB['URI'], 'test')
    def test_cors_middleware_sets_correct_headers_on_other_methods(self):
        response = self.test_client.get('/')

        self.assertIn('Access-Control-Allow-Origin', response.headers)
        self.assertIn('Access-Control-Allow-Methods', response.headers)
        self.assertIn('Access-Control-Allow-Headers', response.headers)
        self.assertIn('Access-Control-Allow-Credentials', response.headers)

        environ.pop('MONGOREST_SETTINGS_MODULE')
Beispiel #25
0
    def test_cors_middleware_sets_correct_headers_on_other_methods(self):
        response = self.test_client.get('/')

        self.assertIn('Access-Control-Allow-Origin', response.headers)
        self.assertIn('Access-Control-Allow-Methods', response.headers)
        self.assertIn('Access-Control-Allow-Headers', response.headers)
        self.assertIn('Access-Control-Allow-Credentials', response.headers)

        environ.pop('MONGOREST_SETTINGS_MODULE')
Beispiel #26
0
 def __update_environment(self):
     from os import chdir
     from os import environ as env
     from os import pathsep as sep
     # set workspace
     chdir(self._svc_cwd_)
     # update environment path
     env['PATH'] = f"{self._svc_env_}\Scripts{sep}{env['PATH']}"
     # remove pythonhome from environment
     env.pop('PYTHONHOME', None)
    def test_raises_value_error_if_auth_collection_is_not_sub_class_of_collection(self):
        environ['MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_auth_colelction_error_settings'

        self.test_client = self.client(
            WSGIDispatcher(resources=[ListResourceMixin]), Response
        )

        with self.assertRaises(ValueError):
            self.test_client.get('/')

        environ.pop('MONGOREST_SETTINGS_MODULE')
    def delete(self, key):
        """Deletes an old, persisted config_value.

        Args:

        Returns:
            None
        """
        environ.pop(key, None)
        ConfigValue.query.filter_by(key=key).delete()
        db.session.commit()
Beispiel #29
0
def git_environ():
    conf = read_conf()
    username = conf.get('git_username') or \
        click.prompt('Enter your Git Username:'******'git_password') or \
        click.prompt('Enter your Git Password', type=str)
    environ['GIT_USERNAME'] = username
    environ['GIT_PASSWORD'] = password
    yield
    environ.pop('GIT_USERNAME', None)
    environ.pop('GIT_PASSWORD', None)
Beispiel #30
0
    def test_load_xml_search_arts_path(self):
        """Test loading file from ARTS_DATA_PATH"""
        backup_path = environ.get("ARTS_DATA_PATH")
        environ["ARTS_DATA_PATH"] = self.ref_dir

        xml.load("vector.xml")

        if backup_path:
            environ["ARTS_DATA_PATH"] = backup_path
        else:
            environ.pop("ARTS_DATA_PATH")
    def _set_environ(self, key: str, value) -> None:
        """Set key in environment to value.

        Note:
            If value is None the key is removed from the
            environment.
        """
        if value is not None:
            environ[key] = value
        else:
            environ.pop(key, None)
Beispiel #32
0
def test_gae():
    environ["GAE_ENV"] = "standard"
    try:
        reload(lumapps.api.utils)
        assert (type(lumapps.api.utils._discovery_cache) ==
                lumapps.api.utils.DiscoveryCacheDict)
    finally:
        environ.pop("GAE_ENV", None)
        reload(lumapps.api.utils)
        invalidate_caches()
    assert (type(lumapps.api.utils._discovery_cache) ==
            lumapps.api.utils.DiscoveryCacheSqlite)
Beispiel #33
0
 def test_health(self):
     app = self.mk_app(self.workspace, settings=self.settings)
     environ['MARATHON_APP_ID'] = 'marathon-app-id'
     environ['MARATHON_APP_VERSION'] = 'marathon-app-version'
     resp = app.get('/health/', status=200)
     data = json.loads(resp.body)
     self.assertEqual(data, {
         'id': 'marathon-app-id',
         'version': 'marathon-app-version',
     })
     environ.pop('MARATHON_APP_ID')
     environ.pop('MARATHON_APP_VERSION')
Beispiel #34
0
def test_storage_options_local():
    env['BAG_STORAGE_KIND'] = 'local'
    conf = config.DumpBagConfig()

    env.pop('BAG_STORAGE_LOCAL_DIR', None)
    with pytest.raises(exception.DumpConfigurationError):
        conf.storage_options()

    env['BAG_STORAGE_LOCAL_DIR'] = 'foo'
    options = conf.storage_options()
    assert type(options) == storage.LocalOptions
    assert options.storage_dir == 'foo'
Beispiel #35
0
def test_encryption_options_gpg():
    env['BAG_ENCRYPTION_KIND'] = 'gpg'
    conf = config.DumpBagConfig()

    env.pop('BAG_GPG_RECIPIENTS', None)
    with pytest.raises(exception.DumpConfigurationError):
        conf.encryption_options()

    env['BAG_GPG_RECIPIENTS'] = '*****@*****.**'
    options = conf.encryption_options()
    assert type(options) == encryption.GPGKeysOptions
    assert options.recipients == ['*****@*****.**']
    def test_authentication_middleware_raises_value_error_if_auth_collection_is_not_sub_class_of_collection(
            self):
        environ[
            'MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_auth_colelction_error_settings'

        self.test_client = self.client(
            WSGIDispatcher(resources=[ListResourceMixin]), Response)

        with self.assertRaises(ValueError):
            self.test_client.get('/')

        environ.pop('MONGOREST_SETTINGS_MODULE')
    def test_adds_authorization_header_to_response_without_token(self):
        environ['MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_auth_settings'

        self.test_client = self.client(
            WSGIDispatcher(resources=[ListResourceMixin]), Response
        )

        response = self.test_client.get('/')

        self.assertIn('HTTP_AUTHORIZATION', response.headers)
        self.assertIn('Token ', response.headers.get('HTTP_AUTHORIZATION'))

        environ.pop('MONGOREST_SETTINGS_MODULE')
    def test_authentication_middleware_does_not_set_token_or_cookie_or_header_if_not_authorized(self):
        environ['MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.middlewares_test_auth_settings'

        self.test_client = self.client(
            WSGIDispatcher(resources=[ListResourceMixin]), Response
        )

        response = self.test_client.get('/')

        self.assertNotIn('HTTP_AUTHORIZATION', response.headers)
        self.assertNotIn('Set-Cookie', response.headers)

        environ.pop('MONGOREST_SETTINGS_MODULE')
Beispiel #39
0
def run(args, api):
    """
        run takes care of calling the action with the needed arguments parsed
        using argparse.

        We first try to call the action. In case the called action requires a
        valid token and the api instance does not have one a TokenRequiredError
        gets raised. In this case we catch the error and ask the user for a
        email/password combination to create a new token. After that we call
        the action again.

        pycclib raises an exception any time the API does answer with a
        HTTP STATUS CODE other than 200, 201 or 204. We catch these exceptions
        here and stop cctrlapp using sys.exit and show the error message to the
        user.
    """

    # check if there is a newer version of cctrl or pycclib
    try:
        check_for_updates(api.check_versions()['cctrl'])
    except KeyError:
        pass

    while True:
        try:
            try:
                args.func(args)
            except TokenRequiredError:
                # check ENV for credentials first
                try:
                    email = env.pop('CCTRL_EMAIL')
                    password = env.pop('CCTRL_PASSWORD')
                except KeyError:
                    email, password = get_credentials()
                try:
                    api.create_token(email, password)
                except UnauthorizedError:
                    sys.exit(messages['NotAuthorized'])
                else:
                    pass
            except ParseAppDeploymentName:
                sys.exit(messages['InvalidAppOrDeploymentName'])
            else:
                break
        except UnauthorizedError, e:
            if delete_tokenfile():
                api.set_token(None)
            else:
                sys.exit(messages['NotAuthorized'])
        except ForbiddenError, e:
            sys.exit(messages['NotAllowed'])
Beispiel #40
0
def main():
    venv_path = 'tmpvenv'

    import sys
    run((sys.executable, '-m', 'virtualenv', venv_path))

    from os.path import join
    venv_python = join(venv_path, 'bin', 'python')

    from os import environ
    environ.pop('__PYVENV_LAUNCHER__', None)  # this thing clobbers python's sys.executable
    # It's set by all OSX python executables  t.t

    run((venv_python, 'stage2.py'))
Beispiel #41
0
    def test_no_proxy(self):
        """
        Starting with Agent 5.0.0, there should always be a local forwarder
        running and all payloads should go through it. So we should make sure
        that we pass the no_proxy environment variable that will be used by requests
        (See: https://github.com/kennethreitz/requests/pull/945 )
        """
        from os import environ as env

        env["http_proxy"] = "http://localhost:3128"
        env["https_proxy"] = env["http_proxy"]
        env["HTTP_PROXY"] = env["http_proxy"]
        env["HTTPS_PROXY"] = env["http_proxy"]

        set_no_proxy_settings()

        self.assertTrue("no_proxy" in env)

        self.assertEquals(env["no_proxy"], "127.0.0.1,localhost,169.254.169.254")
        self.assertEquals({}, get_environ_proxies(
            "http://localhost:17123/api/v1/series"))

        expected_proxies = {
            'http': 'http://localhost:3128',
            'https': 'http://localhost:3128',
            'no': '127.0.0.1,localhost,169.254.169.254'
        }
        environ_proxies = get_environ_proxies("https://www.google.com")
        self.assertEquals(expected_proxies, environ_proxies, (expected_proxies, environ_proxies))

        # Clear the env variables set
        env.pop("http_proxy", None)
        env.pop("https_proxy", None)
        env.pop("HTTP_PROXY", None)
        env.pop("HTTPS_PROXY", None)
    def test_wsgi_dispatcher_adds_middlewares_to_mounts(self):
        environ['MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.wsgi_test_settings'

        class TestWSGIWrapper(WSGIWrapper):
            endpoint = 'test'
            url_map = Map([Rule('/', methods=['GET'], endpoint='test')])

            def test(self, request):
                return Response(status=999)

        app = WSGIDispatcher(resources=[TestWSGIWrapper])
        self.assertIsInstance(app.mounts['/test'], CORSMiddleware)

        environ.pop('MONGOREST_SETTINGS_MODULE')
    def test_cors_middleware_sets_correct_headers_on_options(self):
        response = self.test_client.options('/')

        self.assertIn('Access-Control-Allow-Origin', response.headers)
        self.assertIn('Access-Control-Allow-Methods', response.headers)
        self.assertIn('Access-Control-Allow-Headers', response.headers)
        self.assertIn('Access-Control-Allow-Credentials', response.headers)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.status, '200 OK')
        self.assertEqual(response.data, b'200 OK')
        self.assertEqual(response.headers.get('Content-Type'), 'text/plain')

        environ.pop('MONGOREST_SETTINGS_MODULE')
 def test_runtime_dir_notset(self):
     environ.pop('XDG_RUNTIME_DIR', None)
     self.assertRaises(KeyError, BaseDirectory.get_runtime_dir, strict=True)
     fallback = BaseDirectory.get_runtime_dir(strict=False)
     assert fallback.startswith('/tmp/'), fallback
     assert os.path.isdir(fallback), fallback
     mode = stat.S_IMODE(os.stat(fallback).st_mode)
     self.assertEqual(mode, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR)
     
     # Calling it again should return the same directory.
     fallback2 = BaseDirectory.get_runtime_dir(strict=False)
     self.assertEqual(fallback, fallback2)
     mode = stat.S_IMODE(os.stat(fallback2).st_mode)
     self.assertEqual(mode, stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR)
    def test_develop_theme(self):
        ''' Check if the rules are developed
        '''
        # First we check the status of our environment variables
        var_name = 'DIAZO_ALWAYS_CACHE_RULES'
        env_had_var = var_name in environ
        # and clean it up
        env_var_backup = environ.pop(var_name, None)

        transform = ThemeTransform(None, {})
        # This evaluates to True because we set
        # getConfiguration().debug_mode to True in the test setup
        self.assertTrue(transform.develop_theme())

        # But we can anyway force the cache
        environ[var_name] = 'true'
        self.assertFalse(transform.develop_theme())

        # If we require to debug.diazo the variable will be ignored
        transform = ThemeTransform(None, {'diazo.debug': '1'})
        self.assertTrue(transform.develop_theme())

        # Then we reset our env variables before leaving
        if env_had_var:
            environ[var_name] = env_var_backup
        else:
            del environ[var_name]
Beispiel #46
0
 def test_upload_to_s3(self):
     environ['AWS_SESSION_TOKEN'] = 'Good Times'
     environ.pop('AWS_ACCESS_KEY_ID', None)
 
     with mock.patch('boto3.session.Session') as resource:
         _upload_to_s3('oa.mbtiles', 'xxx', 'yyy', 'zzz', 'bbb', 'kkk')
     
     self.assertEqual(len(resource.mock_calls), 4)
     self.assertEqual(resource.mock_calls[0][1], ('yyy', 'zzz', 'xxx'))
     self.assertEqual(resource.mock_calls[1][1], ('s3', ))
     self.assertEqual(resource.mock_calls[2][0], '().resource().Bucket')
     self.assertEqual(resource.mock_calls[2][1], ('bbb', ))
     self.assertEqual(resource.mock_calls[3][0], '().resource().Bucket().upload_file')
     self.assertEqual(resource.mock_calls[3][1], ('oa.mbtiles', 'kkk'))
         
     self.assertEqual(environ['AWS_SESSION_TOKEN'], 'Good Times')
     self.assertNotIn('AWS_ACCESS_KEY_ID', environ)
Beispiel #47
0
def test_header6():
    """
    Test environment variable QSTAT_HEADER_FULL
    """
    delim = ':'
    callbacks = [
        # <cb function>     <cb args (tuple) >
        ( cb_debug        , () ),
        ( cb_split        , (delim,) ) ]

    environ.pop('CQSTAT_HEADER_FULL')
    parser = ArgParse(__doc__, callbacks)
    parser.parse_it(['-f']) # parse the command line
    h = header_info(parser)
    if h.header == ['custom','qheader','full']:
        good = True
    else:
        good = False
    assert good, "Wrong value for header: %s" % str(h.header)
Beispiel #48
0
    def test_settings_default_values(self):
        environ.pop('MONGOREST_SETTINGS_MODULE', None)

        self.assertEqual(settings.AUTH_COLLECTION, '')

        self.assertIsNotNone(settings.CORS)
        self.assertEqual(
            settings.CORS['Access-Control-Allow-Origin'],
            '*'
        )
        self.assertEqual(
            settings.CORS['Access-Control-Allow-Methods'],
            'GET,POST,PUT,PATCH,DELETE,OPTIONS'
        )
        self.assertEqual(
            settings.CORS['Access-Control-Allow-Headers'],
            'Accept,Accept-Encoding,Authorization,Content-Length,Content-Type,'
            'Origin,User-Agent,X-CSRFToken,X-Requested-With'
        )
        self.assertEqual(
            settings.CORS['Access-Control-Allow-Credentials'], 'true'
        )

        self.assertEqual(settings.MIDDLEWARES, [])

        self.assertIsNotNone(settings.MONGODB)
        self.assertEqual(settings.MONGODB['URI'], '')
        self.assertEqual(settings.MONGODB['USERNAME'], '')
        self.assertEqual(settings.MONGODB['PASSWORD'], '')
        self.assertEqual(settings.MONGODB['HOST'], 'localhost')
        self.assertEqual(settings.MONGODB['HOSTS'], [])
        self.assertEqual(settings.MONGODB['PORT'], 27017)
        self.assertEqual(settings.MONGODB['PORTS'], [])
        self.assertEqual(settings.MONGODB['DATABASE'], 'mongorest')
        self.assertEqual(settings.MONGODB['OPTIONS'], [])

        self.assertEqual(settings.RETRY_LIMIT, 5)
        self.assertEqual(settings.BASE_RETRY_TIME, 2)
        self.assertEqual(settings.LINEAR_RETRIES, False)

        self.assertEqual(settings.SESSION_STORE, '')
Beispiel #49
0
    def _get_uid(self):
        old_lang = environ.get('LANG')
        environ['LANG'] = 'C'

        ioreg_process = Popen(["ioreg", "-l"], stdout=PIPE)
        grep_process = Popen(
            ["grep", "IOPlatformSerialNumber"],
            stdin=ioreg_process.stdout, stdout=PIPE
        )
        ioreg_process.stdout.close()
        output = grep_process.communicate()[0]

        if old_lang is None:
            environ.pop('LANG')
        else:
            environ['LANG'] = old_lang

        result = None
        if output:
            result = output.split()[3][1:-1]
        return result
Beispiel #50
0
    def test_env_var_config_no_split_sequence(self):
        def make_key(appname, key):
            return "{0}_{1}".format(appname.upper(), key.upper())
        appname = "myapp"
        test_dict = {}
        test_dict[make_key(appname, 'channels')] = 'channel1'

        try:
            environ.update(test_dict)
            assert 'MYAPP_CHANNELS' in environ
            config = SampleConfiguration()._set_env_vars(appname)
            assert config.channels == ('channel1',)
        finally:
            [environ.pop(key) for key in test_dict]
Beispiel #51
0
    def test_env_var_config_alias(self):
        def make_key(appname, key):
            return "{0}_{1}".format(appname.upper(), key.upper())
        appname = "myapp"
        test_dict = {}
        test_dict[make_key(appname, 'yes')] = 'yes'
        test_dict[make_key(appname, 'changeps1')] = 'false'

        try:
            environ.update(test_dict)
            assert 'MYAPP_YES' in environ
            config = SampleConfiguration()._set_env_vars(appname)
            assert config.always_yes is True
            assert config.changeps1 is False
        finally:
            [environ.pop(key) for key in test_dict]
Beispiel #52
0
    def test_env_var_config(self):
        def make_key(appname, key):
            return "{0}_{1}".format(appname.upper(), key.upper())
        appname = "myapp"
        test_dict = {}
        test_dict[make_key(appname, 'always_yes')] = 'yes'
        test_dict[make_key(appname, 'changeps1')] = 'false'

        try:
            environ.update(test_dict)
            assert 'MYAPP_ALWAYS_YES' in environ
            raw_data = load_from_string_data('file1', 'file2')
            config = TestConfiguration(app_name=appname)._add_raw_data(raw_data)
            assert config.changeps1 is False
            assert config.always_yes is True
        finally:
            [environ.pop(key) for key in test_dict]
Beispiel #53
0
    def test_an_invalid_setting_will_raise_error(self):
        environ.pop('MONGOREST_SETTINGS_MODULE', None)

        with self.assertRaises(AttributeError):
            return settings.i_am_an_invalid_setting
Beispiel #54
0
    def test_a_new_setting_value_can_be_added(self):
        environ.pop('MONGOREST_SETTINGS_MODULE', None)
        environ['MONGOREST_SETTINGS_MODULE'] = 'tests.fixtures.settings_test_settings'

        self.assertEqual(settings.TEST, 'test')
Beispiel #55
0
def main():
  parser = get_parser()
  args = parser.parse_args()

  vxlDir = path_join(env['VIP_VXL_BUILD_DIR'], env['VIP_VXL_BUILD_TYPE'])
  mkpath(vxlDir);
  os.chdir(vxlDir);


  if os.name == 'nt':
    if not os.path.exists(env['VIP_GLEW_INCLUDE_DIR']):
      print "You are missing Glew"
      from voxel_globe.tools.wget import download
      print "Downloading..."
      zipFile = os.path.join(env['VIP_GLEW_INCLUDE_DIR'], '../../glew.zip')
      dater = download('http://downloads.sourceforge.net/project/glew/glew/' 
                       '1.12.0/glew-1.12.0-win32.zip', 
                       zipFile)
      print "Unpacking..."
      subprocess.Popen(['7z.exe', 'x', zipFile], 
          cwd=os.path.join(env['VIP_GLEW_INCLUDE_DIR'], '../..')).wait();
    from distutils.msvc9compiler import find_vcvarsall
    platform = env.get('VIP_CMAKE_PLATFORM', None)
    if 'VCVARSALL' not in env:
      if platform and platform.lower().startswith('visual'):
        msvcVersion = int(platform.split(' ')[2])
        vcvarall = find_vcvarsall(msvcVersion)
      else:
        for v in range(14, 8, -1): 
        #Start with version 2015(14), and got back to (8),
        #before that its 32 bit only, and we don't care about that
          vcvarall = find_vcvarsall(v)
          if not vcvarall is None:
            if platform.lower() != 'ninja':
              platform = 'Visual Studio %d Win64' % v
            break
      env['VCVARSALL'] = vcvarall
  else:
    platform = env['VIP_CMAKE_PLATFORM']

  if not args.rebuild:
    cmake_options = [];
    
    cmake_options += ['-G', platform]

    #HIGHLY recommended for ninja
    if 'VIP_CMAKE_MAKE_PROGRAM' in env:
      cmake_options += ['-D', 'CMAKE_MAKE_PROGRAM='+\
                              env['VIP_CMAKE_MAKE_PROGRAM']]
    #More or less required for ninja in windows
    if 'VIP_CMAKE_COMPILER' in env:
      cmake_options += ['-D', 'CMAKE_C_COMPILER='+env['VIP_CMAKE_COMPILER']]
      cmake_options += ['-D', 'CMAKE_CXX_COMPILER='+ env['VIP_CMAKE_COMPILER']]


    cmake_options += ['-D', 'CMAKE_BUILD_TYPE='+env['VIP_VXL_BUILD_TYPE']];
    
    if 'VIP_OPENCL_INCLUDE_PATH' in env:
      cmake_options += ['-D', 'OPENCL_INCLUDE_PATH='+
                        env['VIP_OPENCL_INCLUDE_PATH']]
    if 'VIP_OPENCL_LIBRARY_PATH' in env:
      cmake_options += ['-D', 'OPENCL_LIBRARY_PATH='+
                        env['VIP_OPENCL_LIBRARY_PATH']]
    if 'VIP_OPENCL_NVIDIA_LIBRARY_PATH' in env:
      cmake_options += ['-D', 'OPENCL_NVIDIA_LIBRARY_PATH='+
                        env['VIP_OPENCL_NVIDIA_LIBRARY_PATH']]
    if 'VIP_GLEW_INCLUDE_DIR' in env:
      cmake_options += ['-D', 'GLEW_INCLUDE_DIR='+env['VIP_GLEW_INCLUDE_DIR']]
    if 'VIP_GLEW_LIBRARY' in env:
      cmake_options += ['-D', 'GLEW_LIBRARY='+env['VIP_GLEW_LIBRARY']]

    if platform=="Eclipse CDT4 - Unix Makefiles":
      cmake_options += ['-D', 'CMAKE_ECLIPSE_GENERATE_SOURCE_PROJECT=True']

    cmake_options += ['-D', 'CMAKE_INSTALL_PREFIX='+
                   path_join(vxlDir, 'install')];

    cmake_options += ['-D', 'EXECUTABLE_OUTPUT_PATH='+
                   path_join(vxlDir, 'bin')];

    cmake_options += ['-D', 'PYTHON_INCLUDE_DIR='+
                      env['VIP_PYTHON_INCLUDE_DIR'],
                      '-D', 'PYTHON_LIBRARY='+
                      env['VIP_PYTHON_LIBRARY'],
                      '-D', 'PYTHON_INCLUDE_DIR2='+
                      env['VIP_PYTHON_INCLUDE_DIR'],
                      '-D', 'PYTHON_EXECUTABLE='+
                      env['VIP_PYTHON_EXECUTABLE']];
                      
    tmp = env.pop('VIP_CMAKE_ECLIPSE', None);
    if tmp:
      cmake_options += ['-D', 'CMAKE_ECLIPSE_EXECUTABLE='+tmp];

    # Pretty open options section. User can in theory, override anything here  

    tmp = env.pop('VIP_VXL_CMAKE_OPTIONS', None);
    if tmp:
      cmake_options += literal_eval('[' + tmp + ']');
      #Sure, this may be generally unsafe, but only the user administrating the 
      #computer should be able to set and run this, so I choose to trust them
      #Update. literal_eval should be "safe"...er

    tmp = env.pop('VIP_VXL_CMAKE_ENTRIES', None);
    if tmp:
      tmp = literal_eval('[' + tmp + ']');
      for entry in tmp:
        cmake_options += ['-D', entry];

    #Run CMake
    if os.name=='nt':
      if platform.lower()=='ninja':
        args = [ntpath.normpath(os.path.join(env['VIP_INSTALL_DIR'], 
                                             'run_vcvarsall.bat'))]
        pid = subprocess.Popen(args+[env['VIP_CMAKE']] + cmake_options + 
                               [env['VIP_VXL_SRC_DIR']])
      else:
        pid = subprocess.Popen([env['VIP_CMAKE']] + cmake_options + 
                               [env['VIP_VXL_SRC_DIR']])

    else:
      pid = subprocess.Popen([env['VIP_CMAKE']] + cmake_options + 
                               [env['VIP_VXL_SRC_DIR']])
    pid.wait()

  if args.cmake:
    return

  #Make it
  if os.name=='nt':
    if platform.lower()=='ninja':
      cmd = [ntpath.normpath(os.path.join(env['VIP_INSTALL_DIR'], 
                                           'run_vcvarsall.bat')), 
              env['VIP_CMAKE_NINJA']]
    else:
      cmd = [ntpath.normpath(os.path.join(env['VIP_INSTALL_DIR'], 
                                           'run_vcvarsall.bat')), 
              'devenv', 'vxl.sln', '/Build', 
              env['VIP_VXL_BUILD_TYPE']+'^^^|x64']
      #The ^^^ is for Stupid batch escape limitation with | Thank you windows! :(
    
    if platform.lower() != 'ninja':
      if args.verbose:
        pass #No idea right now
      print "Loading vxl solution... This may take a few minutes."
  else:
    cmd = [env['VIP_CMAKE_MAKE_PROGRAM'], '-j', '10']
    if args.verbose:
      if platform.lower() != 'ninja':
        cmd += ['VERBOSE=1']

  if args.verbose:
    if platform.lower() == 'ninja':
      cmd += ['-v']
  pid = subprocess.Popen(cmd, cwd=vxlDir);
  pid.wait();
Beispiel #56
0
import re
from copy import copy
from os import mkdir, environ
from os.path import dirname, join, realpath, exists, basename
from hotqueue import HotQueue
from ConfigParser import ConfigParser
from time import sleep

buildenv = copy(environ)
environ.pop("http_proxy", None)

import subprocess
import requests

# reading the configuration
config = ConfigParser()
config.read(join(dirname(__file__), "config.cfg"))

# start the queue
qjob = HotQueue(
    "jobsubmit",
    host=config.get("hotqueue", "host"),
    port=config.getint("hotqueue", "port"),
    db=config.getint("hotqueue", "db"),
    password=config.get("hotqueue", "password"),
)

qlog = HotQueue(
    "joblog",
    host=config.get("hotqueue", "host"),
    port=config.getint("hotqueue", "port"),
Beispiel #57
0
 def tearDown(self):
     environ.pop('ACS_LOG_CENTRAL')
     reload(Log)
Beispiel #58
0
 def __enter__(self):
     from os import environ
     self.orig = environ.pop('PIP_INDEX_URL', None)
Beispiel #59
0
 def tearDown(self):
     environ.pop('ACS_LOG_STDOUT')
     reload(Log)