class TestAPP(unittest.TestCase): """ The class inherits from unittest """ def setUp(self): """ This method is called before each test """ self.httpObj = HTTPClass() def tearDown(self): """ This method is called after each test """ pass def test_http_response_class(self): with self.assertRaises(Exception) as context: self.httpObj.getResponseStatus(DumyClass) def test_http_response_content_exception_when_url_and_interval_is_empty(self): with self.assertRaises(Exception) as context: self.httpObj.getContent(url="", interval="") def test_http_response_content_exception_when_interval_is_empty(self): with self.assertRaises(Exception) as context: self.httpObj.getContent(url="http://www.google.com", interval="") def test_http_response_content_exception_when_url_is_empty(self): with self.assertRaises(Exception) as context: self.httpObj.getContent(url="", interval=20)
class LoadEvent: def __init__(self, xmlFileName="configuration/config.xml"): self.myhttp = HTTPClass(xmlFileName) #create the HTTP object def logEvents(self, filename="logFolder/log.txt"): #save content of monitorObjList to a log file logfile = open(filename, 'a') #append the file to prevent overwriting for monObj in self.myhttp.getResponses(): #write to file in the order of response object, duration, url, current time, result code wordString = "{0} | {1} | {2} | {3} | {4}\n".format( monObj[0], monObj[1], monObj[2], monObj[3], monObj[4]) logfile.write(wordString) logfile.close() def getCheckingPeriod(self): return self.myhttp.getCheckingPeriod()
class LoadEvent: def __init__(self , xmlFileName = "config.xml"): self.myhttp = HTTPClass(xmlFileName) #create the HTTP object self.monitorObjList = self.myhttp.checkedContent() #get complete response object def fillMonitorModel(self): for monObj in self.monitorObjList: mObj = Monitor(url = monObj[2], httpStatus = monObj[0], responseTime = monObj[1], contentStatus = monObj[5]) mObj.save() def logEvents(self, filename = "logFolder/log.txt"): #save content of monitorObjList to a log file logfile = open(filename, 'a') #append the file to prevent overwriting for monObj in self.monitorObjList: #write to file in the order of url, httpStatus, responseTime, currrent time stamp , contentStatus wordString = "{0} | {1} | {2} | {3} | {4}\n".format(monObj[2], monObj[0], monObj[1], monObj[4], self.__setyesNo(monObj[5])) logfile.write(wordString) logfile.close() def __setyesNo(self, value): if value: return 'Yes' else: return 'No'
def __init__(self, xmlFileName="configuration/config.xml"): self.myhttp = HTTPClass(xmlFileName) #create the HTTP object
def __init__(self , xmlFileName = "config.xml"): self.myhttp = HTTPClass(xmlFileName) #create the HTTP object self.monitorObjList = self.myhttp.checkedContent() #get complete response object
# Initialize variables filename = "data/urls.json" # Read JSON data into the urls variable with open(filename, 'r') as f: try: urls = json.load(f) except Exception as e: print("got exception {e}".format(e=e)) minBatch = 10 # use a heuristics to prevent undersized batches from being used numOfBatches = min(minBatch, (int(len(urls) / minBatch) + 1)) httpObj = HTTPClass() MAXTIME = 1000 # account for possible network latency MININTERVAL = 60 # I minute def scrapWeb(url, interval, tol=5): """ scrabing the url """ print('Starting %s' % url) before = time.time() try: # tol is slackness on timeout httpObj.getContent(url, interval=interval - tol) except Exception as e: print("got exception {e}".format(e=e))
def setUp(self): """ This method is called before each test """ self.httpObj = HTTPClass()