Esempio n. 1
0
    def test_401_index_handling(self):
        self.maxDiff = None

        # Given
        repo = "http://acme.com/repo/ets/"
        config = Configuration()
        config.update(use_webservice=False, indexed_repositories=[repo])
        config.update(auth=("nono", "le petit robot"))
        config.write(self.config)

        url = repo + "index.json"
        responses.add(responses.HEAD, url, status=401)

        error_message = textwrap.dedent("""\
            Could not authenticate as 'nono' (server answered: 'Invalid credentials')
            Ensure your username and password are correct.

            You can change your authentication details with 'enpkg --userpass'.
        """)

        # When
        with use_given_config_context(self.config):
            with mock_print() as m:
                with self.assertRaises(SystemExit):
                    main(["dummy_requirement"])

        # Then
        self.assertMultiLineEqual(m.value, error_message)
Esempio n. 2
0
    def test_invalid_certificate_config(self):
        self.maxDiff = None

        # Given
        url = "http://acme.com"
        config = Configuration()
        config.update(store_url=url)
        config.update(auth=("nono", "le petit robot"))
        config.write(self.config)

        responses.add_callback(responses.GET, re.compile(url + "/*"),
                               self._dummy_ssl_error_callback)

        error_message = "To connect to 'acme.com' insecurely, add the `-k` " \
                        "flag to enpkg command"

        # When
        with use_given_config_context(self.config):
            with mock_print() as m:
                with self.assertRaises(SystemExit):
                    main(["--config"])

        # Then
        last_line = m.value.splitlines()[-1]
        self.assertMultiLineEqual(last_line, error_message)
Esempio n. 3
0
    def test_invalid_certificate_dont_webservice(self):
        self.maxDiff = None

        # Given
        url = "http://acme.com"
        config = Configuration()
        config.update(use_webservice=False,
                      indexed_repositories=["http://acme.com/repo/"])
        config.update(auth=("nono", "le petit robot"))
        config.write(self.config)

        def callback(request):
            msg = "Dummy SSL error"
            raise requests.exceptions.SSLError(msg, request=request)
        responses.add_callback(responses.HEAD, re.compile(url + "/*"),
                               callback)

        error_message = textwrap.dedent("""\
            SSL error: Dummy SSL error
            To connect to 'acme.com' insecurely, add the `-k` flag to enpkg command
        """)

        # When
        with use_given_config_context(self.config):
            with mock_print() as m:
                with self.assertRaises(SystemExit):
                    main(["dummy_requirement"])

        # Then
        self.assertMultiLineEqual(m.value, error_message)
Esempio n. 4
0
 def test_print_version(self):
     # XXX: this is lousy test: we'd like to at least ensure we're printing
     # the correct version, but capturing the stdout is a bit tricky. Once
     # we replace print by proper logging, we should be able to do better.
     try:
         main(["--version"])
     except SystemExit as e:
         self.assertEqual(e.code, 0)
Esempio n. 5
0
    def test_non_existing_config_path(self, install_req):
        # Given
        args = ["--config-path=config.yaml", "foo"]

        # When/Then
        with self.assertRaises(SystemExit) as exc:
            main(args)
        self.assertEqual(exception_code(exc), -1)
Esempio n. 6
0
    def test_non_existing_config_path(self, install_req):
        # Given
        args = ["--config-path=config.yaml", "foo"]

        # When/Then
        with self.assertRaises(SystemExit) as exc:
            main(args)
        self.assertEqual(exception_code(exc), -1)
Esempio n. 7
0
    def test_non_existing_config_path(self, install_req):
        # Given
        dummy_path = os.path.abspath(os.path.join("yola", "config.yaml"))
        args = ["--config-path={0}".format(dummy_path), "foo"]

        # When/Then
        with self.assertRaises(SystemExit) as exc:
            main(args)
        self.assertEqual(exception_code(exc), -1)
Esempio n. 8
0
    def test_user_valid_config(self, install_req):
        # Given
        args = ["--user", "foo"]

        # When
        with mock.patch("enstaller.main.check_prefixes") as m:
            main(args)

        # Then
        m.assert_called_with([site.USER_BASE, sys.prefix])
