Beispiel #1
0
def test_set(etcd_client_mock, instance):
    """
    Test salt.sdb.etcd_db.set function
    """
    with patch("salt.sdb.etcd_db._get_conn", etcd_client_mock):
        instance.get.return_value = "super awesome"

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

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

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

        instance.get.side_effect = Exception
        pytest.raises(Exception, etcd_db.set_, "bad key", "bad value")
Beispiel #2
0
def test_set(subtests, etcd_profile, prefix):
    """
    Test setting a value
    """
    with subtests.test("we should be able to set a key/value pair"):
        assert etcd_db.set_("{}/1".format(prefix), "one",
                            profile=etcd_profile) == "one"

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

    with subtests.test(
            "assigning a value to be None should assign it to an empty value"):
        assert etcd_db.set_("{}/1".format(prefix), None,
                            profile=etcd_profile) == ""

    with subtests.test(
            "providing a service to set should do nothing extra at the moment"
    ):
        assert (etcd_db.set_("{}/1".format(prefix),
                             "one",
                             service="Pablo",
                             profile=etcd_profile) == "one")
Beispiel #3
0
    def test_set(self):
        """
        Test salt.sdb.etcd_db.set function
        """
        with patch("salt.sdb.etcd_db._get_conn", self.EtcdClientMock):
            etcd_db.set_("sdb://myetcd/path/to/foo/bar", "super awesome")

        self.assertEqual(
            self.instance.set.call_args_list,
            [call("sdb://myetcd/path/to/foo/bar", "super awesome")],
        )

        self.assertEqual(
            self.instance.get.call_args_list,
            [call("sdb://myetcd/path/to/foo/bar")],
        )
Beispiel #4
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)
Beispiel #5
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")
Beispiel #6
0
def test_delete(subtests, etcd_profile, prefix):
    """
    Test deleting a value
    """
    with subtests.test("deleting a nonexistent key should still return True"):
        assert etcd_db.delete("{}/1".format(prefix), profile=etcd_profile)

    with subtests.test(
            "underlying delete throwing an error should return False"):
        with patch.object(EtcdClient, "delete", side_effect=Exception):
            assert not etcd_db.delete("{}/1".format(prefix),
                                      profile=etcd_profile)

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

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