Esempio n. 1
0
    def test_max_retries_with_etag(self):
        # Given
        config = Configuration()

        # When/Then
        with Session.from_configuration(config) as session:
            with session.etag():
                for prefix in ("http://", "https://"):
                    self.assertEqual(session._raw.adapters[prefix].max_retries,
                                     0)

        # When/Then
        config.update(max_retries=3)
        with Session.from_configuration(config) as session:
            with session.etag():
                for prefix in ("http://", "https://"):
                    self.assertEqual(session._raw.adapters[prefix].max_retries,
                                     3)
Esempio n. 2
0
    def test_multiple_etag(self):
        # Given
        config = Configuration()
        session = mocked_session_factory(config.repository_cache)

        # When
        with mock.patch("enstaller.session.CacheControlAdapter") as m:
            with session.etag():
                pass
            with session.etag():
                pass

        # Then
        self.assertFalse(
            isinstance(session._raw.adapters["http://"], CacheControlAdapter))
        self.assertFalse(
            isinstance(session._raw.adapters["https://"], CacheControlAdapter))
        self.assertEqual(m.call_count, 4)
Esempio n. 3
0
    def test_update_all_no_updates(self):
        r_output = "No new version of any installed package is available\n"
        config = Configuration()

        installed_entries = [
            dummy_installed_package_factory("numpy", "1.7.1", 2),
            dummy_installed_package_factory("scipy", "0.13.0", 1)
        ]
        remote_entries = [
            dummy_repository_package_factory("numpy", "1.7.1", 1),
            dummy_repository_package_factory("scipy", "0.12.0", 1)
        ]

        with mkdtemp() as d:
            enpkg = create_prefix_with_eggs(config, d, installed_entries,
                                            remote_entries)
            with mock_print() as m:
                update_all(enpkg, config, FakeOptions())
                self.assertMultiLineEqual(m.value, r_output)
Esempio n. 4
0
    def test_pattern(self):
        config = Configuration()
        config.update(use_webservice=False)
        with mkdtemp() as d:
            r_output = textwrap.dedent("""\
                Name                   Versions           Product              Note
                ================================================================================
                dummy                  0.9.8-1            commercial           {0}
                                     * 1.0.1-1            commercial           {0}
                """.format(""))
            entries = [
                dummy_repository_package_factory("dummy", "1.0.1", 1),
                dummy_repository_package_factory("dummy", "0.9.8", 1),
                dummy_repository_package_factory("another_package", "2.0.0", 1)
            ]
            installed_entries = [
                dummy_installed_package_factory("dummy", "1.0.1", 1)
            ]
            enpkg = create_prefix_with_eggs(config, d, installed_entries,
                                            entries)

            with mock_print() as m:
                search(enpkg._remote_repository,
                       enpkg._top_installed_repository,
                       config,
                       UserInfo(True),
                       pat=re.compile("dummy"))
                self.assertMultiLineEqual(m.value, r_output)

            r_output = textwrap.dedent("""\
                Name                   Versions           Product              Note
                ================================================================================
                another_package        2.0.0-1            commercial           {0}
                dummy                  0.9.8-1            commercial           {0}
                                     * 1.0.1-1            commercial           {0}
                """.format(""))
            with mock_print() as m:
                search(enpkg._remote_repository,
                       enpkg._top_installed_repository,
                       config,
                       UserInfo(True),
                       pat=re.compile(".*"))
                self.assertMultiLineEqual(m.value, r_output)
Esempio n. 5
0
    def test_install_non_pypi_after_pypi(self):
        # Given
        config = Configuration()
        config.update(auth=("nono", "le petit robot"))

        session = Session.from_configuration(config)
        session.authenticate(config.auth)

        repository = repository_factory(session, config.indices)

        enpkg = Enpkg(repository, session, [self.prefix])
        enpkg.execute = mock.Mock()

        # When
        with mock_print() as mocked_print:
            with mock_raw_input("yes"):
                install_req(enpkg, config, "swig", FakeOptions())

        # Then
        self._assert_dont_ask_for_pypi(mocked_print)
Esempio n. 6
0
    def test_simple_legacy_canopy(self):
        # Given
        url = "https://api.enthought.com"

        config = Configuration()
        config.update(store_url=url, auth=FAKE_AUTH)

        responses.add(responses.GET,
                      url + "/accounts/user/info/",
                      status=200,
                      body=json.dumps(R_JSON_AUTH_RESP))

        session = Session.from_configuration(config)
        session.authenticate(config.auth)

        # When
        user_info = UserInfo.from_session(session)

        # Then
        self.assertEqual(user_info.first_name, R_JSON_AUTH_RESP["first_name"])
