<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<p>
Hi,
</p>
<p>
I writing a command line wrapper for managing powerdns via its
RESTÂ interface.
</p>
<p>
I'm now refactoring my proof of concept to a full python script.
I'm using <tt>requests</tt> library to communicate the Json code
build by my python class. I'm adding unittest to ensure no
regression, from first bash + jq + python + json + jinja2 + yaml
version.
</p>
<p>
I'm having trouble to understand how to use correctly mock object
to test correctness of requests' call and also returned object.
</p>
<p>
I'm using <tt>py.test</tt> + <tt>pytest-mock</tt>
</p>
<p>
I would like to test here that <tt>r.text</tt> is returned if I
call:<br>
</p>
<div style="padding-left: 30pt">
<tt>r = p.exec_pdns_api('GET', rest_url, text=True)</tt>
</div>
<a
href="https://github.com/opensource-expert/powerdns-shell-wrapper/blob/dev-override-cmd-line/pdns_zone.py#L79"
title="https://github.com/opensource-expert/powerdns-shell-wrapper/blob/dev-override-cmd-line/pdns_zone.py#L79"
class="https">https://github.com/opensource-expert/powerdns-shell-wrapper/blob/dev-override-cmd-line/pdns_zone.py#L79</a>
<p>
how to I make an assertion that the <tt>r.text</tt> has been
called/returned?
</p>
<p>
r is <tt><MagicMock name='get().text' id='139703066450704'></tt>
</p>
<p>
<tt>r.text.assert_called() </tt>is not the good assertion<br>
test code here: <a
href="https://github.com/opensource-expert/powerdns-shell-wrapper/blob/dev-override-cmd-line/test/test_pdns_zone.py#L40">https://github.com/opensource-expert/powerdns-shell-wrapper/blob/dev-override-cmd-line/test/test_pdns_zone.py#L40</a><br>
</p>
<p>
I may using a wrong way of testing it… Any hint would be
appreciated.
</p>
<p>
Regards,<br>
Sylvain.
</p>
<meta name="Description" content="Copy-Paste Buffer">
<meta name="Generator" content="Zim">
</body>
</html>