operator icon indicating copy to clipboard operation
operator copied to clipboard

Add support for automatically encoding testing.Relation data to JSON

Open tonyandrewmeyer opened this issue 9 months ago • 3 comments

It's already common practice to have all the field values in relation data be JSON-encoded, and this will increase more once ops supports using data classes to load/save relation data, where the default is to JSON encode/decode each field's value.

Rather than having a lot of json.dumps() in setting up testing.Relation objects, and a lot of json.loads() in asserts, it would be convenient if there was a way to have this happen transparently.

tonyandrewmeyer avatar Jun 06 '25 05:06 tonyandrewmeyer

Makes sense to me. testing.Relation(..., json=True) maybe?

benhoyt avatar Jun 08 '25 21:06 benhoyt

We're not 100% sure about the API, but something like json=True mentioned above.

benhoyt avatar Sep 09 '25 02:09 benhoyt

Some charm unit tests use idioms like this:

      tracing = Relation(
          "tracing",
          remote_app_data=TracingRequirerAppData(receivers=[requested_protocol]).dump(),
      )

That being said, manual json.dumps() and manual plain (without json) are used in the same set of unit tests.

dimaqq avatar Sep 09 '25 03:09 dimaqq