def test_get_name(self):
        """Ensure we can successfully set the name"""
        self._set_args()

        expected = dict(name='y', status='online')
        namer = GlobalSettings()

        with mock.patch(self.REQ_FUNC, return_value=(200, expected)) as req:
            name = namer.get_name()
            self.assertEquals(name, expected['name'])
    def test_get_name_fail(self):
        """Ensure we can successfully set the name"""
        self._set_args()

        expected = dict(name='y', status='offline')
        namer = GlobalSettings()

        with self.assertRaises(AnsibleFailJson):
            with mock.patch(self.REQ_FUNC, side_effect=Exception()) as req:
                name = namer.get_name()

        with self.assertRaises(AnsibleFailJson):
            with mock.patch(self.REQ_FUNC,
                            return_value=(200, expected)) as req:
                update = namer.update_name()
    def test_set_name(self):
        """Ensure we can successfully set the name"""
        self._set_args(dict(name="x"))

        expected = dict(name='y', status='online')
        namer = GlobalSettings()
        # Expecting an update
        with mock.patch(self.REQ_FUNC, return_value=(200, expected)) as req:
            with mock.patch.object(namer, 'get_name', return_value='y'):
                update = namer.update_name()
                self.assertTrue(update)
        # Expecting no update
        with mock.patch(self.REQ_FUNC, return_value=(200, expected)) as req:
            with mock.patch.object(namer, 'get_name', return_value='x'):
                update = namer.update_name()
                self.assertFalse(update)

        # Expecting an update, but no actual calls, since we're using check_mode=True
        namer.check_mode = True
        with mock.patch(self.REQ_FUNC, return_value=(200, expected)) as req:
            with mock.patch.object(namer, 'get_name', return_value='y'):
                update = namer.update_name()
                self.assertEquals(0, req.called)
                self.assertTrue(update)