Esempio n. 7
0
    def test_simple_brood_auth(self):
        # Given
        url = "https://acme.com"
        token_url = url + "/api/v0/json/auth/tokens/auth"

        config = Configuration()
        config.update(store_url="brood+" + url, auth=FAKE_AUTH)

        responses.add(responses.POST,
                      token_url,
                      status=200,
                      body=json.dumps({"token": "dummy token"}))

        session = Session.from_configuration(config)
        session.authenticate(config.auth)

        # When
        user_info = UserInfo.from_session(session)

        # Then
        self.assertTrue(user_info.is_authenticated)
Esempio n. 8
0
    def test_handle_stripped_header_incomplete_data(self):

        # Given
        def callback(request):
            self.assertTrue(
                "gzip" in request.headers.get("Accept-Encoding", ""))

            headers = {"Content-Encoding": ""}
            incomplete_body = self._gzip_compress(b"{}")[:-1]
            return (200, headers, incomplete_body)

        responses.add_callback(responses.GET, "https://acme.com/index.json",
                               callback)

        config = Configuration()

        # When/Then
        session = Session.from_configuration(config)
        resp = session.fetch("https://acme.com/index.json")
        with self.assertRaises(requests.exceptions.ContentDecodingError):
            _fetch_json_with_progress(resp, "acme.com", quiet=False)
Esempio n. 9
0
    def test_install_not_available(self):
        # Given
        config = Configuration()
        config.update(auth=FAKE_AUTH)

        nose = dummy_repository_package_factory("nose", "1.3.0", 1)
        nose.available = False
        repository = Repository()
        repository.add_package(nose)

        enpkg = Enpkg(repository,
                      mocked_session_factory(config.repository_cache),
                      [self.prefix])
        enpkg.execute = mock.Mock()

        # When/Then
        with mock.patch("enstaller.config.subscription_message") as \
                subscription_message:
            with self.assertRaises(SystemExit) as e:
                install_req(enpkg, config, "nose", FakeOptions())
            subscription_message.assert_called()
            self.assertEqual(e.exception.code, 1)
