1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module atom.mock_service</title>
</head><body bgcolor="#f0f0f8">
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="atom.html"><font color="#ffffff">atom</font></a>.mock_service</strong></big></big></font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/usr/local/svn/gdata-python-client/src/atom/mock_service.py">/usr/local/svn/gdata-python-client/src/atom/mock_service.py</a></font></td></tr></table>
<p><tt>MockService provides CRUD ops. for mocking calls to AtomPub services.<br>
<br>
MockService: Exposes the publicly used methods of AtomService to provide<br>
a mock interface which can be used in unit tests.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
<tr><td bgcolor="#aa55cc"><tt> </tt></td><td> </td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="atom.html">atom</a><br>
</td><td width="25%" valign=top><a href="pickle.html">pickle</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="atom.mock_service.html#MockHttpResponse">MockHttpResponse</a>
</font></dt><dt><font face="helvetica, arial"><a href="atom.mock_service.html#MockRequest">MockRequest</a>
</font></dt></dl>
</dd>
</dl>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="MockHttpResponse">class <strong>MockHttpResponse</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Returned from MockService crud methods as the server's response.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="MockHttpResponse-__init__"><strong>__init__</strong></a>(self, body<font color="#909090">=None</font>, status<font color="#909090">=None</font>, reason<font color="#909090">=None</font>, headers<font color="#909090">=None</font>)</dt><dd><tt>Construct a mock HTTPResponse and set members.<br>
<br>
Args:<br>
body: str (optional) The HTTP body of the server's response. <br>
status: int (optional) <br>
reason: str (optional)<br>
headers: dict (optional)</tt></dd></dl>
<dl><dt><a name="MockHttpResponse-getheader"><strong>getheader</strong></a>(self, header_name)</dt></dl>
<dl><dt><a name="MockHttpResponse-read"><strong>read</strong></a>(self)</dt></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
</td></tr></table> <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><a name="MockRequest">class <strong>MockRequest</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>Represents a request made to an AtomPub server.<br>
<br>
These objects are used to determine if a client request matches a recorded<br>
HTTP request to determine what the mock server's response will be.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="MockRequest-ConcealSecrets"><strong>ConcealSecrets</strong></a>(self, conceal_func)</dt><dd><tt>Conceal secret data in this request.</tt></dd></dl>
<dl><dt><a name="MockRequest-IsMatch"><strong>IsMatch</strong></a>(self, other_request)</dt><dd><tt>Check to see if the other_request is equivalent to this request.<br>
<br>
Used to determine if a recording matches an incoming request so that a<br>
recorded response should be sent to the client.<br>
<br>
The matching is not exact, only the operation and URL are examined <br>
currently.<br>
<br>
Args:<br>
other_request: <a href="#MockRequest">MockRequest</a> The request which we want to check this<br>
(self) <a href="#MockRequest">MockRequest</a> against to see if they are equivalent.</tt></dd></dl>
<dl><dt><a name="MockRequest-__init__"><strong>__init__</strong></a>(self, operation, uri, host<font color="#909090">=None</font>, ssl<font color="#909090">=False</font>, port<font color="#909090">=None</font>, data<font color="#909090">=None</font>, extra_headers<font color="#909090">=None</font>, url_params<font color="#909090">=None</font>, escape_params<font color="#909090">=True</font>, content_type<font color="#909090">='application/atom+xml'</font>)</dt><dd><tt>Constructor for a <a href="#MockRequest">MockRequest</a><br>
<br>
Args:<br>
operation: str One of 'GET', 'POST', 'PUT', or 'DELETE' this is the<br>
HTTP operation requested on the resource.<br>
uri: str The URL describing the resource to be modified or feed to be<br>
retrieved. This should include the protocol (http/https) and the host<br>
(aka domain). For example, these are some valud full_uris:<br>
'<a href="http://example.com">http://example.com</a>', 'https://www.google.com/accounts/ClientLogin'<br>
host: str (optional) The server name which will be placed at the <br>
beginning of the URL if the uri parameter does not begin with 'http'.<br>
Examples include 'example.com', 'www.google.com', 'www.blogger.com'.<br>
ssl: boolean (optional) If true, the request URL will begin with https <br>
instead of http.<br>
data: ElementTree, filestream, list of parts, or other <a href="__builtin__.html#object">object</a> which can be<br>
converted to a string. (optional)<br>
Should be set to None when performing a GET or PUT.<br>
If data is a file-like <a href="__builtin__.html#object">object</a> which can be read, the constructor <br>
will read the entire file into memory. If the data is a list of <br>
parts to be sent, each part will be evaluated and stored.<br>
extra_headers: dict (optional) HTTP headers included in the request.<br>
url_params: dict (optional) Key value pairs which should be added to <br>
the URL as URL parameters in the request. For example uri='/', <br>
url_parameters={'foo':'1','bar':'2'} could become '/?foo=1&bar=2'.<br>
escape_params: boolean (optional) Perform URL escaping on the keys and <br>
values specified in url_params. Defaults to True.<br>
content_type: str (optional) Provides the MIME type of the data being <br>
sent.</tt></dd></dl>
<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary for instance variables (if defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list of weak references to the object (if defined)</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#eeaa77">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
<td width="100%"><dl><dt><a name="-ConcealValueWithSha"><strong>ConcealValueWithSha</strong></a>(source)</dt></dl>
<dl><dt><a name="-DumpRecordings"><strong>DumpRecordings</strong></a>(conceal_func<font color="#909090">=<function ConcealValueWithSha at 0x7faf3dee4c08></font>)</dt></dl>
<dl><dt><a name="-HttpRequest"><strong>HttpRequest</strong></a>(service, operation, data, uri, extra_headers<font color="#909090">=None</font>, url_params<font color="#909090">=None</font>, escape_params<font color="#909090">=True</font>, content_type<font color="#909090">='application/atom+xml'</font>)</dt><dd><tt>Simulates an HTTP call to the server, makes an actual HTTP request if <br>
real_request_handler is set.<br>
<br>
This function operates in two different modes depending on if <br>
real_request_handler is set or not. If real_request_handler is not set,<br>
HttpRequest will look in this module's recordings list to find a response<br>
which matches the parameters in the function call. If real_request_handler<br>
is set, this function will call real_request_handler.HttpRequest, add the<br>
response to the recordings list, and respond with the actual response.<br>
<br>
Args:<br>
service: atom.AtomService <a href="__builtin__.html#object">object</a> which contains some of the parameters<br>
needed to make the request. The following members are used to<br>
construct the HTTP call: server (str), additional_headers (dict),<br>
port (int), and ssl (bool).<br>
operation: str The HTTP operation to be performed. This is usually one of<br>
'GET', 'POST', 'PUT', or 'DELETE'<br>
data: ElementTree, filestream, list of parts, or other <a href="__builtin__.html#object">object</a> which can be<br>
converted to a string.<br>
Should be set to None when performing a GET or PUT.<br>
If data is a file-like <a href="__builtin__.html#object">object</a> which can be read, this method will read<br>
a chunk of 100K bytes at a time and send them.<br>
If the data is a list of parts to be sent, each part will be evaluated<br>
and sent.<br>
uri: The beginning of the URL to which the request should be sent.<br>
Examples: '/', '/base/feeds/snippets',<br>
'/m8/feeds/contacts/default/base'<br>
extra_headers: dict of strings. HTTP headers which should be sent<br>
in the request. These headers are in addition to those stored in<br>
service.additional_headers.<br>
url_params: dict of strings. Key value pairs to be added to the URL as<br>
URL parameters. For example {'foo':'bar', 'test':'param'} will<br>
become ?foo=bar&test=param.<br>
escape_params: bool default True. If true, the keys and values in<br>
url_params will be URL escaped when the form is constructed<br>
(Special characters converted to %XX form.)<br>
content_type: str The MIME type for the data being sent. Defaults to<br>
'application/atom+xml', this is only used if data is set.</tt></dd></dl>
<dl><dt><a name="-LoadRecordings"><strong>LoadRecordings</strong></a>(recordings_file_or_string)</dt></dl>
</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
<td width="100%"><strong>__author__</strong> = 'api.jscudder (Jeffrey Scudder)'<br>
<strong>real_request_handler</strong> = None<br>
<strong>recordings</strong> = []</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom> <br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
<tr><td bgcolor="#7799ee"><tt> </tt></td><td> </td>
<td width="100%">api.jscudder (Jeffrey Scudder)</td></tr></table>
</body></html>
|