Esempio n. 1
0
 def test_parse_simple_unsupported_entry(self):
     # XXX: ideally, we would like something like with self.assertWarns to
     # check for the warning, but backporting the python 3.3 code to
     # unittest2 is a bit painful.
     with mock.patch("enstaller.config.warnings.warn") as m:
         Configuration.from_file(StringIO("nono = 'le petit robot'"))
         m.assert_called_with('Unsupported configuration setting nono, ignored')
Esempio n. 2
0
    def test_max_retries_setup(self):
        # When
        config = Configuration()

        # Then
        self.assertEqual(config.max_retries, 0)

        # Given
        data = StringIO("max_retries = 1")

        # When
        config = Configuration.from_file(data)

        # Then
        self.assertEqual(config.max_retries, 1)

        # Given
        data = StringIO("max_retries = 0")

        # When
        config = Configuration.from_file(data)

        # Then
        self.assertEqual(config.max_retries, 0)

        # Given
        data = StringIO("max_retries = 'a'")

        # When/Then
        with self.assertRaises(InvalidConfiguration):
            Configuration.from_file(data)
Esempio n. 3
0
    def test_max_retries_setup(self):
        # When
        config = Configuration()

        # Then
        self.assertEqual(config.max_retries, 0)

        # Given
        data = StringIO("max_retries = 1")

        # When
        config = Configuration.from_file(data)

        # Then
        self.assertEqual(config.max_retries, 1)

        # Given
        data = StringIO("max_retries = 0")

        # When
        config = Configuration.from_file(data)

        # Then
        self.assertEqual(config.max_retries, 0)

        # Given
        data = StringIO("max_retries = 'a'")

        # When/Then
        with self.assertRaises(InvalidConfiguration):
            Configuration.from_file(data)
Esempio n. 4
0
 def test_parse_simple_unsupported_entry(self):
     # XXX: ideally, we would like something like with self.assertWarns to
     # check for the warning, but backporting the python 3.3 code to
     # unittest2 is a bit painful.
     with mock.patch("enstaller.config.warnings.warn") as m:
         Configuration.from_file(StringIO("nono = 'le petit robot'"))
         m.assert_called_with(
             'Unsupported configuration setting nono, ignored')
Esempio n. 5
0
    def test_both_auth_set(self):
        # Given
        data = "EPD_auth = '{0}'\napi_token = 'token'"
        data = StringIO(data.format(FAKE_CREDS))

        msg = "Both 'EPD_auth' and 'api_token' set in configuration." \
              "\nYou should remove one of those for consistent " \
              "behaviour."

        # When
        with self.assertWarnsRegex(Warning, msg):
            Configuration.from_file(data)
