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_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_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_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_applications_sorted(self): default_type = Applications.DEFAULT_TYPE a1 = Application({'name': 'foo', 'helper': 'bar', 'type': default_type}) a2 = Application({'name': 'baz', 'helper': 'qux', 'type': default_type}) a3 = Application({'name': 'quux', 'helper': 'corge', 'type': default_type}) collection = ApplicationsCollection([a1, a2, a3]) self.assertEqual(collection.sorted('name'), ApplicationsCollection([a2, a1, a3])) self.assertEqual(collection.sorted('helper'), ApplicationsCollection([a1, a3, a2])) self.assertIsInstance(collection, ApplicationsCollection)
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_contains_formating(self): a1 = Application({"name": "foo", "type": "applicaiton", "helper": "some helper"}) a3 = Application({"name": "foo", "type": "application", "helper": "some helper with {FOO} argument"}) self.assertFalse(a1.helper_contains_formating) self.assertTrue(a3.helper_contains_formating)
def test_contains_name(self): a1 = Application({"name": "foo", "type": "applicaiton", "helper": "some helper"}) a2 = Application({"name": "foo", "type": "application", "helper": "some helper with {NAME} argument"}) self.assertFalse(a1.helper_contains_name) self.assertTrue(a2.helper_contains_name)
def test_representations(self): rule = Application({"name": "foo"}) self.assertEquals(str(rule), "<Application: foo>") self.assertEquals(repr(rule), "<Application: foo>")
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"))