Esempio n. 10
0
    def test_simple_no_webservice(self):
        output_template = textwrap.dedent("""\
            Python version: {pyver}
            enstaller version: {version}
            sys.prefix: {sys_prefix}
            platform: {platform}
            architecture: {arch}
            use_webservice: False
            keyring backend: {keyring_backend}
            settings:
                prefix = {{prefix}}
                repository_cache = {{repository_cache}}
                noapp = False
                proxy = None
                IndexedRepos:
                    'http://acme.com/'
            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())

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

        config = Configuration()
        config.update(indexed_repositories=["http://acme.com"],
                      use_webservice=False)

        with mock_print() as m:
            print_config(config, config.prefix,
                         Session(DummyAuthenticator(), self.prefix))
            self.assertMultiLineEqual(m.value, r_output)
Esempio n. 11
0
    def test_simple(self):
        # Given
        config = Configuration()
        session = Session.from_configuration(config)
        entries = [
            dummy_repository_package_factory("MKL", "10.3", 1),
            dummy_repository_package_factory("numpy",
                                             "1.8.0",
                                             1,
                                             dependencies=["MKL 10.3"]),
        ]
        _mock_index(entries)
        r_output = textwrap.dedent("""\
            Resolving dependencies for numpy: numpy-1.8.0-1.egg
                mkl 10.3
        """)

        # When
        with mock_print() as m:
            query_platform(session, config.indices, "numpy", custom_plat)

        # Then
        self.assertMultiLineEqual(m.value, r_output)
Esempio n. 12
0
    def test_handle_stripped_header(self):

        # Given
        def callback(request):
            self.assertTrue(
                "gzip" in request.headers.get("Accept-Encoding", ""))

            headers = {"Content-Encoding": ""}
            body = self._gzip_compress(b"{}")
            return (200, headers, body)

        responses.add_callback(responses.GET, "https://acme.com/index.json",
                               callback)

        config = Configuration()

        # When
        session = Session.from_configuration(config)
        resp = session.fetch("https://acme.com/index.json")
        data = _fetch_json_with_progress(resp, "acme.com", quiet=False)

        # Then
        self.assertEqual(data, {})
Esempio n. 13
0
    def test_verify_ssl_setup(self):
        # When
        config = Configuration()

        # Then
        self.assertTrue(config.verify_ssl)

        # Given
        data = StringIO("verify_ssl = True")

        # When
        config = Configuration.from_file(data)

        # Then
        self.assertTrue(config.verify_ssl)

        # Given
        data = StringIO("verify_ssl = False")

        # When
        config = Configuration.from_file(data)

        # Then
        self.assertFalse(config.verify_ssl)
Esempio n. 14
0
    def test_not_available(self):
        responses.add(responses.GET,
                      "https://acme.com/accounts/user/info/",
                      body=json.dumps(R_JSON_AUTH_FREE_RESP))
        config = Configuration()
        config.update(store_url="https://acme.com")

        r_output = textwrap.dedent("""\
            Name                   Versions           Product              Note
            ================================================================================
            another_package        2.0.0-1            commercial           not subscribed to
            dummy                  0.9.8-1            commercial           {0}
                                   1.0.1-1            commercial           {0}
            Note: some of those packages are not available at your current
            subscription level ('Canopy / EPD Free').
            """.format(""))
        another_entry = dummy_repository_package_factory(
            "another_package", "2.0.0", 1)
        another_entry.available = False

        entries = [
            dummy_repository_package_factory("dummy", "1.0.1", 1),
            dummy_repository_package_factory("dummy", "0.9.8", 1),
            another_entry
        ]

        with Session.from_configuration(config) as session:
            with mkdtemp() as d:
                with mock_print() as m:
                    enpkg = create_prefix_with_eggs(config,
                                                    d,
                                                    remote_entries=entries)
                    search(enpkg._remote_repository,
                           enpkg._installed_repository, config, session)

                self.assertMultiLineEqual(m.value, r_output)
Esempio n. 15
0
    def test_install_pypi_requirement(self):
        self.maxDiff = None

        # Given
        r_message = textwrap.dedent("""\
        The following packages/requirements are coming from the PyPi repo:

        rednose

        The PyPi repository which contains >10,000 untested ("as is")
        packages. Some packages are licensed under GPL or other licenses
        which are prohibited for some users. Dependencies may not be
        provided. If you need an updated version or if the installation
        fails due to unmet dependencies, the Knowledge Base article
        Installing external packages into Canopy Python
        (https://support.enthought.com/entries/23389761) may help you with
        installing it.

        Are you sure that you wish to proceed?  (y/[n])
        """)

        config = Configuration()
        session = Session.from_configuration(config)
        session.authenticate(("nono", "le petit robot"))
        repository = repository_factory(session, config.indices)

        enpkg = Enpkg(repository, session, [self.prefix])
        enpkg.execute = mock.Mock()

        # When
        with mock_print() as mocked_print:
            with mock_raw_input("yes"):
                install_req(enpkg, config, "rednose", FakeOptions())

        # Then
        self.assertMultiLineEqual(mocked_print.value, r_message)
Esempio n. 16
0
    def test_set_epd_auth(self):
        config = Configuration()
        config.set_auth_from_encoded(FAKE_CREDS)

        self.assertEqual(config.auth, FAKE_AUTH)
Esempio n. 17
0
 def test_without_auth_or_keyring(self):
     config = Configuration()
     self.assertIsNone(config.auth)
Esempio n. 18
0
    def test_with_auth(self):
        config = Configuration()
        config.update(auth=(FAKE_USER, FAKE_PASSWORD))

        self.assertEqual(config.auth, FAKE_AUTH)
Esempio n. 19
0
    def test_nones(self):
        config = Configuration()

        with self.assertRaises(InvalidConfiguration):
            config.update(auth=(None, None))
Esempio n. 20
0
    def test_set_invalid_epd_auth(self):
        config = Configuration()

        with self.assertRaises(InvalidConfiguration):
            config.set_auth_from_encoded(FAKE_USER)
Esempio n. 21
0
 def test_writable_repository_cache(self):
     config = Configuration()
     with mkdtemp() as d:
         config.update(repository_cache=d)
         self.assertEqual(config.repository_cache, d)
Esempio n. 22
0
def _mock_list_dependencies_configuration(f):
    config = Configuration()
    config.update(auth=("fake", "auth"))
    return mock.patch("enstaller.main.Configuration._from_legacy_locations",
                      return_value=config)(f)