#format python # ---- AT_BookSearch.py ---- import unittest import httplib, urllib DEFAULT_HEADER = {"Content-Type":"application/x-www-form-urlencoded", "Referer":"http://165.194.100.2/cgi-bin/mcu100?LIBRCODE=ATSL&USERID=*&SYSDB=R", "Accept":"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*"} DEFAULT_SERVICE_IP = "165.194.17.56" DEFAULT_SERVICE_PORT = 8080 DEFAULT_SERVICE_SIMPLE_PATH = "/servlet/SimpleSearch" DEFAULT_SERVICE_ADVANCED_PATH = "/servlet/AdvancedSearch" def getSimpleSearchResponse(params): params=urllib.urlencode(params) conn = httplib.HTTPConnection(DEFAULT_SERVICE_IP, DEFAULT_SERVICE_PORT) conn.request("POST", DEFAULT_SERVICE_SIMPLE_PATH, params, DEFAULT_HEADER) response = conn.getresponse() print response.status, response.reason data = response.read() conn.close() return data def getAdvancedSearchResponse(params): params=urllib.urlencode(params) conn = httplib.HTTPConnection(DEFAULT_SERVICE_IP, DEFAULT_SERVICE_PORT) conn.request("POST", DEFAULT_SERVICE_ADVANCED_PATH, params, DEFAULT_HEADER) response = conn.getresponse() print response.status, response.reason data = response.read() conn.close() return data class TestAdvancedSearch(unittest.TestCase): def testOne(self): params = {'TI':'Test', 'AU':'', 'IB':'', 'PU':'', 'OP1':'','OP2':'','OP3':''} data = getAdvancedSearchResponse(params) self.assert_(data.count("") > 70) def testKorean(self): params = {'TI':'', 'AU':'김소월', 'IB':'', 'PU':'', 'OP1':'','OP2':'','OP3':''} data = getAdvancedSearchResponse(params) self.assert_(data.count("") > 10) def testKoreanTwo(self): params = {'TI':'한글', 'AU':'', 'IB':'', 'PU':'', 'OP1':'','OP2':'','OP3':''} data = getAdvancedSearchResponse(params) self.assert_(data.count("") > 10) class TestSimpleSearch(unittest.TestCase): def testOne(self): params = {'keyword':'한글'} data = getSimpleSearchResponse(params) self.assert_(data.count("") > 10) def testIsbn(self): params = {'keyword':'897087223X'} data = getSimpleSearchResponse(params) self.assert_(data.count("김불꾼") > 0) def testKoreanAndNumber(self): params = {'keyword':'한글3'} data = getSimpleSearchResponse(params) self.assert_(data.count("") > 10) def testKoreanAndNumberWithSpace(self): params = {'keyword':'한글 3'} data = getSimpleSearchResponse(params) self.assert_(data.count("") > 10) if __name__=="__main__": unittest.main(argv=('','-v'))