Example #1
0
    def test_get(self):
        """
        Test salt.sdb.etcd_db.get function
        """
        with patch("salt.sdb.etcd_db._get_conn", self.EtcdClientMock):
            etcd_db.get("sdb://myetcd/path/to/foo/bar")

        self.assertEqual(
            self.instance.get.call_args_list,
            [call("sdb://myetcd/path/to/foo/bar")],
        )
Example #2
0
def test_basic_operations(etcd_profile, prefix, profile_name):
    """
    Ensure we can do the basic CRUD operations available in sdb.etcd_db
    """
    assert (etcd_db.set_("{}/1".format(prefix),
                         "one",
                         profile=etcd_profile[profile_name]) == "one")
    etcd_db.delete("{}/1".format(prefix), profile=etcd_profile[profile_name])
    assert (etcd_db.get("{}/1".format(prefix),
                        profile=etcd_profile[profile_name]) is None)
Example #3
0
def test_get(etcd_client_mock, instance):
    """
    Test salt.sdb.etcd_db.get function
    """
    with patch("salt.sdb.etcd_db._get_conn", etcd_client_mock):
        instance.get.return_value = "super awesome"
        assert etcd_db.get("sdb://myetcd/path/to/foo/bar") == "super awesome"
        instance.get.assert_called_with("sdb://myetcd/path/to/foo/bar")

        assert (etcd_db.get("sdb://myetcd/path/to/foo/bar",
                            service="salt") == "super awesome")
        instance.get.assert_called_with("sdb://myetcd/path/to/foo/bar")

        assert (etcd_db.get("sdb://myetcd/path/to/foo/bar",
                            profile="stack") == "super awesome")
        instance.get.assert_called_with("sdb://myetcd/path/to/foo/bar")

        instance.get.side_effect = Exception
        pytest.raises(Exception, etcd_db.get, "bad key")
Example #4
0
def test_get(subtests, etcd_profile, prefix):
    """
    Test getting a value
    """
    with subtests.test("getting a nonexistent key should return None"):
        assert etcd_db.get("{}/1".format(prefix), profile=etcd_profile) is None

    with subtests.test(
            "we should be able to get a key/value pair that exists"):
        etcd_db.set_("{}/1".format(prefix), "one", profile=etcd_profile)
        assert etcd_db.get("{}/1".format(prefix),
                           profile=etcd_profile) == "one"

    with subtests.test(
            "providing a service to get should do nothing extra at the moment"
    ):
        assert (etcd_db.get("{}/1".format(prefix),
                            service="Picasso",
                            profile=etcd_profile) == "one")