Esempio n. 9
0
    def test_enstaller_in_req(self):
        r_output = textwrap.dedent("""\
            Enstaller has been updated.
            Please re-run your previous command.
        """)

        with mock_print() as m:
            with mock.patch("enstaller.main.inplace_update"):
                main(["enstaller"])
        self.assertMultiLineEqual(m.value, r_output)
Esempio n. 10
0
    def test_user_invalid_config(self, install_req):
        # Given
        r_msg = "Using the --user option, but your PYTHONPATH is not setup " \
                "accordingly"

        args = ["--user", "foo"]

        # When/Then
        with self.assertWarnsRegex(Warning, r_msg):
            main(args)
Esempio n. 11
0
    def test_user_valid_config(self, install_req):
        # Given
        args = ["--user", "foo"]

        # When
        with mock.patch("enstaller.main.check_prefixes") as m:
            main(args)

        # Then
        m.assert_called_with([site.USER_BASE, sys.prefix])
Esempio n. 12
0
    def test_user_invalid_config(self, install_req):
        # Given
        r_msg = "Using the --user option, but your PYTHONPATH is not setup " \
                "accordingly"

        args = ["--user", "foo"]

        # When/Then
        with self.assertWarnsRegex(Warning, r_msg):
            main(args)
Esempio n. 13
0
    def test_setup_proxy(self, install_req):
        # Given
        args = ["--proxy=http://acme.com:3128", "foo"]

        # When
        with mock.patch("enstaller.main.setup_proxy_or_die") as m:
            main(args)

        # Then
        m.assert_called()
        self.assertEqual(m.call_args[0][1], "http://acme.com:3128")
Esempio n. 14
0
    def test_setup_proxy(self, install_req):
        # Given
        args = ["--proxy=http://acme.com:3128", "foo"]

        # When
        with mock.patch("enstaller.main.setup_proxy_or_die") as m:
            main(args)

        # Then
        m.assert_called()
        self.assertEqual(m.call_args[0][1], "http://acme.com:3128")
Esempio n. 15
0
    def test_max_retries(self, install_req):
        # Given
        args = ["--max-retries", "42"]

        # When
        with mock.patch("enstaller.main.dispatch_commands_with_enpkg") as m:
            main(args)
        config = m.call_args[0][2]

        # Then
        m.assert_called()
        self.assertEqual(config.max_retries, 42)
Esempio n. 16
0
    def test_max_retries(self, install_req):
        # Given
        args = ["--max-retries", "42"]

        # When
        with mock.patch("enstaller.main.dispatch_commands_with_enpkg") as m:
            main(args)
        config = m.call_args[0][2]

        # Then
        m.assert_called()
        self.assertEqual(config.max_retries, 42)
Esempio n. 17
0
    def test_home_expand(self, install_req):
        # Given
        path = "~/config.yaml"
        args = ["--config-path=~/config.yaml", "foo"]

        r_path = os.path.expanduser(path)

        # When
        with mock.patch("enstaller.main.Configuration.from_yaml_filename",
                        return_value=Configuration()) \
                as mocked_factory:
            with self.assertRaises(SystemExit) as exc:
                main(args)
            self.assertEqual(exception_code(exc), -1)

        # Then
        mocked_factory.assert_called_with(r_path)
Esempio n. 18
0
    def test_config_path_missing_auth(self, install_req):
        # Given
        path = os.path.join(self.prefix, "config.yaml")
        with open(path, "wt") as fp:
            fp.write("")

        args = ["--config-path=" + path, "foo"]

        r_msg = "Authentication missing from {0!r}\n".format(path)

        # When
        with mock_print() as m:
            with self.assertRaises(SystemExit) as exc:
                main(args)

        # Then
        self.assertEqual(exception_code(exc), -1)
        self.assertEqual(m.value, r_msg)
Esempio n. 19
0
    def test_simple(self):
        # Given
        path = os.path.join(self.prefix, "enstaller.yaml")
        responses.add(responses.POST, "http://acme.com/api/v0/json/auth/tokens/auth",
                      body=json.dumps({"token": "dummy token"}))

        with open(path, "wt") as fp:
            fp.write(textwrap.dedent("""\
                    store_url: "http://acme.com"
                    authentication:
                      kind: "simple"
                      username: "******"
                      password: "******"
            """))

        # When
        # Then No exception
        main(["-s", "numpy", "-c", path])
