def test_install(self): ''' Test to install new alternative for defined <name> ''' name = 'pager' link = '/usr/bin/pager' path = '/usr/bin/less' priority = 5 ret = {'name': name, 'link': link, 'path': path, 'priority': priority, 'result': None, 'changes': {}, 'comment': ''} bad_link = '/bin/pager' err = 'the primary link for {0} must be {1}'.format(name, link) mock = MagicMock(side_effect=[True, False, False, False]) mock_out = MagicMock(side_effect=['', err]) mock_path = MagicMock(return_value=path) mock_link = MagicMock(return_value=link) with patch.dict(alternatives.__salt__, {'alternatives.check_installed': mock, 'alternatives.install': mock_out, 'alternatives.show_current': mock_path, 'alternatives.show_link': mock_link}): comt = ('Alternatives for {0} is already set to {1}' ).format(name, path) ret.update({'comment': comt, 'result': True}) self.assertDictEqual(alternatives.install(name, link, path, priority), ret) comt = (('Alternative will be set for {0} to {1} with priority {2}' ).format(name, path, priority)) ret.update({'comment': comt, 'result': None}) with patch.dict(alternatives.__opts__, {'test': True}): self.assertDictEqual(alternatives.install(name, link, path, priority), ret) comt = ('Alternative for {0} set to path {1} with priority {2}' ).format(name, path, priority) ret.update({'comment': comt, 'result': True, 'changes': {'name': name, 'link': link, 'path': path, 'priority': priority}}) with patch.dict(alternatives.__opts__, {'test': False}): self.assertDictEqual(alternatives.install(name, link, path, priority), ret) comt = ('Alternative for {0} not installed: {1}' ).format(name, err) ret.update({'comment': comt, 'result': False, 'changes': {}, 'link': bad_link}) with patch.dict(alternatives.__opts__, {'test': False}): self.assertDictEqual(alternatives.install(name, bad_link, path, priority), ret)
def test_install(self): ''' Test to install new alternative for defined <name> ''' name = 'pager' link = '/usr/bin/pager' path = '/usr/bin/less' priority = 5 ret = {'name': name, 'link': link, 'path': path, 'priority': priority, 'result': None, 'changes': {}, 'comment': ''} bad_link = '/bin/pager' err = 'the primary link for {0} must be {1}'.format(name, link) mock = MagicMock(side_effect=[True, False, False, False]) mock_out = MagicMock(side_effect=['', err]) mock_path = MagicMock(return_value=path) mock_link = MagicMock(return_value=link) with patch.dict(alternatives.__salt__, {'alternatives.check_installed': mock, 'alternatives.install': mock_out, 'alternatives.show_current': mock_path, 'alternatives.show_link': mock_link}): comt = ('Alternatives for {0} is already set to {1}' ).format(name, path) ret.update({'comment': comt, 'result': True}) self.assertDictEqual(alternatives.install(name, link, path, priority), ret) comt = (('Alternative will be set for {0} to {1} with priority {2}' ).format(name, path, priority)) ret.update({'comment': comt, 'result': None}) with patch.dict(alternatives.__opts__, {'test': True}): self.assertDictEqual(alternatives.install(name, link, path, priority), ret) comt = ('Alternative for {0} set to path {1} with priority {2}' ).format(name, path, priority) ret.update({'comment': comt, 'result': True, 'changes': {'name': name, 'link': link, 'path': path, 'priority': priority}}) with patch.dict(alternatives.__opts__, {'test': False}): self.assertDictEqual(alternatives.install(name, link, path, priority), ret) comt = ('Alternative for {0} not installed: {1}' ).format(name, err) ret.update({'comment': comt, 'result': False, 'changes': {}, 'link': bad_link}) with patch.dict(alternatives.__opts__, {'test': False}): self.assertDictEqual(alternatives.install(name, bad_link, path, priority), ret)
def test_install(self): ''' Test to install new alternative for defined <name> ''' name = 'pager' link = '/usr/bin/pager' path = '/usr/bin/less' priority = 5 ret = { 'name': name, 'link': link, 'path': path, 'priority': priority, 'result': None, 'changes': {}, 'comment': '' } mock = MagicMock(side_effect=[True, False, False]) mock_bool = MagicMock(return_value=True) with patch.dict( alternatives.__salt__, { 'alternatives.check_installed': mock, 'alternatives.install': mock_bool }): comt = ('Alternatives for {0} is already set to {1}').format( name, path) ret.update({'comment': comt, 'result': True}) self.assertDictEqual( alternatives.install(name, link, path, priority), ret) comt = (('Alternative will be set for {0} to {1} with priority {2}' ).format(name, path, priority)) ret.update({'comment': comt, 'result': None}) with patch.dict(alternatives.__opts__, {'test': True}): self.assertDictEqual( alternatives.install(name, link, path, priority), ret) comt = ( 'Setting alternative for {0} to {1} with priority {2}').format( name, path, priority) ret.update({ 'comment': comt, 'result': True, 'changes': { 'name': name, 'link': link, 'path': path, 'priority': priority } }) with patch.dict(alternatives.__opts__, {'test': False}): self.assertDictEqual( alternatives.install(name, link, path, priority), ret)
def test_install(self): ''' Test to install new alternative for defined <name> ''' name = 'pager' link = '/usr/bin/pager' path = '/usr/bin/less' priority = 5 ret = {'name': name, 'link': link, 'path': path, 'priority': priority, 'result': None, 'changes': {}, 'comment': ''} mock = MagicMock(side_effect=[True, False, False]) mock_bool = MagicMock(return_value=True) with patch.dict(alternatives.__salt__, {'alternatives.check_installed': mock, 'alternatives.install': mock_bool}): comt = ('Alternatives for {0} is already set to {1}' ).format(name, path) ret.update({'comment': comt, 'result': True}) self.assertDictEqual(alternatives.install(name, link, path, priority), ret) comt = (('Alternative will be set for {0} to {1} with priority {2}' ).format(name, path, priority)) ret.update({'comment': comt, 'result': None}) with patch.dict(alternatives.__opts__, {'test': True}): self.assertDictEqual(alternatives.install(name, link, path, priority), ret) comt = ('Setting alternative for {0} to {1} with priority {2}' ).format(name, path, priority) ret.update({'comment': comt, 'result': True, 'changes': {'name': name, 'link': link, 'path': path, 'priority': priority}}) with patch.dict(alternatives.__opts__, {'test': False}): self.assertDictEqual(alternatives.install(name, link, path, priority), ret)
def test_install(): """ Test to install new alternative for defined <name> """ name = "pager" link = "/usr/bin/pager" path = "/usr/bin/less" priority = 5 ret = { "name": name, "link": link, "path": path, "priority": priority, "result": None, "changes": {}, "comment": "", } bad_link = "/bin/pager" err = "the primary link for {} must be {}".format(name, link) mock_cinst = MagicMock(side_effect=[True, False]) mock_cexist = MagicMock( side_effect=[True, False, False, True, False, False, False, True]) mock_out = MagicMock(side_effect=["", err, ""]) mock_path = MagicMock(return_value=path) mock_link = MagicMock(return_value=link) with patch.dict( alternatives.__salt__, { "alternatives.check_installed": mock_cinst, "alternatives.check_exists": mock_cexist, "alternatives.install": mock_out, "alternatives.show_current": mock_path, "alternatives.show_link": mock_link, }, ): comt = "Alternative {} for {} is already registered".format(path, name) ret.update({"comment": comt, "result": True}) assert alternatives.install(name, link, path, priority) == ret comt = "Alternative will be set for {} to {} with priority {}".format( name, path, priority) ret.update({"comment": comt, "result": None}) with patch.dict(alternatives.__opts__, {"test": True}): assert alternatives.install(name, link, path, priority) == ret comt = "Alternative for {} set to path {} with priority {}".format( name, path, priority) ret.update({ "comment": comt, "result": True, "changes": { "name": name, "link": link, "path": path, "priority": priority, }, }) with patch.dict(alternatives.__opts__, {"test": False}): assert alternatives.install(name, link, path, priority) == ret comt = "Alternative for {} not installed: {}".format(name, err) ret.update({ "comment": comt, "result": False, "changes": {}, "link": bad_link }) with patch.dict(alternatives.__opts__, {"test": False}): assert alternatives.install(name, bad_link, path, priority) == ret comt = "Alternative {} for {} registered with priority {} and not set to default".format( path, name, priority) ret.update({ "comment": comt, "result": True, "changes": { "name": name, "link": link, "path": path, "priority": priority, }, "link": link, }) with patch.dict(alternatives.__opts__, {"test": False}): assert alternatives.install(name, link, path, priority) == ret