add unit test for multiple top level folders
authorTomas Olander <tomasolander@gmail.com>
Sun, 23 Feb 2014 13:50:23 +0000 (14:50 +0100)
committerTomas Olander <tomasolander@gmail.com>
Sun, 23 Feb 2014 13:50:23 +0000 (14:50 +0100)
jenkinsapi_tests/unittests/test_job_folders.py

index a23c4d8f200e49f6cb8cd7bafb850bc48c63c40f..15cfa4a078a18086cc4cee14f906def3830e305f 100644 (file)
@@ -119,6 +119,67 @@ class TestJobFolders(unittest.TestCase):
         )
         get_data_mock.assert_called_once_with('http://localhost:8080/job/Folder1/api/python')
 
+    @mock.patch('jenkinsapi.jenkins.JenkinsBase.get_data')
+    def test_multiple_folders(self, get_data_mock):
+        get_data_mock.side_effect = [
+            # first call
+            {
+                'jobs': [
+                    {
+                        'name': "Foo",
+                        'url': "http://localhost:8080/job/Folder1/job/Foo",
+                        'color': "disabled",
+                    },
+                ]
+            },
+
+            # second call
+            {
+                'jobs': [
+                    {
+                        'name': "Bar",
+                        'url': "http://localhost:8080/job/Folder2/job/Bar",
+                        'color': "blue",
+                    },
+                ]
+            },
+        ]
+
+        jobs = [
+            {
+                'name': "Folder1",
+                'url': "http://localhost:8080/job/Folder1",
+            },
+            {
+                'name': "Folder2",
+                'url': "http://localhost:8080/job/Folder2",
+            },
+        ]
+
+        self.assertEquals(
+            self.jb.resolve_job_folders(jobs),
+            [
+                {
+                    'name': "Foo",
+                    'url': "http://localhost:8080/job/Folder1/job/Foo",
+                    'color': "disabled",
+                },
+                {
+                    'name': "Bar",
+                    'url': "http://localhost:8080/job/Folder2/job/Bar",
+                    'color': "blue",
+                },
+            ]
+        )
+
+        self.assertEquals(
+            get_data_mock.call_args_list,
+            [
+                mock.call('http://localhost:8080/job/Folder1/api/python'),
+                mock.call('http://localhost:8080/job/Folder2/api/python'),
+            ]
+        )
+
     @mock.patch('jenkinsapi.jenkins.JenkinsBase.get_data')
     def test_multiple_folder_levels(self, get_data_mock):
         get_data_mock.side_effect = [