From: Alfredo Deza Date: Tue, 4 Mar 2014 18:50:44 +0000 (-0500) Subject: create tests for the new conf utils X-Git-Tag: v1.4.0~8^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F166%2Fhead;p=ceph-deploy.git create tests for the new conf utils Signed-off-by: Alfredo Deza --- diff --git a/ceph_deploy/tests/unit/test_conf.py b/ceph_deploy/tests/unit/test_conf.py new file mode 100644 index 0000000..c9b379a --- /dev/null +++ b/ceph_deploy/tests/unit/test_conf.py @@ -0,0 +1,36 @@ +from mock import Mock, patch +from ceph_deploy import conf +from ceph_deploy.tests import fakes + + +class TestLocateOrCreate(object): + + def setup(self): + self.fake_write = Mock(name='fake_write') + self.fake_file = fakes.mock_open(data=self.fake_write) + self.fake_file.readline.return_value = self.fake_file + + def test_no_conf(self): + with patch('__builtin__.open', self.fake_file): + conf.cephdeploy.location() + + assert self.fake_file.called is True + assert self.fake_file.call_args[0][0].endswith('/.cephdeploy.conf') + + def test_cwd_conf_exists(self): + fake_path = Mock() + fake_path.join = Mock(return_value='/srv/cephdeploy.conf') + fake_path.exists = Mock(return_value=True) + with patch('ceph_deploy.conf.cephdeploy.path', fake_path): + result = conf.cephdeploy.location() + + assert result == '/srv/cephdeploy.conf' + + def test_home_conf_exists(self): + fake_path = Mock() + fake_path.expanduser = Mock(return_value='/home/alfredo/.cephdeploy.conf') + fake_path.exists = Mock(side_effect=[False, True]) + with patch('ceph_deploy.conf.cephdeploy.path', fake_path): + result = conf.cephdeploy.location() + + assert result == '/home/alfredo/.cephdeploy.conf'