Exemple #1
0
    def test_use_webservice_valid_user(self):
        config = Configuration()
        config.set_auth(FAKE_USER, FAKE_PASSWORD)

        with mock.patch("enstaller.config.web_auth") as mocked_auth:
            authenticate(config)
            self.assertTrue(mocked_auth.called)
Exemple #2
0
    def test_recursive_install_unavailable_dependency(self):
        config = Configuration()
        config.set_auth("None", "None")

        r_output = textwrap.dedent("""\
        Error: could not resolve "numpy 1.7.1" required by "scipy-0.12.0-1.egg"
        You may be able to force an install of just this egg by using the
        --no-deps enpkg commandline argument after installing another version
        of the dependency.
        Available versions of the required package 'numpy' are:
            1.7.1 (no subscription)
        No package found to fulfill your requirement at your subscription level:
            You are logged in as None.
            Subscription level: EPD
        """)

        self.maxDiff = None
        numpy = dummy_enpkg_entry_factory("numpy", "1.7.1", 1)
        numpy.available = False
        scipy = dummy_enpkg_entry_factory("scipy", "0.12.0", 1)
        scipy.packages = [Dependency.from_spec_string("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, "scipy", FakeOptions())
                self.assertMultiLineEqual(m.value, r_output)
Exemple #3
0
    def test_use_remote(self):
        config = Configuration()
        config.use_webservice = False
        config.set_auth(FAKE_USER, FAKE_PASSWORD)

        remote = mock.Mock()
        user = authenticate(config, remote)
        self.assertEqual(user, {"is_authenticated": True})
Exemple #4
0
    def test_reset_auth_without_keyring(self):
        config = Configuration()
        config.set_auth(FAKE_USER, FAKE_PASSWORD)

        config.reset_auth()

        self.assertIsNone(config._username)
        self.assertIsNone(config._password)
        self.assertFalse(config.is_auth_configured)
Exemple #5
0
    def test_use_webservice_invalid_user(self):
        config = Configuration()
        config.set_auth(FAKE_USER, FAKE_PASSWORD)

        with mock.patch("enstaller.config.web_auth") as mocked_auth:
            mocked_auth.return_value = {"is_authenticated": False}

            with self.assertRaises(AuthFailedError):
                authenticate(config)
Exemple #6
0
    def test_deprecated_get_auth(self):
        with mkdtemp() as d:
            f = os.path.join(d, "enstaller4rc")
            config = Configuration()
            config.set_auth(FAKE_USER, FAKE_PASSWORD)
            config.write(f)

            with mock.patch("enstaller.config.get_path", lambda: f):
                self.assertEqual(get_auth(), (FAKE_USER, FAKE_PASSWORD))
Exemple #7
0
    def test_with_keyring(self):
        with make_keyring_available_context() as mocked_keyring:
            config = Configuration()
            config.set_auth(FAKE_USER, FAKE_PASSWORD)

            self.assertEqual(config.get_auth(), (FAKE_USER, FAKE_PASSWORD))
            mocked_keyring.set_password.assert_called_with("Enthought.com",
                                                           FAKE_USER,
                                                           FAKE_PASSWORD)
Exemple #8
0
    def test_reset_auth_with_keyring(self):
        with make_keyring_available_context() as m:
            config = Configuration()
            config.set_auth(FAKE_USER, FAKE_PASSWORD)

            config.reset_auth()

            m.set_password.assert_called_with(KEYRING_SERVICE_NAME, FAKE_USER, "")
            self.assertIsNone(config._username)
            self.assertIsNone(config._password)
            self.assertTrue(config.use_keyring)
            self.assertFalse(config.is_auth_configured)
Exemple #9
0
    def test_no_config_file(self):
        with tempfile.NamedTemporaryFile(delete=False) as fp:
            fp.write("")

        config = Configuration()
        self.assertEqual(config.get_auth(), (None, None))

        config.set_auth(FAKE_USER, FAKE_PASSWORD)
        config.write(fp.name)

        new_config = Configuration.from_file(fp.name)
        self.assertEqual(new_config.get_auth(), (FAKE_USER, FAKE_PASSWORD))
Exemple #10
0
    def test_keyring_call(self):
        with mock.patch("__builtin__.open"):
            mocked_keyring = mock.MagicMock(["get_password", "set_password"])
            with mock.patch("enstaller.config.keyring", mocked_keyring):
                config = Configuration()
                config.set_auth(FAKE_USER, FAKE_PASSWORD)
                config.write("dummy_config.rc")

                r_args = ("Enthought.com", FAKE_USER, FAKE_PASSWORD)
                self.assertTrue(mocked_keyring.set_password.call_with(r_args))
                r_args = ("Enthought.com", FAKE_USER)
                self.assertTrue(mocked_keyring.get_password.call_with(r_args))
Exemple #11
0
    def test_simple(self):
        config = Configuration()
        config.set_auth(FAKE_USER, FAKE_PASSWORD)
        config.write(self.f)

        config = Configuration.from_file(self.f)

        self.assertEqual(config.EPD_auth, FAKE_CREDS)
        self.assertEqual(config.autoupdate, True)
        self.assertEqual(config.proxy, None)
        self.assertEqual(config.use_webservice, True)
        self.assertEqual(config.webservice_entry_point, get_default_url())
Exemple #12
0
    def test_use_remote_invalid(self):
        config = Configuration()
        config.use_webservice = False
        config.set_auth(FAKE_USER, FAKE_PASSWORD)

        remote = mock.Mock()

        for klass in KeyError, Exception:
            attrs = {"connect.side_effect": klass()}
            remote.configure_mock(**attrs)

            with self.assertRaises(AuthFailedError):
                authenticate(config, remote)
Exemple #13
0
    def test_with_auth(self):
        config = Configuration()
        config.set_auth(FAKE_USER, FAKE_PASSWORD)

        self.assertEqual(config.get_auth(), (FAKE_USER, FAKE_PASSWORD))