Beispiel #1
0
    def test_pattern(self):
        config = Configuration()
        config.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_enpkg_entry_factory("dummy", "1.0.1", 1),
                       dummy_enpkg_entry_factory("dummy", "0.9.8", 1),
                       dummy_enpkg_entry_factory("another_package", "2.0.0", 1)]
            installed_entries = [dummy_installed_egg_factory("dummy", "1.0.1", 1)]
            enpkg = _create_prefix_with_eggs(config, d, installed_entries, entries)

            with mock_print() as m:
                search(enpkg, 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, pat=re.compile(".*"))
                self.assertMultiLineEqual(m.value, r_output)
Beispiel #2
0
    def test_not_available(self):
        config = Configuration()
        config.use_webservice = False

        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}
            """.format(""))
        another_entry = dummy_enpkg_entry_factory("another_package", "2.0.0", 1)
        another_entry.available = False

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

        with mock.patch("enstaller.main.subscription_message") as mocked_subscription_message:
            mocked_subscription_message.return_value = ""
            with mkdtemp() as d:
                with mock_print() as m:
                    enpkg = _create_prefix_with_eggs(config, d, remote_entries=entries)
                    search(enpkg)

                    self.assertMultiLineEqual(m.value, r_output)
                    self.assertTrue(mocked_subscription_message.called)
Beispiel #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})
Beispiel #4
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)
Beispiel #5
0
    def test_no_installed(self):
        config = Configuration()
        config.use_webservice = False

        with mkdtemp() as d:
            # XXX: isn't there a better way to ensure ws at the end of a line
            # are not eaten away ?
            r_output = textwrap.dedent("""\
                Name                   Versions           Product              Note
                ================================================================================
                another_dummy          2.0.0-1            commercial           {0}
                dummy                  0.9.8-1            commercial           {0}
                                       1.0.0-1            commercial           {0}
                """.format(""))
            entries = [dummy_enpkg_entry_factory("dummy", "1.0.0", 1),
                       dummy_enpkg_entry_factory("dummy", "0.9.8", 1),
                       dummy_enpkg_entry_factory("another_dummy", "2.0.0", 1)]
            enpkg = _create_prefix_with_eggs(config, d, remote_entries=entries)

            with mock_print() as m:
                search(enpkg)
                self.assertMultiLineEqual(m.value, r_output)