class TestView(unittest.TestCase): DATA = {'description': 'Important Shizz', 'jobs': [{'color': 'blue', 'name': 'foo', 'url': 'http://*****:*****@mock.patch.object(View, '_poll') def setUp(self, _poll): _poll.return_value = self.DATA # def __init__(self, url, name, jenkins_obj) self.J = mock.MagicMock() # Jenkins object self.v = View('http://localhost:800/view/FodFanFo', 'FodFanFo', self.J) def testRepr(self): # Can we produce a repr string for this object repr(self.v) def testName(self): with self.assertRaises(AttributeError): self.v.id() self.assertEquals(self.v.name, 'FodFanFo')
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://localhost:800/view/FodFanFo', 'FodFanFo', self.J)
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)
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)
def view(jenkins, monkeypatch): def fake_get_data(cls, url, tree=None): # pylint: disable=unused-argument return VIEW_DATA monkeypatch.setattr(JenkinsBase, 'get_data', fake_get_data) return View('http://localhost:800/view/Buildampel', 'Buildampel', jenkins)
def __getitem__(self, view_name): self.poll() for row in self._data.get('views', []): if row['name'] == view_name: return View(row['url'], row['name'], self.jenkins) raise KeyError('View %s not found' % view_name)
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://localhost:800/view/FodFanFo", "FodFanFo", self.J)
def iteritems(self): """ Get the names & objects for all views """ self.jenkins.poll() for row in self.jenkins._data.get('views', []): name = row['name'] url = row['url'] yield name, View(url, name, self.jenkins)
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)
def __getitem__(self, view_name): for row in self.jenkins._data.get('views', []): if row['name'] == view_name: return View(row['url'], row['name'], self.jenkins)
def get_view_by_url(self, str_view_url): #for nested view str_view_name = str_view_url.split('/view/')[-1].replace('/', '') return View(str_view_url, str_view_name, jenkins_obj=self)
def __init__(self, url, name, jenkins_obj): _View.__init__(self, url, name, jenkins_obj) self._get_form_content()
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)
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)
def setUp(self, _poll): _poll.return_value = self.DATA # def __init__(self, url, name, jenkins_obj) self.J = mock.MagicMock() # Jenkins object self.v = View('http://localhost:800/view/FodFanFo', 'FodFanFo', self.J)
def get_view(self, str_view_name): view_url = self.get_view_url(str_view_name) view_api_url = self.python_api_url(view_url) return View(view_url, str_view_name, jenkins_obj=self)
def view(_view_poll, _job_poll, jenkins): _view_poll.return_value = DATA _job_poll.return_value = JOB_DATA return View('http://localhost:800/view/FodFanFo', 'FodFanFo', jenkins)
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)