|
| 1 | +# Licensed to Cloudera, Inc. under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. Cloudera, Inc. licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +import unittest |
| 18 | +from cm_api.endpoints.clusters import * |
| 19 | +from cm_api.endpoints.services import * |
| 20 | +from cm_api.endpoints.types import * |
| 21 | +from cm_api_tests import utils |
| 22 | + |
| 23 | +class TestWatchedDir(unittest.TestCase): |
| 24 | + |
| 25 | + def test_empty_list_watched_directories(self): |
| 26 | + resource = utils.MockResource(self) |
| 27 | + service = ApiService(resource, name="bar") |
| 28 | + |
| 29 | + resource.expect("GET", "/cm/service/watcheddir", |
| 30 | + retdata={ "items" : [] }) |
| 31 | + |
| 32 | + responses = service.list_watched_directories() |
| 33 | + self.assertIsInstance(responses, ApiList) |
| 34 | + self.assertEquals(0, len(responses)) |
| 35 | + |
| 36 | + def test_non_empty_list_watched_directories(self): |
| 37 | + WATCHED_DIRS_LIST = '''{ |
| 38 | + "items": [ { |
| 39 | + "path" : "/dir1" |
| 40 | + }, { |
| 41 | + "path" : "/dir2" |
| 42 | + } ] |
| 43 | + }''' |
| 44 | + |
| 45 | + resource = utils.MockResource(self) |
| 46 | + service = ApiService(resource, name="bar") |
| 47 | + |
| 48 | + resource.expect("GET", "/cm/service/watcheddir", |
| 49 | + retdata=json.loads(WATCHED_DIRS_LIST)) |
| 50 | + responses = service.list_watched_directories() |
| 51 | + |
| 52 | + self.assertIsInstance(responses, ApiList) |
| 53 | + self.assertEquals(2, len(responses)) |
| 54 | + response = responses[0] |
| 55 | + self.assertIsInstance(response, ApiWatchedDir) |
| 56 | + self.assertEquals("/dir1", response.path) |
| 57 | + response = responses[1] |
| 58 | + self.assertIsInstance(response, ApiWatchedDir) |
| 59 | + self.assertEquals("/dir2", response.path) |
| 60 | + |
| 61 | + def test_add_watched_directory(self): |
| 62 | + resource = utils.MockResource(self) |
| 63 | + service = ApiService(resource, name="bar") |
| 64 | + |
| 65 | + resource.expect("POST", "/cm/service/watcheddir", |
| 66 | + retdata={ 'path' : '/dir' }, data={ 'path' : '/dir' }) |
| 67 | + response = service.add_watched_directory("/dir") |
| 68 | + self.assertIsInstance(response, ApiWatchedDir) |
| 69 | + self.assertEquals("/dir", response.path) |
| 70 | + |
| 71 | + def test_remove_watched_directory(self): |
| 72 | + resource = utils.MockResource(self) |
| 73 | + service = ApiService(resource, name="bar") |
| 74 | + |
| 75 | + resource.expect("DELETE", "/cm/service/watcheddir/one_dir_path", |
| 76 | + retdata={ 'path' : 'one_dir_path' }) |
| 77 | + response = service.remove_watched_directory("one_dir_path") |
| 78 | + self.assertIsInstance(response, ApiWatchedDir) |
| 79 | + self.assertEquals("one_dir_path", response.path) |
0 commit comments