Exemplo n.º 1
0
    def test_recursive_install_unavailable_dependency(self):
        config = Configuration()
        session = Session(DummyAuthenticator(), self.prefix)

        auth = ("nono", "le gros robot")
        session.authenticate(auth)
        config.update(auth=auth)

        r_output = textwrap.dedent("""
        Cannot install 'scipy', as this package (or some of its requirements) are not
        available at your subscription level 'Canopy / EPD Free' (You are logged in as
        'nono').
        """)

        self.maxDiff = None
        numpy = dummy_repository_package_factory("numpy", "1.7.1", 1)
        numpy.available = False
        scipy = dummy_repository_package_factory("scipy", "0.12.0", 1)
        scipy.packages = ["numpy 1.7.1"]

        remote_entries = [numpy, scipy]

        with mock.patch("enstaller.main.Enpkg.execute"):
            enpkg = create_prefix_with_eggs(config, self.prefix, [],
                                            remote_entries)
            with mock_print() as m:
                with self.assertRaises(SystemExit):
                    install_req(enpkg, config, "scipy", FakeOptions())
                self.assertMultiLineEqual(m.value, r_output)
Exemplo n.º 2
0
    def test_simple_in_memory(self):
        output_template = textwrap.dedent("""\
            Python version: {pyver}
            enstaller version: {version}
            sys.prefix: {sys_prefix}
            platform: {platform}
            architecture: {arch}
            use_webservice: True
            keyring backend: {keyring_backend}
            settings:
                prefix = {{prefix}}
                repository_cache = {{repository_cache}}
                noapp = False
                proxy = None
            No valid auth information in configuration, cannot authenticate.
            You are not logged in.  To log in, type 'enpkg --userpass'.
        """).format(pyver=PY_VER,
                    sys_prefix=sys.prefix,
                    version=__version__,
                    platform=platform.platform(),
                    arch=platform.architecture()[0],
                    keyring_backend=_keyring_backend_name())

        config = Configuration()
        prefix = config.prefix
        repository_cache = os.path.join(prefix, "LOCAL-REPO")
        r_output = output_template.format(prefix=os.path.normpath(prefix),
                                          repository_cache=repository_cache)

        with mock_print() as m:
            print_config(config, config.prefix,
                         Session(DummyAuthenticator(), self.prefix))
            self.assertMultiLineEqual(m.value, r_output)
Exemplo n.º 3
0
    def setUp(self):
        self.prefix = tempfile.mkdtemp()

        self.config = Configuration()
        self.config.update(use_webservice=False,
                           indexed_repositories=["http://acme.com"])
        self.session = Session(self.klass.from_configuration(self.config),
                               self.prefix)
Exemplo n.º 4
0
    def test_remote_success(self):
        write_default_config(self.f)

        config = Configuration()
        auth = ("usr", "password")
        session = Session(DummyAuthenticator(old_auth_user), self.d)

        with session:
            usr = config._checked_change_auth(auth, session, self.f)
            self.assertEqual(usr, UserInfo(True))
Exemplo n.º 5
0
    def test_use_webservice_invalid_user(self):
        # Given
        config = Configuration()
        responses.add(responses.GET,
                      config.api_url,
                      body=json.dumps(R_JSON_NOAUTH_RESP),
                      content_type='application/json')

        # When/Then
        session = Session(LegacyCanopyAuthManager(config.api_url), self.prefix)
        with session:
            with self.assertRaises(AuthFailedError):
                session.authenticate((FAKE_USER, FAKE_PASSWORD))
Exemplo n.º 6
0
    def test_from_configuration(self):
        # Given
        responses.add(responses.GET,
                      self.config.api_url,
                      status=200,
                      body=json.dumps(R_JSON_AUTH_RESP))
        authenticator = LegacyCanopyAuthManager.from_configuration(self.config)
        session = Session(authenticator, self.prefix)

        # When
        with session:
            # Then no exception
            session.authenticate((FAKE_USER, FAKE_PASSWORD))
Exemplo n.º 7
0
    def test_from_configuration(self):
        # Given
        responses.add(responses.POST,
                      self.token_url,
                      status=200,
                      body=json.dumps({"token": "dummy token"}))
        authenticator = BroodAuthenticator.from_configuration(self.config)
        session = Session(authenticator, self.prefix)
        r_auth = BroodBearerTokenAuth("dummy token")

        # When
        with session:
            session.authenticate((FAKE_USER, FAKE_PASSWORD))

            # Then
            self.assertIsInstance(session._raw.auth, BroodBearerTokenAuth)
            self.assertEqual(session._raw.auth._token, r_auth._token)
Exemplo n.º 8
0
    def test_from_configuration(self):
        # Given
        responses.add(responses.HEAD,
                      self.config.indices[0][0],
                      status=200,
                      body=json.dumps(R_JSON_AUTH_RESP))
        authenticator = OldRepoAuthManager.from_configuration(self.config)
        session = Session(authenticator, self.prefix)

        # When
        with session:
            session.authenticate((FAKE_USER, FAKE_PASSWORD))

        # Then
        self.assertIsInstance(session._raw.auth, requests.auth.HTTPBasicAuth)
        self.assertEqual(session._raw.auth.username, FAKE_USER)
        self.assertEqual(session._raw.auth.password, FAKE_PASSWORD)
Exemplo n.º 9
0
    def test_repository_factory(self):
        # Given
        config = Configuration()
        entries = [
            dummy_repository_package_factory("numpy", "1.8.0", 1),
            dummy_repository_package_factory("scipy", "0.13.3", 1),
        ]
        self._mock_index(entries)

        # When
        with Session(DummyAuthenticator(), self.tempdir) as session:
            repository = repository_factory(session, config.indices)

        # Then
        repository.find_package("numpy", "1.8.0-1")
        repository.find_package("scipy", "0.13.3-1")

        self.assertEqual(repository.find_packages("nose"), [])
Exemplo n.º 10
0
 def setUp(self):
     self.d = tempfile.mkdtemp()
     self.f = os.path.join(self.d, "enstaller4rc")
     self.session = Session(DummyAuthenticator(), self.d)
Exemplo n.º 11
0
def mocked_session_factory(repository_cache):
    return Session(DummyAuthenticator(), repository_cache)