def test_container_to_bytes_incomp_chars_and_encod(test_input, encoding, errors): """ Test for passing incompatible characters and encodings container_to_bytes(). """ with pytest.raises(UnicodeEncodeError, match="codec can't encode"): container_to_bytes(test_input, encoding=encoding, errors=errors)
def get_update_params(module, zbx, mediatype_id, **kwargs): """Filters only the parameters that are different and need to be updated. Args: module: AnsibleModule object. zbx: ZabbixAPI object. mediatype_id (int): ID of the mediatype to be updated. **kwargs: Parameters for the new mediatype. Returns: A tuple where the first element is a dictionary of parameters that need to be updated and the second one is a dictionary returned by diff() function with existing mediatype data and new params passed to it. """ existing_mediatype = container_to_bytes( zbx.mediatype.get({ 'output': 'extend', 'mediatypeids': [mediatype_id] })[0]) if existing_mediatype['type'] != kwargs['type']: return kwargs, diff(existing_mediatype, kwargs) else: params_to_update = {} for key in kwargs: if (not (kwargs[key] is None and existing_mediatype[key] == '') ) and kwargs[key] != existing_mediatype[key]: params_to_update[key] = kwargs[key] return params_to_update, diff(existing_mediatype, kwargs)
def test_container_to_bytes_default_encoding_err(test_input, expected): """ Test for passing objects to container_to_bytes(). Default encoding and errors """ assert container_to_bytes(test_input, encoding=DEFAULT_ENCODING, errors=DEFAULT_ERR_HANDLER) == expected
def test_container_to_bytes_surrogate_then_replace(test_input, encoding, expected): """ Test for container_to_bytes() with surrogate_then_replace err handler. """ assert container_to_bytes(test_input, encoding=encoding, errors='surrogate_then_replace') == expected
def test_container_to_bytes(test_input, expected, encoding, errors): """Test for passing objects to container_to_bytes().""" assert container_to_bytes(test_input, encoding=encoding, errors=errors) == expected