From c60142efda817f030a7495cd6fe4a19953e55afa Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 21 May 2013 13:40:27 +0200 Subject: Make an ipa-tests package Rename the 'tests' directory to 'ipa-tests', and create an ipa-tests RPM containing the test suite Part of the work for: https://fedorahosted.org/freeipa/ticket/3654 --- ipatests/test_ipaserver/httptest.py | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 ipatests/test_ipaserver/httptest.py (limited to 'ipatests/test_ipaserver/httptest.py') diff --git a/ipatests/test_ipaserver/httptest.py b/ipatests/test_ipaserver/httptest.py new file mode 100644 index 00000000..7f1b5b13 --- /dev/null +++ b/ipatests/test_ipaserver/httptest.py @@ -0,0 +1,52 @@ +# Authors: +# Martin Kosek +# +# Copyright (C) 2012 Red Hat +# see file 'COPYING' for use and warranty information +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +""" +Base class for HTTP request tests +""" + +import urllib +import httplib + +from ipalib import api + +class Unauthorized_HTTP_test(object): + """ + Base class for simple HTTP request tests executed against URI + with no required authorization + """ + app_uri = '' + host = api.env.host + content_type = 'application/x-www-form-urlencoded' + + def send_request(self, method='POST', params=None): + """ + Send a request to HTTP server + + :param key When not None, overrides default app_uri + """ + if params is not None: + params = urllib.urlencode(params, True) + url = 'https://' + self.host + self.app_uri + + headers = {'Content-Type' : self.content_type, + 'Referer' : url} + + conn = httplib.HTTPSConnection(self.host) + conn.request(method, self.app_uri, params, headers) + return conn.getresponse() -- cgit