Ejemplo n.º 1
0
    def test_add_job(self, _poll, _view_poll):
        _poll.return_value = self.DATA
        _view_poll.return_value = self.DATA
        J = mock.MagicMock()  # Jenkins object
        J.has_job.return_value = True
        v = View("http://localhost:800/view/FodFanFo", "FodFanFo", self.J)

        result = v.add_job("bar")
        self.assertFalse(result)
Ejemplo n.º 2
0
    def test_add_job(self, _poll, _view_poll):
        _poll.return_value = self.DATA
        _view_poll.return_value = self.DATA
        J = mock.MagicMock()  # Jenkins object
        J.has_job.return_value = True
        v = View('http://localhost:800/view/FodFanFo', 'FodFanFo', self.J)

        result = v.add_job('bar')
        self.assertTrue(result)
Ejemplo n.º 3
0
class TestView(unittest.TestCase):

    DATA = {
        "description": "Important Shizz",
        "jobs": [
            {"color": "blue", "name": "foo", "url": "http://*****:*****@mock.patch.object(Job, "_poll")
    @mock.patch.object(View, "_poll")
    def setUp(self, _view_poll, _job_poll):
        _view_poll.return_value = self.DATA
        _job_poll.return_value = self.JOB_DATA

        # def __init__(self, url, name, jenkins_obj)
        self.J = mock.MagicMock()  # Jenkins object
        self.J.has_job.return_value = False
        self.v = View("http://*****:*****@mock.patch.object(JenkinsBase, "_poll")
    def test_iteritems(self, _poll):
        _poll.return_value = self.JOB_DATA
        for job_name, job_obj in self.v.iteritems():
            self.assertTrue(isinstance(job_obj, Job))

    def test_get_job_dict(self):
        jobs = self.v.get_job_dict()
        self.assertEquals(
            jobs, {"foo": "http://*****:*****@mock.patch.object(JenkinsBase, "_poll")
    def test_getitem(self, _poll):
        _poll.return_value = self.JOB_DATA
        self.assertTrue(isinstance(self.v["foo"], Job))

    def test_delete(self):
        self.v.delete()
        self.assertTrue(self.v.deleted)

    def test_get_job_url(self):
        self.assertEquals(self.v.get_job_url("foo"), "http://*****:*****@mock.patch.object(JenkinsBase, "_poll")
    @mock.patch.object(View, "_poll")
    def test_add_job(self, _poll, _view_poll):
        _poll.return_value = self.DATA
        _view_poll.return_value = self.DATA
        J = mock.MagicMock()  # Jenkins object
        J.has_job.return_value = True
        v = View("http://*****:*****@mock.patch.object(Jenkins, "has_job")
    def test_add_wrong_job(self, _has_job):
        _has_job.return_value = False
        result = self.v.add_job("bar")
        self.assertFalse(result)

    def test_add_existing_job(self):
        result = self.v.add_job("foo")
        self.assertFalse(result)

    def test_get_nested_view_dict(self):
        result = self.v.get_nested_view_dict()
        self.assertTrue(isinstance(result, dict))
        self.assertEquals(len(result), 0)
Ejemplo n.º 4
0
class TestView(unittest.TestCase):

    DATA = {'description': 'Important Shizz',
            'jobs': [
                {'color': 'blue',
                 'name': 'foo',
                 'url': 'http://*****:*****@mock.patch.object(Job, '_poll')
    @mock.patch.object(View, '_poll')
    def setUp(self, _view_poll, _job_poll):
        _view_poll.return_value = self.DATA
        _job_poll.return_value = self.JOB_DATA

        # def __init__(self, url, name, jenkins_obj)
        self.J = mock.MagicMock()  # Jenkins object
        self.J.has_job.return_value = False
        self.v = View('http://*****:*****@mock.patch.object(JenkinsBase, '_poll')
    def test_iteritems(self, _poll):
        _poll.return_value = self.JOB_DATA
        for job_name, job_obj in self.v.iteritems():
            self.assertTrue(isinstance(job_obj, Job))

    def test_get_job_dict(self):
        jobs = self.v.get_job_dict()
        self.assertEquals(jobs, {
            'foo': 'http://*****:*****@mock.patch.object(JenkinsBase, '_poll')
    def test_getitem(self, _poll):
        _poll.return_value = self.JOB_DATA
        self.assertTrue(isinstance(self.v['foo'], Job))

    def test_delete(self):
        self.v.delete()
        self.assertTrue(self.v.deleted)

    def test_get_job_url(self):
        self.assertEquals(self.v.get_job_url('foo'), 'http://*****:*****@mock.patch.object(JenkinsBase, '_poll')
    @mock.patch.object(View, '_poll')
    def test_add_job(self, _poll, _view_poll):
        _poll.return_value = self.DATA
        _view_poll.return_value = self.DATA
        J = mock.MagicMock()  # Jenkins object
        J.has_job.return_value = True
        v = View('http://*****:*****@mock.patch.object(View, 'get_jenkins_obj')
    def test_add_wrong_job(self, _get_jenkins):
        _get_jenkins.return_value = TestView.SelfPatchJenkins()
        result = self.v.add_job('bar')
        self.assertFalse(result)

    def test_add_existing_job(self):
        result = self.v.add_job('foo')
        self.assertFalse(result)

    def test_get_nested_view_dict(self):
        result = self.v.get_nested_view_dict()
        self.assertTrue(isinstance(result, dict))
        self.assertEquals(len(result), 0)
Ejemplo n.º 5
0
class TestView(unittest.TestCase):

    DATA = {'description': 'Important Shizz',
            'jobs': [
                {'color': 'blue',
                 'name': 'foo',
                 'url': 'http://*****:*****@mock.patch.object(Job, '_poll')
    @mock.patch.object(View, '_poll')
    def setUp(self, _view_poll, _job_poll):
        _view_poll.return_value = self.DATA
        _job_poll.return_value = self.JOB_DATA

        # def __init__(self, url, name, jenkins_obj)
        self.J = mock.MagicMock()  # Jenkins object
        self.J.has_job.return_value = False
        self.v = View('http://*****:*****@mock.patch.object(JenkinsBase, '_poll')
    def test_iteritems(self, _poll):
        _poll.return_value = self.JOB_DATA
        for job_name, job_obj in self.v.iteritems():
            self.assertTrue(isinstance(job_obj, Job))

    def test_get_job_dict(self):
        jobs = self.v.get_job_dict()
        self.assertEquals(jobs, {
            'foo': 'http://*****:*****@mock.patch.object(JenkinsBase, '_poll')
    def test_getitem(self, _poll):
        _poll.return_value = self.JOB_DATA
        self.assertTrue(isinstance(self.v['foo'], Job))

    def test_delete(self):
        self.v.delete()
        self.assertTrue(self.v.deleted)

    def test_get_job_url(self):
        self.assertEquals(self.v.get_job_url('foo'), 'http://*****:*****@mock.patch.object(JenkinsBase, '_poll')
    @mock.patch.object(View, '_poll')
    def test_add_job(self, _poll, _view_poll):
        _poll.return_value = self.DATA
        _view_poll.return_value = self.DATA
        J = mock.MagicMock()  # Jenkins object
        J.has_job.return_value = True
        v = View('http://*****:*****@mock.patch.object(View, 'get_jenkins_obj')
    def test_add_wrong_job(self, _get_jenkins):
        _get_jenkins.return_value = TestView.SelfPatchJenkins()
        result = self.v.add_job('bar')
        self.assertFalse(result)

    def test_add_existing_job(self):
        result = self.v.add_job('foo')
        self.assertFalse(result)

    def test_get_nested_view_dict(self):
        result = self.v.get_nested_view_dict()
        self.assertTrue(isinstance(result, dict))
        self.assertEquals(len(result), 0)

    @mock.patch.object(View, '_poll')
    def test_poll_cache(self, _poll):
        # only gets called once in interval
        v = View('http://localhost:800/view/FodFanFo', 'FodFanFo', self.J,
                  poll_cache_timeout=1)
        for i in range(2):
            v.poll()
        self.assertEquals(_poll.call_count, 1)
        v.poll(True)  # test force poll
        self.assertEquals(_poll.call_count, 2)

        # ensure it gets called again after cache timeout
        _poll.reset_mock()
        time.sleep(1.1)
        v.poll()
        self.assertTrue(_poll.called)

        # ensure it is disabled by default
        _poll.reset_mock()
        for i in range(2):
            self.v.poll()
        self.assertEquals(_poll.call_count, 2)
        self.assertIsNone(self.v.poll_cache_expires)