Esempio n. 20
0
    def test_config_path_missing_auth(self, install_req):
        # Given
        path = os.path.join(self.prefix, "config.yaml")
        with open(path, "wt") as fp:
            fp.write("")

        args = ["--config-path=" + path, "foo"]

        r_msg = "Authentication missing from {0!r}\n".format(path)

        # When
        with mock_print() as m:
            with self.assertRaises(SystemExit) as exc:
                main(args)

        # Then
        self.assertEqual(exception_code(exc), -1)
        self.assertEqual(m.value, r_msg)
Esempio n. 21
0
    def test_verbose_flag(self, install_req):
        # Given
        args = ["foo"]

        # When
        with mock.patch("enstaller.logging.basicConfig") as m:
            main(args)

        # Then
        m.assert_called()
        self.assertEqual(m.call_args[1]["level"], logging.WARN)

        # Given
        args = ["foo", "-v"]

        # When
        with mock.patch("enstaller.logging.basicConfig") as m:
            main(args)

        # Then
        m.assert_called()
        self.assertEqual(m.call_args[1]["level"], logging.INFO)

        # Given
        args = ["foo", "-vv"]

        # When
        with mock.patch("enstaller.main.http_client.HTTPConnection") \
                as fake_connection:
            with mock.patch("enstaller.logging.basicConfig") as m:
                main(args)

        # Then
        fake_connection.assert_not_called()

        m.assert_called()
        self.assertEqual(m.call_args[1]["level"], logging.DEBUG)

        # Given
        args = ["foo", "-vvv"]

        # When
        with mock.patch("enstaller.main.http_client.HTTPConnection") \
                as fake_connection:
            with mock.patch("enstaller.logging.basicConfig") as m:
                main(args)

        # Then
        fake_connection.assert_called()
        self.assertEqual(fake_connection.debuglevel, 1)

        m.assert_called()
        self.assertEqual(m.call_args[1]["level"], logging.DEBUG)
Esempio n. 22
0
    def test_verbose_flag(self, install_req):
        # Given
        args = ["foo"]

        # When
        with mock.patch("enstaller.logging.basicConfig") as m:
            main(args)

        # Then
        m.assert_called()
        self.assertEqual(m.call_args[1]["level"], logging.WARN)

        # Given
        args = ["foo", "-v"]

        # When
        with mock.patch("enstaller.logging.basicConfig") as m:
            main(args)

        # Then
        m.assert_called()
        self.assertEqual(m.call_args[1]["level"], logging.INFO)

        # Given
        args = ["foo", "-vv"]

        # When
        with mock.patch("enstaller.main.http_client.HTTPConnection") \
                as fake_connection:
            with mock.patch("enstaller.logging.basicConfig") as m:
                main(args)

        # Then
        fake_connection.assert_not_called()

        m.assert_called()
        self.assertEqual(m.call_args[1]["level"], logging.DEBUG)

        # Given
        args = ["foo", "-vvv"]

        # When
        with mock.patch("enstaller.main.http_client.HTTPConnection") \
                as fake_connection:
            with mock.patch("enstaller.logging.basicConfig") as m:
                main(args)

        # Then
        fake_connection.assert_called()
        self.assertEqual(fake_connection.debuglevel, 1)

        m.assert_called()
        self.assertEqual(m.call_args[1]["level"], logging.DEBUG)
Esempio n. 23
0
    def test_quiet(self, install_req):
        # Given
        args = ["foo"]

        # When
        with mock.patch("sys.stdout", new=StringIO()) as m:
            main(args)

        # Then
        self.assertNotEqual(m.getvalue(), "")

        # Given
        args = ["foo", "--quiet"]

        # When
        with mock.patch("sys.stdout", new=StringIO()) as m:
            main(args)

        # Then
        self.assertEqual(m.getvalue(), "")
Esempio n. 24
0
    def test_simple(self):
        # Given
        path = os.path.join(self.prefix, "enstaller.yaml")
        responses.add(responses.POST,
                      "http://acme.com/api/v0/json/auth/tokens/auth",
                      body=json.dumps({"token": "dummy token"}))

        with open(path, "wt") as fp:
            fp.write(
                textwrap.dedent("""\
                    store_url: "http://acme.com"
                    authentication:
                      kind: "simple"
                      username: "******"
                      password: "******"
            """))

        # When
        # Then No exception
        main(["-s", "numpy", "-c", path])
