2 # Copyright 2010 Google Inc. All Rights Reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 """Mock instance of ArchivedHttpRequest used for testing."""
19 class ArchivedHttpRequest(object):
20 """Mock instance of ArchivedHttpRequest in HttpArchive."""
22 def __init__(self
, command
, host
, path
, request_body
, headers
):
23 """Initialize an ArchivedHttpRequest.
26 command: a string (e.g. 'GET' or 'POST').
27 host: a host name (e.g. 'www.google.com').
28 path: a request path (e.g. '/search?q=dogs').
29 request_body: a request body string for a POST or None.
30 headers: [(header1, value1), ...] list of tuples
32 self
.command
= command
35 self
.request_body
= request_body
36 self
.headers
= headers
37 self
.trimmed_headers
= headers
40 return '%s %s%s %s' % (self
.command
, self
.host
, self
.path
,
44 return repr((self
.command
, self
.host
, self
.path
, self
.request_body
,
45 self
.trimmed_headers
))
48 """Return a integer hash to use for hashed collections including dict."""
49 return hash(repr(self
))
51 def __eq__(self
, other
):
52 """Define the __eq__ method to match the hash behavior."""
53 return repr(self
) == repr(other
)
55 def matches(self
, command
=None, host
=None, path
=None):
56 """Returns true iff the request matches all parameters."""
57 return ((command
is None or command
== self
.command
) and
58 (host
is None or host
== self
.host
) and
59 (path
is None or path
== self
.path
))