<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    Hi Dan,
    <br>
    <p>
      Le 02/11/2016 à 19:10, Daniel Bradburn a écrit :<br>
      &gt;<br>
      &gt; Hi Sylvain, perhaps the responses library might be of use to
      you for mocking the requests library<br>
      &gt;<br>
      &gt; <a href="https://pypi.python.org/pypi/responses"
        title="https://pypi.python.org/pypi/responses" class="https">https://pypi.python.org/pypi/responses</a>
    </p>
    <p>
      Thanks Dan.
    </p>
    <p>
      I also found it here, with other tools, I share the link:<br>
      <a
href="http://stackoverflow.com/questions/15753390/python-mock-requests-and-the-response"
title="http://stackoverflow.com/questions/15753390/python-mock-requests-and-the-response"
        class="http">http://stackoverflow.com/questions/15753390/python-mock-requests-and-the-response</a>
    </p>
    <p>
      Coming back to my original question, using pytest-mock.
    </p>
    <p>
      It will create a MagickMock object which grabs all call, and even
      as a returned object.
    </p>
    <p>
      My code give the following steps: <br>
      <a
href="https://github.com/opensource-expert/powerdns-shell-wrapper/blob/dev-override-cmd-line/pdns_zone.py#L81"
title="https://github.com/opensource-expert/powerdns-shell-wrapper/blob/dev-override-cmd-line/pdns_zone.py#L81"
        class="https">https://github.com/opensource-expert/powerdns-shell-wrapper/blob/dev-override-cmd-line/pdns_zone.py#L81</a>
    </p>
    <p>
      <tt>r = requests.get(call_url, headers=headers)</tt><br>
      […]<br>
      <tt>return r.text</tt>
    </p>
    <p>
      And my test call it that way:
    </p>
    <p>
      <tt>r = p.exec_pdns_api('GET', rest_url)</tt>
    </p>
    <p>
      So <tt>r </tt>becomes a returned value of a requests call, the
      MagickMock object is reflecting that:
    </p>
    <p>
      &gt;&gt; how to I make an assertion that the r.text has been
      called/returned?<br>
      &gt;&gt; r is <tt>&lt;MagicMock name='get().text'
        id='139703066450704'&gt;</tt>
    </p>
    <p>
      What assertion can I use on such object in fact?
    </p>
    <p>
      Regards,<br>
      Sylvain.<br>
      -- <br>
      Sylvain Viart - DevOps système linux - freelance developer
    </p>
    <meta name="Description" content="Copy-Paste Buffer">
    <meta name="Generator" content="Zim">
  </body>
</html>