Esempio n. 25
0
    def test_quiet(self, install_req):
        # Given
        args = ["foo"]

        # When
        with mock.patch("sys.stdout", new=StringIO()) as m:
            main(args)

        # Then
        self.assertNotEqual(m.getvalue(), "")

        # Given
        args = ["foo", "--quiet"]

        # When
        with mock.patch("sys.stdout", new=StringIO()) as m:
            main(args)

        # Then
        self.assertEqual(m.getvalue(), "")
Esempio n. 26
0
    def test_enpkg_req_with_valid_auth(self):
        """
        Ensure 'enpkg req' authenticate as expected
        """
        with open(self.config, "w") as fp:
            fp.write("EPD_auth = '{0}'".format(FAKE_CREDS))

        json_data = {
            "is_authenticated": True,
            "first_name": "nono",
            "last_name": "le petit robot",
            "has_subscription": True,
            "subscription_level": "free"
        }
        responses.add(responses.GET,
                      "https://api.enthought.com/accounts/user/info/",
                      body=json.dumps(json_data),
                      status=200,
                      content_type='application/json')

        with use_given_config_context(self.config):
            main(["nono"])
Esempio n. 27
0
    def test_no_autoupdate(self, install_req):
        # Given
        args = ["foo"]

        # When
        with mock.patch("enstaller.main.update_enstaller") as m:
            main(args)

        # Then
        self.assertTrue(m.called)

        # Given
        args = ["--no-autoupdate", "foo"]

        # When
        with mock.patch("enstaller.main.update_enstaller") as m:
            main(args)

        # Then
        self.assertFalse(m.called)

        # Given
        args = ["foo"]

        config = Configuration()
        config.update(autoupdate=False, auth=("dummy", "dummy"))

        mock_config = mock.Mock()
        mock_config.return_value = config
        mock_config.from_file.return_value = config

        # When
        with mock.patch("enstaller.main.Configuration", mock_config):
            with mock.patch("enstaller.main.update_enstaller") as m:
                main(args)

        # Then
        self.assertFalse(m.called)
Esempio n. 28
0
 def test_install_epd(self):
     with mock.patch("enstaller.main.epd_install_confirm") as m:
         main(["epd"])
     self.assertTrue(m.called)
Esempio n. 29
0
 def test_install_numpy(self):
     main(["numpy"])
Esempio n. 30
0
 def test_updated_enstaller_in_req(self):
     with mock_print() as m:
         with mock.patch("enstaller.main.install_req"):
             main(["enstaller"])
     self.assertMultiLineEqual(m.value, "")
Esempio n. 31
0
 def test_updated_enstaller(self, logger):
     with mock.patch("enstaller.main.install_req"):
         main([""])
     logger.info.assert_called_with('prefix: %r',
                                    os.path.normpath(sys.prefix))
Esempio n. 32
0
#!"C:\Program Files (x86)\IronPython 2.7\ipy.exe"
# This script was created by egginst when installing:
#
#   ironpkg-1.0.0-1.egg
#
if __name__ == '__main__':
    import sys
    from enstaller.main import main

    sys.exit(main())
Esempio n. 33
0
 def test_remove(self):
     with mock.patch("enstaller.main.Enpkg.execute"):
         main(["--remove", "numpy"])
Esempio n. 34
0
 def test_install_epd_and_other(self):
     with mock.patch("enstaller.main.epd_install_confirm"):
         with mock.patch("enstaller.main.install_req"):
             with self.assertRaises(SystemExit) as e:
                 main(["epd", "numpy"])
             self.assertNotEqual(exception_code(e), 0)
Esempio n. 35
0
 def test_remove_epd_fails(self):
     with mock.patch("enstaller.main.epd_install_confirm"):
         with mock.patch("enstaller.main.install_req"):
             with self.assertRaises(SystemExit) as e:
                 main(["--remove", "epd"])
                 self.assertNotEqual(exception_code(e), 0)
Esempio n. 36
0
 def test_help_runs_and_exits_correctly(self):
     try:
         main(["--help"])
     except SystemExit as e:
         self.assertEqual(e.code, 0)
Esempio n. 37
0
 def test_print_env(self):
     try:
         main(["--env"])
     except SystemExit as e:
         self.assertEqual(e.code, 0)