Esempio n. 6
0
    def test_change_existing_config_file_empty_username(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("EPD_auth = '{0}'".format(FAKE_CREDS))

        config = Configuration.from_file(fp.name)
        self.assertEqual(config.auth, FAKE_AUTH)

        config.reset_auth()
        config._change_auth(fp.name)

        new_config = Configuration.from_file(fp.name)
        self.assertIsNone(new_config.auth)
Esempio n. 7
0
    def test_change_existing_config_file_empty_username(self):
        with tempfile.NamedTemporaryFile(delete=False) as fp:
            fp.write("EPD_auth = '{0}'".format(FAKE_CREDS))

        config = Configuration.from_file(fp.name)
        self.assertEqual(config.get_auth(), (FAKE_USER, FAKE_PASSWORD))

        config.reset_auth()
        config._change_auth(fp.name)

        new_config = Configuration.from_file(fp.name)
        self.assertEqual(new_config.get_auth(), (None, None))
Esempio n. 8
0
    def test_change_existing_config_file_empty_username(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("EPD_auth = '{0}'".format(FAKE_CREDS))

        config = Configuration.from_file(fp.name)
        self.assertEqual(config.auth, FAKE_AUTH)

        config.reset_auth()
        config._change_auth(fp.name)

        new_config = Configuration.from_file(fp.name)
        self.assertIsNone(new_config.auth)
Esempio n. 9
0
    def test_both_auth_set(self):
        # Given
        data = "EPD_auth = '{0}'\napi_token = 'token'"
        data = StringIO(data.format(FAKE_CREDS))

        msg = "Both 'EPD_auth' and 'api_token' set in configuration." \
              "\nYou should remove one of those for consistent " \
              "behaviour."

        # When
        with self.assertWarnsRegex(Warning, msg):
            Configuration.from_file(data)
Esempio n. 10
0
    def test_change_existing_config_file(self):
        r_new_password = "******"
        with tempfile.NamedTemporaryFile(delete=False) as fp:
            fp.write("EPD_auth = '{0}'".format(FAKE_CREDS))

        config = Configuration.from_file(fp.name)
        self.assertEqual(config.get_auth(), (FAKE_USER, FAKE_PASSWORD))

        config.set_auth(FAKE_USER, r_new_password)
        config._change_auth(fp.name)
        new_config = Configuration.from_file(fp.name)

        self.assertEqual(new_config.get_auth(), (FAKE_USER, r_new_password))
Esempio n. 11
0
    def test_invalid_syntax(self):
        # Given
        data = "store_url = http://acme.com"
        r_message = "Could not parse configuration file (invalid python " \
                    "syntax at line 1: expression 'store_url = " \
                    "http://acme.com')"

        # When
        with self.assertRaises(InvalidConfiguration) as e:
            Configuration.from_file(StringIO(data))

        # Then
        self.assertMultiLineEqual(str(e.exception), r_message)
Esempio n. 12
0
    def test_invalid_syntax(self):
        # Given
        data = "store_url = http://acme.com"
        r_message = "Could not parse configuration file (invalid python " \
                    "syntax at line 1: expression 'store_url = " \
                    "http://acme.com')"

        # When
        with self.assertRaises(InvalidConfiguration) as e:
            Configuration.from_file(StringIO(data))

        # Then
        self.assertMultiLineEqual(str(e.exception), r_message)
Esempio n. 13
0
    def test_change_existing_config_file(self):
        r_new_password = "******"
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("EPD_auth = '{0}'".format(FAKE_CREDS))

        config = Configuration.from_file(fp.name)
        self.assertEqual(config.auth, FAKE_AUTH)

        config.update(auth=(FAKE_USER, r_new_password))
        config._change_auth(fp.name)
        new_config = Configuration.from_file(fp.name)

        self.assertEqual(new_config.auth,
                         UserPasswordAuth(FAKE_USER, r_new_password))
Esempio n. 14
0
    def test_change_existing_config_file(self):
        r_new_password = "******"
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("EPD_auth = '{0}'".format(FAKE_CREDS))

        config = Configuration.from_file(fp.name)
        self.assertEqual(config.auth, FAKE_AUTH)

        config.update(auth=(FAKE_USER, r_new_password))
        config._change_auth(fp.name)
        new_config = Configuration.from_file(fp.name)

        self.assertEqual(new_config.auth,
                         UserPasswordAuth(FAKE_USER, r_new_password))
Esempio n. 15
0
    def test_unsupported_syntax(self):
        # Given
        data = textwrap.dedent("""\
        store_url = 'http://acme'
        store_url += '.com'
        """)
        r_message = "Could not parse configuration file (error at line 2: " \
            "expression \"store_url += '.com'\" not supported)"

        # When
        with self.assertRaises(InvalidConfiguration) as e:
            Configuration.from_file(StringIO(data))

        # Then
        self.assertMultiLineEqual(str(e.exception), r_message)
Esempio n. 16
0
    def test_unsupported_syntax(self):
        # Given
        data = textwrap.dedent("""\
        store_url = 'http://acme'
        store_url += '.com'
        """)
        r_message = "Could not parse configuration file (error at line 2: " \
            "expression \"store_url += '.com'\" not supported)"

        # When
        with self.assertRaises(InvalidConfiguration) as e:
            Configuration.from_file(StringIO(data))

        # Then
        self.assertMultiLineEqual(str(e.exception), r_message)
Esempio n. 17
0
    def test_with_configuration_no_keyring(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            auth_line = "EPD_auth = '{0}'".format(FAKE_CREDS)
            fp.write(auth_line)

        config = Configuration.from_file(fp.name)
        self.assertIsNotNone(config.auth)
Esempio n. 18
0
    def test_from_file_complete_combination2(self):
        # Given
        if sys.platform == "win32":
            r_prefix = "C:\\tmp"
        else:
            r_prefix = "/tmp"
        r_repository_cache = r_prefix
        fp = StringIO(
            textwrap.dedent("""\
        EPD_auth = "{creds}"

        repository_cache = {prefix!r}
        prefix = {prefix!r}
        use_webservice = False

        store_url = "http://acme.com"
        use_pypi = True
        autoupdate = True
        noapp = True
        """.format(creds=FAKE_CREDS, prefix=r_prefix)))

        # When
        config = Configuration.from_file(fp)

        # Then
        self.assertEqual(config.auth, FAKE_AUTH)
        self.assertSamePath(config.repository_cache, r_repository_cache)
        self.assertSamePath(config.prefix, r_prefix)
        self.assertEqual(config.use_webservice, False)
        self.assertEqual(config.store_url, "http://acme.com")
        self.assertEqual(config.use_pypi, True)
        self.assertEqual(config.autoupdate, True)
        self.assertEqual(config.noapp, True)
Esempio n. 19
0
    def test_without_configuration_with_keyring(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("")

        with mock.patch("enstaller.config.keyring"):
            config = Configuration.from_file(fp.name)
            self.assertIsNone(config.auth)
Esempio n. 20
0
    def test_simple(self):
        output_template = textwrap.dedent("""\
            Python version: {pyver}
            enstaller version: {version}
            sys.prefix: {sys_prefix}
            platform: {platform}
            architecture: {arch}
            use_webservice: True
            config file: {{config_file}}
            settings:
                prefix = {{prefix}}
                local = {{local}}
                noapp = False
                proxy = None
                IndexedRepos: (not used)
            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])

        try:
            with tempfile.NamedTemporaryFile(delete=False) as fp:
                fp.write("")
            config = Configuration.from_file(fp.name)
        finally:
            os.unlink(fp.name)

        prefix = config.prefix
        local = os.path.join(prefix, "LOCAL-REPO")
        r_output = output_template.format(prefix=prefix, config_file=fp.name, local=local)

        with mock_print() as m:
            print_config(config, None, config.prefix)
            self.assertMultiLineEqual(m.value, r_output)
Esempio n. 21
0
    def test_without_configuration_with_keyring(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("")

        with mock.patch("enstaller.config.keyring"):
            config = Configuration.from_file(fp.name)
            self.assertIsNone(config.auth)
Esempio n. 22
0
    def test_from_file_complete_combination2(self):
        # Given
        if sys.platform == "win32":
            r_prefix = "C:\\tmp"
        else:
            r_prefix = "/tmp"
        r_repository_cache = r_prefix
        fp = StringIO(textwrap.dedent("""\
        EPD_auth = "{creds}"

        repository_cache = {prefix!r}
        prefix = {prefix!r}
        use_webservice = False

        store_url = "http://acme.com"
        use_pypi = True
        autoupdate = True
        noapp = True
        """.format(creds=FAKE_CREDS, prefix=r_prefix)))

        # When
        config = Configuration.from_file(fp)

        # Then
        self.assertEqual(config.auth, FAKE_AUTH)
        self.assertSamePath(config.repository_cache, r_repository_cache)
        self.assertSamePath(config.prefix, r_prefix)
        self.assertEqual(config.use_webservice, False)
        self.assertEqual(config.store_url, "http://acme.com")
        self.assertEqual(config.use_pypi, True)
        self.assertEqual(config.autoupdate, True)
        self.assertEqual(config.noapp, True)
Esempio n. 23
0
    def test_with_configuration_no_keyring(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            auth_line = "EPD_auth = '{0}'".format(FAKE_CREDS)
            fp.write(auth_line)

        config = Configuration.from_file(fp.name)
        self.assertIsNotNone(config.auth)
Esempio n. 24
0
    def test_change_existing_config_file_without_keyring(self):
        # Given
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("EPD_auth = '{0}'".format(FAKE_CREDS))

        # When
        config = Configuration.from_file(fp.name)
        config.update(auth=("user", "dummy"))
        config._change_auth(fp.name)

        # Then
        with open(fp.name, "r") as f:
            content = f.read()
            self.assertNotRegex(content, "EPD_username")
            self.assertRegex(content, "EPD_auth")
        config = Configuration.from_file(fp.name)
        self.assertEqual(config.auth, UserPasswordAuth("user", "dummy"))
Esempio n. 25
0
    def test_change_existing_config_file_without_keyring(self):
        # Given
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("EPD_auth = '{0}'".format(FAKE_CREDS))

        # When
        config = Configuration.from_file(fp.name)
        config.update(auth=("user", "dummy"))
        config._change_auth(fp.name)

        # Then
        with open(fp.name, "r") as f:
            content = f.read()
            self.assertNotRegex(content, "EPD_username")
            self.assertRegex(content, "EPD_auth")
        config = Configuration.from_file(fp.name)
        self.assertEqual(config.auth, UserPasswordAuth("user", "dummy"))
Esempio n. 26
0
    def test_epd_auth(self):
        """
        Ensure config auth information is properly set-up when using EPD_auth
        """
        s = StringIO("EPD_auth = '{0}'".format(FAKE_CREDS))
        config = Configuration.from_file(s)

        self.assertEqual(config.auth, FAKE_AUTH)
Esempio n. 27
0
    def test_epd_auth(self):
        """
        Ensure config auth information is properly set-up when using EPD_auth
        """
        s = StringIO("EPD_auth = '{0}'".format(FAKE_CREDS))
        config = Configuration.from_file(s)

        self.assertEqual(config.auth, FAKE_AUTH)
Esempio n. 28
0
    def test_change_empty_config_file_empty_username(self):
        with tempfile.NamedTemporaryFile(delete=False) as fp:
            fp.write("")

        config = Configuration.from_file(fp.name)
        self.assertEqual(config.get_auth(), (None, None))

        config.set_auth(FAKE_USER, FAKE_PASSWORD)
        self.assertEqual(config.get_auth(), (FAKE_USER, FAKE_PASSWORD))
Esempio n. 29
0
    def test_epd_username_with_keyring(self, mocked_keyring):
        mocked_keyring.get_password = lambda service, username: FAKE_PASSWORD

        s = StringIO("EPD_username = '******'".format(FAKE_USER))
        config = Configuration.from_file(s)

        self.assertTrue(config.use_keyring)
        self.assertEqual(config.EPD_username, FAKE_USER)
        self.assertEqual(config.EPD_auth, FAKE_CREDS)
Esempio n. 30
0
    def test_with_configuration_with_keyring(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            auth_line = "EPD_username = '******'".format(FAKE_USER)
            fp.write(auth_line)

        mocked_keyring = mock.Mock(["get_password"])
        with mock.patch("enstaller.config.keyring", mocked_keyring):
            config = Configuration.from_file(fp.name)
            self.assertIsNotNone(config.auth)
Esempio n. 31
0
    def test_epd_username(self):
        with fake_keyring_context() as mocked_keyring:
            mocked_keyring.set_password(KEYRING_SERVICE_NAME, FAKE_USER, FAKE_PASSWORD)

            s = StringIO("EPD_username = '******'".format(FAKE_USER))
            config = Configuration.from_file(s)

            self.assertEqual(config.auth, FAKE_AUTH)
            self.assertEqual(config.auth._encoded_auth, FAKE_CREDS)
Esempio n. 32
0
    def test_with_configuration_with_keyring(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            auth_line = "EPD_username = '******'".format(FAKE_USER)
            fp.write(auth_line)

        mocked_keyring = mock.Mock(["get_password"])
        with mock.patch("enstaller.config.keyring", mocked_keyring):
            config = Configuration.from_file(fp.name)
            self.assertIsNotNone(config.auth)
Esempio n. 33
0
    def test_epd_username_wo_keyring(self):
        """
        Ensure config auth correctly reports itself as non configured when
        using EPD_username but keyring is not available to get password.
        """
        s = StringIO("EPD_username = '******'".format(FAKE_USER))

        config = Configuration.from_file(s)
        self.assertIsNone(config.auth)
Esempio n. 34
0
    def test_simple_with_proxy(self):
        proxystr = "http://acme.com:3128"

        config = Configuration()
        config.proxy = proxystr
        config.write(self.f)

        config = Configuration.from_file(self.f)
        self.assertEqual(config.proxy, proxystr)
Esempio n. 35
0
    def test_epd_username_wo_keyring(self):
        """
        Ensure config auth correctly reports itself as non configured when
        using EPD_username but keyring is not available to get password.
        """
        s = StringIO("EPD_username = '******'".format(FAKE_USER))

        config = Configuration.from_file(s)
        self.assertIsNone(config.auth)
Esempio n. 36
0
    def test_epd_auth_with_keyring(self, mocked_keyring):
        """
        Ensure config is properly setup in keyring mode when using EPD_auth
        """
        s = StringIO("EPD_auth = '{0}'".format(FAKE_CREDS))
        config = Configuration.from_file(s)

        self.assertTrue(config.use_keyring)
        self.assertEqual(config.EPD_username, FAKE_USER)
        self.assertEqual(config.EPD_auth, FAKE_CREDS)
Esempio n. 37
0
def _ensure_config_or_die():
    config_filename = _ensure_config_path()

    try:
        config = Configuration.from_file(config_filename)
    except InvalidConfiguration as e:
        print(str(e))
        sys.exit(EXIT_ABORTED)

    return config
Esempio n. 38
0
    def test_change_empty_config_file_empty_username(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("")

        config = Configuration.from_file(fp.name)
        self.assertIsNone(config.auth)

        config.update(auth=(FAKE_USER, FAKE_PASSWORD))
        self.assertEqual(config.auth,
                         UserPasswordAuth(FAKE_USER, FAKE_PASSWORD))
Esempio n. 39
0
    def test_store_kind(self):
        """
        Ensure config auth information is properly set-up when using EPD_auth
        """
        # Given
        config = Configuration()

        # When
        config.update(store_url="http://acme.com")

        # Then
        self.assertEqual(config.store_kind, "legacy")
        self.assertEqual(config.store_url, "http://acme.com")

        # Given
        config = Configuration()

        # When
        config.update(store_url="brood+http://acme.com")

        # Then
        self.assertEqual(config.store_kind, "brood")
        self.assertEqual(config.store_url, "http://acme.com")

        # Given
        s = StringIO("store_url = 'http://acme.com'")

        # When
        config = Configuration.from_file(s)

        # Then
        self.assertEqual(config.store_kind, "legacy")
        self.assertEqual(config.store_url, "http://acme.com")

        # Given
        s = StringIO("store_url = 'brood+http://acme.com'")

        # When
        config = Configuration.from_file(s)

        # Then
        self.assertEqual(config.store_kind, "brood")
        self.assertEqual(config.store_url, "http://acme.com")
Esempio n. 40
0
    def test_change_empty_config_file_empty_username(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("")

        config = Configuration.from_file(fp.name)
        self.assertIsNone(config.auth)

        config.update(auth=(FAKE_USER, FAKE_PASSWORD))
        self.assertEqual(config.auth, UserPasswordAuth(FAKE_USER,
                                                       FAKE_PASSWORD))
Esempio n. 41
0
    def test_simple_with_proxy(self):
        proxystr = "http://acme.com:3128"

        config = Configuration()
        config.update(proxy=proxystr)
        config.write(self.f)

        config = Configuration.from_file(self.f)
        self.assertEqual(str(config.proxy), proxystr)
        self.assertEqual(config.proxy_dict, {"http": proxystr})
Esempio n. 42
0
def _ensure_config_or_die():
    config_filename = _ensure_config_path()

    try:
        config = Configuration.from_file(config_filename)
    except InvalidConfiguration as e:
        print(str(e))
        sys.exit(EXIT_ABORTED)

    return config
Esempio n. 43
0
    def test_simple_with_proxy(self):
        proxystr = "http://acme.com:3128"

        config = Configuration()
        config.update(proxy=proxystr)
        config.write(self.f)

        config = Configuration.from_file(self.f)
        self.assertEqual(str(config.proxy), proxystr)
        self.assertEqual(config.proxy_dict, {"http": proxystr})
Esempio n. 44
0
    def test_store_kind(self):
        """
        Ensure config auth information is properly set-up when using EPD_auth
        """
        # Given
        config = Configuration()

        # When
        config.update(store_url="http://acme.com")

        # Then
        self.assertEqual(config.store_kind, "legacy")
        self.assertEqual(config.store_url, "http://acme.com")

        # Given
        config = Configuration()

        # When
        config.update(store_url="brood+http://acme.com")

        # Then
        self.assertEqual(config.store_kind, "brood")
        self.assertEqual(config.store_url, "http://acme.com")

        # Given
        s = StringIO("store_url = 'http://acme.com'")

        # When
        config = Configuration.from_file(s)

        # Then
        self.assertEqual(config.store_kind, "legacy")
        self.assertEqual(config.store_url, "http://acme.com")

        # Given
        s = StringIO("store_url = 'brood+http://acme.com'")

        # When
        config = Configuration.from_file(s)

        # Then
        self.assertEqual(config.store_kind, "brood")
        self.assertEqual(config.store_url, "http://acme.com")
Esempio n. 45
0
    def test_epd_username(self):
        with fake_keyring_context() as mocked_keyring:
            mocked_keyring.set_password(KEYRING_SERVICE_NAME, FAKE_USER,
                                        FAKE_PASSWORD)

            s = StringIO("EPD_username = '******'".format(FAKE_USER))
            config = Configuration.from_file(s)

            self.assertEqual(config.auth, FAKE_AUTH)
            self.assertEqual(config.auth._encoded_auth, FAKE_CREDS)
Esempio n. 46
0
    def test_change_config_file_empty_auth(self):
        config_data = "EPD_auth = '{0}'".format(FAKE_CREDS)
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write(config_data)

        config = Configuration.from_file(fp.name)
        config.update(auth=(None, None))
        config._change_auth(fp.name)

        with open(fp.name, "r") as fp:
            self.assertEqual(fp.read(), config_data)
Esempio n. 47
0
    def test_simple(self, mock1):
        config = Configuration()
        config.set_auth('usr', 'password')
        write_default_config(self.f)
        config._checked_change_auth(self.f)

        new_config = Configuration.from_file(self.f)
        usr = enstaller.config.authenticate(new_config)

        self.assertTrue(usr.get('is_authenticated'))
        self.assertTrue(usr.get('has_subscription'))
Esempio n. 48
0
    def test_epd_username_wo_keyring(self):
        """
        Ensure config auth correctly reports itself as non configured when
        using EPD_auth but keyring is not available to get password.
        """
        s = StringIO("EPD_username = '******'".format(FAKE_USER))

        config = Configuration.from_file(s)
        self.assertFalse(config.is_auth_configured)
        with self.assertRaises(InvalidConfiguration):
            config.EPD_auth
Esempio n. 49
0
    def test_change_config_file_empty_auth(self):
        config_data = "EPD_auth = '{0}'".format(FAKE_CREDS)
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write(config_data)

        config = Configuration.from_file(fp.name)
        config.update(auth=(None, None))
        config._change_auth(fp.name)

        with open(fp.name, "r") as fp:
            self.assertEqual(fp.read(), config_data)
Esempio n. 50
0
    def test_no_config_file(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("")

        config = Configuration()
        self.assertIsNone(config.auth)

        config.update(auth=(FAKE_USER, FAKE_PASSWORD))
        config.write(fp.name)

        new_config = Configuration.from_file(fp.name)
        self.assertEqual(new_config.auth, FAKE_AUTH)
Esempio n. 51
0
    def test_change_auth_wo_existing_auth(self):
        r_output = "EPD_auth = '{0}'\n".format(FAKE_CREDS)

        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("")

        config = Configuration.from_file(fp.name)
        config.update(auth=(FAKE_USER, FAKE_PASSWORD))
        config._change_auth(fp.name)

        with open(fp.name) as fp:
            self.assertMultiLineEqual(fp.read(), r_output)
Esempio n. 52
0
    def test_change_auth_wo_existing_auth(self):
        r_output = "EPD_auth = '{0}'\n".format(FAKE_CREDS)

        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("")

        config = Configuration.from_file(fp.name)
        config.update(auth=(FAKE_USER, FAKE_PASSWORD))
        config._change_auth(fp.name)

        with open(fp.name) as fp:
            self.assertMultiLineEqual(fp.read(), r_output)
Esempio n. 53
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. 54
0
    def test_change_store_url(self):
        config = Configuration()
        config.update(auth=(FAKE_USER, FAKE_PASSWORD))
        config.write(self.f)

        config = Configuration.from_file(self.f)
        config.update(store_url="https://acme.com")

        self.assertEqual(config.auth._encoded_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,
                         "https://acme.com/eggs/{0}/".format(custom_plat))
        self.assertEqual(config.api_url,
                         "https://acme.com/accounts/user/info/")
Esempio n. 55
0
    def test_api_token(self):
        # Given
        config = Configuration()

        # When
        config.update(auth=APITokenAuth("dummy token"))

        # Then
        self.assertEqual(config.auth, APITokenAuth("dummy token"))

        # Given
        data = StringIO("api_token = 'yoyo'")

        # When
        config = Configuration.from_file(data)

        # Then
        self.assertEqual(config.auth, APITokenAuth("yoyo"))
Esempio n. 56
0
    def test_simple(self):
        output_template = textwrap.dedent("""\
            Python version: {pyver}
            enstaller version: {version}
            sys.prefix: {sys_prefix}
            platform: {platform}
            architecture: {arch}
            use_webservice: True
            config file: {{config_file}}
            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())

        try:
            with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
                fp.write("")
            config = Configuration.from_file(fp.name)
        finally:
            os.unlink(fp.name)

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

        with mock_print() as m:
            print_config(config, config.prefix,
                         Session(DummyAuthenticator(), self.prefix))
            self.assertMultiLineEqual(m.value, r_output)
Esempio n. 57
0
    def test_epd_auth_wo_keyring(self):
        s = StringIO("EPD_auth = '{0}'".format(FAKE_CREDS))

        config = Configuration.from_file(s)
        self.assertEqual(config.auth, FAKE_AUTH)
Esempio n. 58
0
    def test_without_configuration_no_keyring(self):
        with tempfile.NamedTemporaryFile(delete=False, mode="wt") as fp:
            fp.write("")

        config = Configuration.from_file(fp.name)
        self.assertIsNone(config.auth)
Esempio n. 59
0
 def test_parse_simple_unsupported_entry(self):
     # XXX: ideally, we would like to check for the warning, but doing so is
     # a bit too painful as it has not been backported to unittest2
     Configuration.from_file(StringIO("nono = 'le petit robot'"))