diff options
Diffstat (limited to 'service/test/support/test_helper.py')
-rw-r--r-- | service/test/support/test_helper.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/service/test/support/test_helper.py b/service/test/support/test_helper.py index ff1de64a..54685008 100644 --- a/service/test/support/test_helper.py +++ b/service/test/support/test_helper.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. from datetime import datetime +import io from pixelated.adapter.model.mail import InputMail @@ -79,3 +80,26 @@ class TestRequest: def __init__(self, json): self.json = json + + +from twisted.web.test.test_web import DummyRequest + + +class PixRequestMock(DummyRequest): + def __init__(self, path): + DummyRequest.__init__(self, path) + self.content = None + self.code = None + + def getWrittenData(self): + if len(self.written): + return self.written[0] + + +def request_mock(path='', method='GET', body='', headers={}): + dummy = PixRequestMock(path.split('/')) + for name, value in headers.iteritems(): + dummy.setHeader(name, value) + dummy.method = method + dummy.content = io.BytesIO(body) + return dummy |