From: Aleksey Maksimov Date: Mon, 10 Jun 2013 14:55:22 +0000 (+0800) Subject: Added tests for create_view and delete_view X-Git-Tag: v0.2.23~224^2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b059a0db8055ec0bf60fd0c96f96d3c66f319acc;p=tools%2Fpython-jenkinsapi.git Added tests for create_view and delete_view --- diff --git a/jenkinsapi_tests/unittests/test_jenkins.py b/jenkinsapi_tests/unittests/test_jenkins.py index 53c688b..7fd87eb 100644 --- a/jenkinsapi_tests/unittests/test_jenkins.py +++ b/jenkinsapi_tests/unittests/test_jenkins.py @@ -2,7 +2,8 @@ import mock import unittest import datetime -from jenkinsapi.jenkins import Jenkins +from jenkinsapi.jenkins import Jenkins, JenkinsBase, View +from jenkinsapi.utils.requester import Requester class TestJenkins(unittest.TestCase): @@ -45,5 +46,65 @@ class TestJenkinsURLs(unittest.TestCase): self.assertEquals( J.get_create_url(), 'http://localhost:8080/createItem') + +class TestJenkinsViews(unittest.TestCase): + + @mock.patch.object(Jenkins, '_poll') + @mock.patch.object(JenkinsBase, '_poll') + def test_create_view(self, _poll, _base_poll): + mock_requester = Requester(username='foouser', password='foopassword') + mock_requester.get_url = mock.MagicMock(return_value='
') + mock_requester.post_url = mock.MagicMock(return_value='') + _poll.return_value = {'views': [ + {'name': 'All', + 'url': 'http://localhost:8080/views/All'}, + {'name': 'NewView', + 'url': 'http://localhost:8080/views/NewView'}, + ]} + _base_poll.return_value = _poll.return_value + J = Jenkins('http://localhost:8080/', + username='foouser', password='foopassword', + requester=mock_requester) + new_view = J.create_view(str_view_name='NewView', person=None) + self.assertTrue(isinstance(new_view, View)) + self.assertEquals(new_view.baseurl, + 'http://localhost:8080/views/NewView') + + @mock.patch.object(Jenkins, '_poll') + def test_create_existing_view(self, _poll): + mock_requester = Requester(username='foouser', password='foopassword') + mock_requester.get_url = mock.MagicMock( + return_value='A view already exists') + J = Jenkins('http://localhost:8080/', + username='foouser', password='foopassword', + requester=mock_requester) + new_view = J.create_view(str_view_name='NewView', person=None) + self.assertFalse(isinstance(new_view, View)) + + @mock.patch.object(Jenkins, '_poll') + def test_delete_inexisting_view(self, _poll): + mock_requester = Requester(username='foouser', password='foopassword') + mock_requester.get_url = mock.MagicMock(return_value='
') + J = Jenkins('http://localhost:8080/', + username='foouser', password='foopassword', + requester=mock_requester) + delete_result = J.delete_view(str_view_name='NewView', person=None) + self.assertFalse(delete_result) + + @mock.patch.object(Jenkins, '_poll') + def test_delete_existing_view(self, _poll): + mock_requester = Requester(username='foouser', password='foopassword') + mock_requester.get_url = mock.MagicMock(return_value='View exists') + _poll.return_value = {'views': [ + {'name': 'All', + 'url': 'http://localhost:8080/views/All'}, + ]} + J = Jenkins('http://localhost:8080/', + username='foouser', password='foopassword', + requester=mock_requester) + delete_result = J.delete_view(str_view_name='NewView', person=None) + self.assertTrue(delete_result) + + if __name__ == '__main__': unittest.main()