1# #!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# <HTTPretty - HTTP client mock for Python>
4# Copyright (C) <2011-2021> Gabriel Falcão <gabriel@nacaolivre.org>
5#
6# Permission is hereby granted, free of charge, to any person
7# obtaining a copy of this software and associated documentation
8# files (the "Software"), to deal in the Software without
9# restriction, including without limitation the rights to use,
10# copy, modify, merge, publish, distribute, sublicense, and/or sell
11# copies of the Software, and to permit persons to whom the
12# Software is furnished to do so, subject to the following
13# conditions:
14#
15# The above copyright notice and this permission notice shall be
16# included in all copies or substantial portions of the Software.
17#
18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25# OTHER DEALINGS IN THE SOFTWARE.
26# flake8: noqa
27
28
29from . import core
30
31from .core import httpretty, httprettified, EmptyRequestHeaders
32from .core import set_default_thread_timeout, get_default_thread_timeout
33from .errors import HTTPrettyError, UnmockedError
34from .version import version
35
36__version__ = version
37
38# aliases
39EmptyRequestHeaders = core.EmptyRequestHeaders
40Entry = core.Entry
41HTTPrettyRequestEmpty = core.HTTPrettyRequestEmpty
42URIInfo = core.URIInfo
43URIMatcher = core.URIMatcher
44httprettified = core.httprettified
45httprettized = core.httprettized
46httpretty = core.httpretty
47
48HTTPretty = httpretty
49activate = httprettified
50
51enabled = httprettized
52
53enable = httpretty.enable
54register_uri = httpretty.register_uri
55disable = httpretty.disable
56is_enabled = httpretty.is_enabled
57reset = httpretty.reset
58Response = httpretty.Response
59
60GET = httpretty.GET
61"""Match requests of GET method"""
62PUT = httpretty.PUT
63"""Match requests of PUT method"""
64POST = httpretty.POST
65"""Match requests of POST method"""
66DELETE = httpretty.DELETE
67"""Match requests of DELETE method"""
68HEAD = httpretty.HEAD
69"""Match requests of HEAD method"""
70PATCH = httpretty.PATCH
71"""Match requests of OPTIONS method"""
72OPTIONS = httpretty.OPTIONS
73"""Match requests of OPTIONS method"""
74CONNECT = httpretty.CONNECT
75"""Match requests of CONNECT method"""
76
77
78def last_request():
79 """
80 :returns: the last :py:class:`~httpretty.core.HTTPrettyRequest`
81 """
82 return httpretty.last_request
83
84
85def latest_requests():
86 """returns the history of made requests"""
87 return httpretty.latest_requests
88
89
90def has_request():
91 """
92 :returns: bool - whether any request has been made
93 """
94 return not isinstance(httpretty.last_request.headers, EmptyRequestHeaders)