]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-deploy.git/commitdiff
create tests for the new conf utils 166/head
authorAlfredo Deza <alfredo.deza@inktank.com>
Tue, 4 Mar 2014 18:50:44 +0000 (13:50 -0500)
committerAlfredo Deza <alfredo.deza@inktank.com>
Tue, 4 Mar 2014 18:50:44 +0000 (13:50 -0500)
Signed-off-by: Alfredo Deza <alfredo.deza@inktank.com>
ceph_deploy/tests/unit/test_conf.py [new file with mode: 0644]

diff --git a/ceph_deploy/tests/unit/test_conf.py b/ceph_deploy/tests/unit/test_conf.py
new file mode 100644 (file)
index 0000000..c9b379a
--- /dev/null
@@ -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'