def note_content(): content = StringIO() view = NoteForHiddenView(content) view.assign("args", self.args.args) view.assign("total_count", len(self.args.applications)) view.assign("session_count", self.args.applications.count_type(Applications.TYPES["SESSION"])) view.assign("static_count", self.args.applications.count_type(Applications.TYPES["STATIC"])) view.render() return content.getvalue() if version_info.major >= 3 else content.getvalue().decode("utf8")
def setUp(self): self.out = StringIO()
class TestViews(unittest.TestCase): def setUp(self): self.out = StringIO() def test_default_none(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign("applications", ApplicationsCollection([])) view.render() self.assertEquals(self.out.getvalue(), "") def test_default_with_helpers(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign( "applications", ApplicationsCollection([ Application({ "type": "application", "helper": "first helper", "name": None }), Application({ "type": "application", "helper": "second helper", "name": None }), Application({ "type": "application", "helper": "third helper", "name": None }), ])) view.render() self.assertEquals(self.out.getvalue(), ("You should restart:\n" " * Some applications using:\n" " first helper\n" " second helper\n" " third helper\n")) def test_default_without_helpers(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign( "applications", ApplicationsCollection([ Application({ "type": "application", "name": "foo", "helper": None }), Application({ "type": "application", "name": "bar", "helper": None }), Application({ "type": "application", "name": "baz", "helper": None }), ])) view.render() self.assertEquals(self.out.getvalue(), ("You should restart:\n" " * These applications manually:\n" " bar\n" " baz\n" " foo\n")) def test_default_with_without_helpers(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign( "applications", ApplicationsCollection([ Application({ "type": "application", "helper": "first helper", "name": None }), Application({ "type": "application", "helper": "second helper", "name": None }), Application({ "type": "application", "helper": "third helper", "name": None }), Application({ "type": "application", "name": "foo", "helper": None }), Application({ "type": "application", "name": "bar", "helper": None }), Application({ "type": "application", "name": "baz", "helper": None }), ])) view.render() self.assertEquals(self.out.getvalue(), ("You should restart:\n" " * Some applications using:\n" " first helper\n" " second helper\n" " third helper\n" "\n" " * These applications manually:\n" " bar\n" " baz\n" " foo\n")) def test_default_all_session(self): view = DefaultView(self.out) view.assign("args", ArgsMock(all=True)) view.assign( "applications", ApplicationsCollection([ Application({ "type": "session", "name": "foo", "helper": "h1" }), Application({ "type": "session", "name": "bar", "helper": "h2" }), Application({ "type": "session", "name": "baz", "helper": "h3" }), ])) view.render() self.assertEquals(self.out.getvalue(), ("You should restart:\n" " * These applications restarting your session:\n" " bar\n" " baz\n" " foo\n")) def test_default_all_static(self): view = DefaultView(self.out) view.assign("args", ArgsMock(all=True)) view.assign( "applications", ApplicationsCollection([ Application({ "type": "static", "name": "foo", "helper": "h1" }), Application({ "type": "static", "name": "bar", "helper": "h2" }), Application({ "type": "static", "name": "baz", "helper": "h3" }), ])) view.render() self.assertEquals(self.out.getvalue(), ("You should restart:\n" " * These applications rebooting your computer:\n" " bar\n" " baz\n" " foo\n")) def test_default_all_session_static(self): view = DefaultView(self.out) view.assign("args", ArgsMock(all=True)) view.assign( "applications", ApplicationsCollection([ Application({ "type": "session", "name": "foo", "helper": "h1" }), Application({ "type": "session", "name": "bar", "helper": "h2" }), Application({ "type": "session", "name": "baz", "helper": "h3" }), Application({ "type": "static", "name": "aaa", "helper": "h4" }), Application({ "type": "static", "name": "bbb", "helper": "h5" }), Application({ "type": "static", "name": "ccc", "helper": "h6" }), ])) view.render() self.assertEquals(self.out.getvalue(), ("You should restart:\n" " * These applications restarting your session:\n" " bar\n" " baz\n" " foo\n" "\n" " * These applications rebooting your computer:\n" " aaa\n" " bbb\n" " ccc\n")) def test_default_all(self): view = DefaultView(self.out) view.assign("args", ArgsMock(all=True)) view.assign( "applications", ApplicationsCollection([ Application({ "type": "application", "helper": "first helper", "name": None }), Application({ "type": "application", "helper": "second helper", "name": None }), Application({ "type": "application", "name": "foo", "helper": None }), Application({ "type": "application", "name": "bar", "helper": None }), Application({ "type": "session", "name": "baz", "helper": "h1" }), Application({ "type": "session", "name": "qux", "helper": "h2" }), Application({ "type": "static", "name": "aaa", "helper": "h3" }), Application({ "type": "static", "name": "bbb", "helper": "h4" }), ])) view.render() self.assertEquals(self.out.getvalue(), ("You should restart:\n" " * Some applications using:\n" " first helper\n" " second helper\n" "\n" " * These applications manually:\n" " bar\n" " foo\n" "\n" " * These applications restarting your session:\n" " baz\n" " qux\n" "\n" " * These applications rebooting your computer:\n" " aaa\n" " bbb\n")) def test_default_not_all(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign( "applications", ApplicationsCollection([ Application({ "type": "application", "helper": "first helper", "name": None }), Application({ "type": "application", "helper": "second helper", "name": None }), Application({ "type": "application", "name": "foo", "helper": None }), Application({ "type": "application", "name": "bar", "helper": None }), Application({ "type": "session", "name": "baz", "helper": "h1" }), Application({ "type": "session", "name": "qux", "helper": "h2" }), Application({ "type": "static", "name": "aaa", "helper": "h3" }), ])) view.render() self.assertEquals(self.out.getvalue(), ( "You should restart:\n" " * Some applications using:\n" " first helper\n" " second helper\n" "\n" " * These applications manually:\n" " bar\n" " foo\n" "\n" "Additionally to those process above, there are:\n" " - 2 processes requiring restart of your session (i.e. Logging out & Logging in again)\n" " - 1 processes requiring reboot\n")) def test_default_note_only(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign( "applications", ApplicationsCollection([ Application({ "type": "session", "name": "foo", "helper": "h1" }), Application({ "type": "session", "name": "bar", "helper": "h2" }), Application({ "type": "static", "name": "baz", "helper": "h3" }), ])) view.render() self.assertEquals(self.out.getvalue(), ( "You should restart:\n" "There are:\n" " - 2 processes requiring restart of your session (i.e. Logging out & Logging in again)\n" " - 1 processes requiring reboot\n")) def test_helper(self): processes = [ ProcessMock(2, "foo", 1234, ["file1", "file2"]), ProcessMock(3, "foo", 5678, ["file2", "file3"]), ] package = Package("foopackage") package.modified = None package.description = "Foo package description" package.category = "categ" package.files = ["file1", "file2"] a1 = AffectedProcessMock(2) a1.packages = set([package]) affected_by = [a1] view = HelperView(self.out) view.assign("args", ArgsMock(verbose=2)) view.assign("processes", processes) view.assign("application", Applications.find("foo")) view.assign("package", package) view.assign("affected_by", affected_by) view.assign("affects", None) view.render() self.assertEquals(self.out.getvalue(), ( "* foo\n" " Package: foopackage\n" " Description: Foo package description\n" " Type: Application\n" " State: foo has been started by None some-time ago. PID - 2\n" " foo has been started by None some-time ago. PID - 3\n" "\n" " Affected by:\n" " foopackage\n" " file1\n" " file2\n"))
class TestViews(unittest.TestCase): def setUp(self): self.out = StringIO() def test_default_none(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign("applications", ApplicationsCollection([])) view.render() self.assertEquals(self.out.getvalue(), "") def test_default_with_helpers(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign("applications", ApplicationsCollection([ Application({"type": "application", "helper": "first helper", "name": None}), Application({"type": "application", "helper": "second helper", "name": None}), Application({"type": "application", "helper": "third helper", "name": None}), ])) view.render() self.assertEquals(self.out.getvalue(), ( "You should restart:\n" " * Some applications using:\n" " first helper\n" " second helper\n" " third helper\n" )) def test_default_without_helpers(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign("applications", ApplicationsCollection([ Application({"type": "application", "name": "foo", "helper": None}), Application({"type": "application", "name": "bar", "helper": None}), Application({"type": "application", "name": "baz", "helper": None}), ])) view.render() self.assertEquals(self.out.getvalue(), ( "You should restart:\n" " * These applications manually:\n" " bar\n" " baz\n" " foo\n" )) def test_default_with_without_helpers(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign("applications", ApplicationsCollection([ Application({"type": "application", "helper": "first helper", "name": None}), Application({"type": "application", "helper": "second helper", "name": None}), Application({"type": "application", "helper": "third helper", "name": None}), Application({"type": "application", "name": "foo", "helper": None}), Application({"type": "application", "name": "bar", "helper": None}), Application({"type": "application", "name": "baz", "helper": None}), ])) view.render() self.assertEquals(self.out.getvalue(), ( "You should restart:\n" " * Some applications using:\n" " first helper\n" " second helper\n" " third helper\n" "\n" " * These applications manually:\n" " bar\n" " baz\n" " foo\n" )) def test_default_all_session(self): view = DefaultView(self.out) view.assign("args", ArgsMock(all=True)) view.assign("applications", ApplicationsCollection([ Application({"type": "session", "name": "foo", "helper": "h1"}), Application({"type": "session", "name": "bar", "helper": "h2"}), Application({"type": "session", "name": "baz", "helper": "h3"}), ])) view.render() self.assertEquals(self.out.getvalue(), ( "You should restart:\n" " * These applications restarting your session:\n" " bar\n" " baz\n" " foo\n" )) def test_default_all_static(self): view = DefaultView(self.out) view.assign("args", ArgsMock(all=True)) view.assign("applications", ApplicationsCollection([ Application({"type": "static", "name": "foo", "helper": "h1"}), Application({"type": "static", "name": "bar", "helper": "h2"}), Application({"type": "static", "name": "baz", "helper": "h3"}), ])) view.render() self.assertEquals(self.out.getvalue(), ( "You should restart:\n" " * These applications rebooting your computer:\n" " bar\n" " baz\n" " foo\n" )) def test_default_all_session_static(self): view = DefaultView(self.out) view.assign("args", ArgsMock(all=True)) view.assign("applications", ApplicationsCollection([ Application({"type": "session", "name": "foo", "helper": "h1"}), Application({"type": "session", "name": "bar", "helper": "h2"}), Application({"type": "session", "name": "baz", "helper": "h3"}), Application({"type": "static", "name": "aaa", "helper": "h4"}), Application({"type": "static", "name": "bbb", "helper": "h5"}), Application({"type": "static", "name": "ccc", "helper": "h6"}), ])) view.render() self.assertEquals(self.out.getvalue(), ( "You should restart:\n" " * These applications restarting your session:\n" " bar\n" " baz\n" " foo\n" "\n" " * These applications rebooting your computer:\n" " aaa\n" " bbb\n" " ccc\n" )) def test_default_all(self): view = DefaultView(self.out) view.assign("args", ArgsMock(all=True)) view.assign("applications", ApplicationsCollection([ Application({"type": "application", "helper": "first helper", "name": None}), Application({"type": "application", "helper": "second helper", "name": None}), Application({"type": "application", "name": "foo", "helper": None}), Application({"type": "application", "name": "bar", "helper": None}), Application({"type": "session", "name": "baz", "helper": "h1"}), Application({"type": "session", "name": "qux", "helper": "h2"}), Application({"type": "static", "name": "aaa", "helper": "h3"}), Application({"type": "static", "name": "bbb", "helper": "h4"}), ])) view.render() self.assertEquals(self.out.getvalue(), ( "You should restart:\n" " * Some applications using:\n" " first helper\n" " second helper\n" "\n" " * These applications manually:\n" " bar\n" " foo\n" "\n" " * These applications restarting your session:\n" " baz\n" " qux\n" "\n" " * These applications rebooting your computer:\n" " aaa\n" " bbb\n" )) def test_default_not_all(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign("applications", ApplicationsCollection([ Application({"type": "application", "helper": "first helper", "name": None}), Application({"type": "application", "helper": "second helper", "name": None}), Application({"type": "application", "name": "foo", "helper": None}), Application({"type": "application", "name": "bar", "helper": None}), Application({"type": "session", "name": "baz", "helper": "h1"}), Application({"type": "session", "name": "qux", "helper": "h2"}), Application({"type": "static", "name": "aaa", "helper": "h3"}), ])) view.render() self.assertEquals(self.out.getvalue(), ( "You should restart:\n" " * Some applications using:\n" " first helper\n" " second helper\n" "\n" " * These applications manually:\n" " bar\n" " foo\n" "\n" "Additionally to those process above, there are:\n" " - 2 processes requiring restart of your session (i.e. Logging out & Logging in again)\n" " - 1 processes requiring reboot\n" )) def test_default_note_only(self): view = DefaultView(self.out) view.assign("args", ArgsMock()) view.assign("applications", ApplicationsCollection([ Application({"type": "session", "name": "foo", "helper": "h1"}), Application({"type": "session", "name": "bar", "helper": "h2"}), Application({"type": "static", "name": "baz", "helper": "h3"}), ])) view.render() self.assertEquals(self.out.getvalue(), ( "You should restart:\n" "There are:\n" " - 2 processes requiring restart of your session (i.e. Logging out & Logging in again)\n" " - 1 processes requiring reboot\n" )) def test_helper(self): processes = [ ProcessMock(2, "foo", 1234, ["file1", "file2"]), ProcessMock(3, "foo", 5678, ["file2", "file3"]), ] package = Package("foopackage") package.modified = None package.description = "Foo package description" package.category = "categ" package.files = ["file1", "file2"] a1 = AffectedProcessMock(2) a1.packages = set([package]) affected_by = [a1] view = HelperView(self.out) view.assign("args", ArgsMock(verbose=2)) view.assign("processes", processes) view.assign("application", Applications.find("foo")) view.assign("package", package) view.assign("affected_by", affected_by) view.assign("affects", None) view.render() self.assertEquals(self.out.getvalue(), ( "* foo\n" " Package: foopackage\n" " Description: Foo package description\n" " Type: Application\n" " State: foo has been started by None some-time ago. PID - 2\n" " foo has been started by None some-time ago. PID - 3\n" "\n" " Affected by:\n" " foopackage\n" " file1\n" " file2\n" ))