示例#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)
示例#2
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)
示例#3
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))
示例#4
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))
示例#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))
示例#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))
示例#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)
示例#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)
示例#9
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)
示例#10
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)