Exemple #1
0
def test_rm():
    with patch("etcd.Client", autospec=True) as mock:
        etcd_client = mock.return_value
        client = etcd_util.EtcdClient({})

        etcd_client.delete.return_value = True
        assert client.rm("/some-key")
        etcd_client.delete.assert_called_with("/some-key", recursive=False)
        assert client.rm("/some-dir", recurse=True)
        etcd_client.delete.assert_called_with("/some-dir", recursive=True)

        etcd_client.delete.side_effect = etcd.EtcdNotFile()
        assert client.rm("/some-dir") is None

        etcd_client.delete.side_effect = etcd.EtcdDirNotEmpty()
        assert client.rm("/some-key") is None

        etcd_client.delete.side_effect = etcd.EtcdRootReadOnly()
        assert client.rm("/") is None

        etcd_client.delete.side_effect = ValueError
        assert client.rm("/some-dir") is None

        etcd_client.delete.side_effect = Exception
        with pytest.raises(Exception):
            client.rm("some-dir")
Exemple #2
0
    def test_rm(self):
        with patch('etcd.Client', autospec=True) as mock:
            etcd_client = mock.return_value
            client = etcd_util.EtcdClient({})

            etcd_client.delete.return_value = True
            self.assertEqual(client.rm('/some-key'), True)
            etcd_client.delete.assert_called_with('/some-key', recursive=False)
            self.assertEqual(client.rm('/some-dir', recurse=True), True)
            etcd_client.delete.assert_called_with('/some-dir', recursive=True)

            etcd_client.delete.side_effect = etcd.EtcdNotFile()
            self.assertEqual(client.rm('/some-dir'), None)

            etcd_client.delete.side_effect = etcd.EtcdDirNotEmpty()
            self.assertEqual(client.rm('/some-key'), None)

            etcd_client.delete.side_effect = etcd.EtcdRootReadOnly()
            self.assertEqual(client.rm('/'), None)

            etcd_client.delete.side_effect = ValueError
            self.assertEqual(client.rm('/some-dir'), None)

            etcd_client.delete.side_effect = Exception
            self.assertRaises(Exception, client.rm, 'some-dir')
 def test_delete_empty_parents_not_empty(self):
     m_client = Mock()
     m_client.delete = Mock()
     m_client.delete.side_effect = [
         None,
         etcd.EtcdDirNotEmpty(),
     ]
     delete_empty_parents(m_client, "/foo/bar/baz/biff", "/foo")
     self.assertEqual(m_client.delete.mock_calls, [
         call("foo/bar/baz/biff", dir=True, timeout=5),
         call("foo/bar/baz", dir=True, timeout=5),
     ])
Exemple #4
0
def test_rm(use_v2, client_name):
    with patch(client_name, autospec=True) as mock:
        etcd_client = mock.return_value
        client = etcd_util.get_conn(
            {"etcd.require_v2": use_v2, "etcd.encode_values": False}
        )

        if use_v2:
            etcd_client.delete.return_value = True
            assert client.rm("/some-key")
            etcd_client.delete.assert_called_with("/some-key", recursive=False)
            assert client.rm("/some-dir", recurse=True)
            etcd_client.delete.assert_called_with("/some-dir", recursive=True)

            etcd_client.delete.side_effect = etcd.EtcdNotFile()
            assert client.rm("/some-dir") is None

            etcd_client.delete.side_effect = etcd.EtcdDirNotEmpty()
            assert client.rm("/some-key") is None

            etcd_client.delete.side_effect = etcd.EtcdRootReadOnly()
            assert client.rm("/") is None

            etcd_client.delete.side_effect = ValueError
            assert client.rm("/some-dir") is None

            etcd_client.delete.side_effect = Exception
            with pytest.raises(Exception):
                client.rm("some-dir")
        else:
            etcd_client.delete_range.return_value = MagicMock(deleted=1)
            assert client.rm("/some-key")
            etcd_client.delete_range.assert_called_with("/some-key", prefix=False)

            etcd_client.delete_range.return_value = MagicMock(deleted=0)
            assert client.rm("/some-key", recurse=True) is None
            etcd_client.delete_range.assert_called_with("/some-key", prefix=True)

            delattr(etcd_client.delete_range.return_value, "deleted")
            assert not client.rm("/some-key")
            etcd_client.delete_range.assert_called_with("/some-key", prefix=False)