Skip to content

Commit

Permalink
Adjust 'data' docs in format.rst
Browse files Browse the repository at this point in the history
The details of how things works when data is a non-string were
not correct. When fixing that it became clear that the information
would make more sense presented as a list. So now it is.
  • Loading branch information
cdent committed Nov 30, 2016
1 parent 2fe6fd0 commit 21663d9
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions docs/source/format.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,23 @@ Data
----

The ``data`` key has some special handing to allow for a bit more
flexibility when doing a ``POST`` or ``PUT``. If the value is not a
string (that is, it is a sequence or structure) it is treated as a
data structure which is turned into a JSON string. If the value is a
string that begins with ``<@`` then the rest of the string is treated
as a filepath to be loaded. The path is relative to the test directory
and may not traverse up into parent directories. If the value is an
undecorated string, that's the value.

When reading from a file care should be taken to ensure that a
reasonable content-type is set for the data as this will control if any
encoding is done of the resulting string value. If it is text, json, xml
or javascript it will be encoded to UTF-8.
flexibility when doing a ``POST`` or ``PUT``:

* If the value is not a string (that is, it is a sequence or structure)
it is treated as a data structure that will be turned into a
string by the ``dumps`` method on the relevant
:doc:`content handler <handlers>`. For example if the content-type of
the body is ``application/json`` the data structure will be turned
into a JSON string.
* If the value is a string that begins with ``<@`` then the rest of the
string is treated as a filepath to be loaded. The path is relative
to the test directory and may not traverse up into parent directories.
* If the value is an undecorated string, that's the value.

.. note:: When reading from a file care should be taken to ensure that a
reasonable content-type is set for the data as this will control
if any encoding is done of the resulting string value. If it
is text, json, xml or javascript it will be encoded to UTF-8.


.. _the gabbi tests: https://github.com/cdent/gabbi/tree/master/gabbi/tests/gabbits_intercept
Expand Down

0 comments on commit 21663d9

Please sign in to comment.