Example #1
0
    def test_set_key_value_raises_if_value_too_large(self, monkeypatch,
                                                     cloud_api):
        Client = MagicMock()
        monkeypatch.setattr("prefect.backend.kv_store.Client", Client)

        # value over the 10 KB limit
        large_value = "1" * 10001

        with pytest.raises(ValueError,
                           match="Value payload exceedes 10 KB limit."):
            set_key_value(key="foo", value=large_value)
        Client.assert_not_called()
Example #2
0
def set_command(key, value):
    """
    Set a key value pair, overriding existing values if key exists

    \b
    Arguments:
        key         TEXT    Key to set
        value       TEXT    Value associated with key to set
    """
    try:
        kv_store.set_key_value(key=key, value=value)
        click.secho("Key value pair set successfully", fg="green")
    except Exception as exc:
        log_exception(exc)
        raise TerminalError("An error occurred setting the key value pair")
Example #3
0
    def test_set_key_value_calls_client_mutation_correctly(
            self, monkeypatch, cloud_api, value):
        Client = MagicMock()
        Client().graphql.return_value = GraphQLResult(
            data=dict(set_key_value=GraphQLResult({"id": "123"}), ))
        monkeypatch.setattr("prefect.backend.kv_store.Client", Client)

        key_value_id = set_key_value(key="foo", value=value)
        Client.return_value.graphql.assert_called_with(
            query={
                "mutation($input: set_key_value_input!)": {
                    "set_key_value(input: $input)": {"id"}
                }
            },
            variables={"input": {
                "key": "foo",
                "value": value
            }},
        )
        assert key_value_id == "123"
Example #4
0
 def test_set_key_value_raises_on_server_backend(self, server_api):
     with pytest.raises(ClientError):
         set_key_value(key="foo", value="bar")