Hi Guys ,
I have a class with 2 methods, and a test class I want to run in order to test this class.
The class looks as follows:
Code:
import httplib;
import urllib;
class FormHelper:
def __init__(self):
return;
'''
This method can be used to submit a form as part of an availibility check.
Pass it the host, path of the POST request and a set of params in the form 'spam':2,'param2':"lol" and it will
return you the data response
'''
def submitForm(self,host,path,params ):
params = urllib.urlencode({'spam': "1", 'eggs': 2, 'bacon': 0});
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"};
conn = httplib.HTTPConnection(host+":80");
conn.request("POST", path, params, headers);
response = conn.getresponse();
print response.status, response.reason;
data = response.read();
conn.close();
return data;
'''
This method can be used to grab a page as part of any activity
Pass it the host, path of the URL you want and it will return you the page's content
'''
def getPage(self,host,path):
conn = httplib.HTTPConnection(host)
conn.request("GET", path)
r1 = conn.getresponse()
print r1.status, r1.reason
data1 = r1.read()
conn.close()
return data1;
The test looks as follows:
Code:
from UtilityCode import FormHelper
if __name__ == '__main__':
formHelper = FormHelper();
data = formHelper
print data;
Now what im trying to do in the test code is data = formHelper.getPage("firsparm","secondparm");
but it wont let me - what am I doing wrong!?