"""Unit test for the sampling algorithm $Id: test.py 803 2008-12-03 12:08:26Z goodwin $ """ # Copyright 2008-2011 eGovMon # This program is distributed under the terms of the GNU General # Public License. # # This file is part of the eGovernment Monitoring # (eGovMon) # # eGovMon 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 2 of the License, or # (at your option) any later version. # # eGovMon 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 eGovMon; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301 USA __author__ = "$Author: goodwin $" __version__ = "$Revision: 803 $" __updated__ = "$LastChangedDate$" import os import unittest, doctest import psycopg2 import sc import MySQLdb result = [] from samplingfunctions import * import samplingfunctions import random class TestSequenceFunctions(unittest.TestCase): def setUp(self): reload(samplingfunctions) from egovmondb import eGovMonDB self.egovmondb= eGovMonDB() def testrunningpdf(self): import sc sc = sc.SystemConfiguration() domain = 'www.egovmon.no' testrunid = '1' #Setup towards URL repositoriy con = psycopg2.connect(host=sc.egovmondbhost,user=sc.egovmondbusername,database=sc.egovmondbdatabase,password=sc.egovmondbpassword) cur = con.cursor() site,title,source,coverage,category,testrunid = 'www.egovmon.no','eGovernment Monitoring','maintainer@egovmon.no','','','1' self.egovmondb.currentTestRun = testrunid cur.execute("insert into egovmondb.testrun (testrunid,started,responsible,urllistid) select %(testrunid)s,timestamp 'now',%(source)s,1 where not exists (select True from egovmondb.testrun where testrunid = %(testrunid)s);",locals()) con.commit() cur.execute('insert into egovmondb.WebSite (site,title) select %(site)s,%(title)s where not exists (select True from egovmondb.WebSite where site=%(site)s);',locals()) cur.execute('update egovmondb.WebSite set smallsite=True where site=%(site)s;',locals()) cur.execute('delete from egovmondb.SitePDFResults where siteid in (select siteid from website where site=%(site)s) and testrunid=%(testrunid)s;',locals()) cur.execute('insert into egovmondb.SitePDFResults (siteid,testrunid) select (select siteid from website where site=%(site)s),%(testrunid)s;',locals()) cur.execute('delete from WebPage where siteid in (select siteid from website where site=%(site)s) and testrunid=%(testrunid)s;',locals()) con.commit() #Checking that the eGovMonDB is empty. cur.execute('select count(*) from WebPage where siteid in (select siteid from website where site=%(site)s) and testrunid=%(testrunid)s;',locals()) self.assert_(cur.fetchall()[0][0]==0) pages = [ {'url':'http://www.egovmon.no/upload/downloads/folder_egovmon_org.pdf'}, {'url':'http://www.egovmon.no/upload/downloads/d211-final-v11-no.pdf'}, {'url':'http://www.egovmon.no/upload/downloads/d411-final.pdf'}, {'url':'http://www.egovmon.no/upload/downloads/eiao_publishable-activity-report-final-2008-09-04.pdf'} ] for page in pages: page['site'] = 'www.egovmon.no' page['contenttype'] = 'PDF' self.egovmondb.writeAllScenarios(pages) os.system('sampler %(domain)s %(testrunid)s PDF'%locals()) #Checking that data is there cur.execute('select sitescore from SitePDFResults natural join WebSite where testrunid=%(testrunid)s and site=%(site)s;',locals()) cur.fetchall()[0][0] cur.execute('select endchecktime from SitePDFResults natural join WebSite where testrunid=%(testrunid)s and site=%(site)s;',locals()) self.assert_(cur.fetchall()[0][0]) #checking QA data #cur.execute('select stddev,siteaverage,crawlercount,successfullchecks,numberoftests,numberofpassedtests from siteqa natural join site where testrunid=%(testrunid)s and site=%(site)s;',locals()) #stddev,siteaverage,crawlercount,successfullchecks,numberoftests,numberofpassedtests = cur.fetchall()[0] #self.assert_(stddev) #self.assert_(siteaverage) #self.assert_(crawlercount) #self.assert_(successfullchecks) #self.assert_(numberoftests) #self.assert_(numberofpassedtests) def testrunningmobileok(self): import sc sc = sc.SystemConfiguration() domain = 'www.egovmon.no' testrunid = '1' #Setup towards URL repositoriy con = psycopg2.connect(host=sc.egovmondbhost,user=sc.egovmondbusername,database=sc.egovmondbdatabase,password=sc.egovmondbpassword) cur = con.cursor() site,title,source,coverage,category,testrunid = 'www.egovmon.no','eGovernment Monitoring','maintainer@egovmon.no','','','1' self.egovmondb.currentTestRun = testrunid cur.execute("insert into egovmondb.testrun (testrunid,started,responsible,urllistid) select %(testrunid)s,timestamp 'now',%(source)s,1 where not exists (select True from egovmondb.testrun where testrunid = %(testrunid)s);",locals()) con.commit() cur.execute('insert into egovmondb.WebSite (site,title) select %(site)s,%(title)s where not exists (select True from egovmondb.WebSite where site=%(site)s);',locals()) cur.execute('update egovmondb.WebSite set smallsite=True where site=%(site)s;',locals()) cur.execute('delete from egovmondb.SiteMobileOKResults where siteid in (select siteid from website where site=%(site)s) and testrunid=%(testrunid)s;',locals()) cur.execute("insert into egovmondb.SiteMobileOKResults (siteid,testrunid,startchecktime) select (select siteid from website where site=%(site)s),%(testrunid)s,timestamp 'now';",locals()) cur.execute('delete from WebPage where siteid in (select siteid from website where site=%(site)s) and testrunid=%(testrunid)s;',locals()) con.commit() #Checking that the eGovMonDB is empty. cur.execute('select count(*) from WebPage where siteid in (select siteid from website where site=%(site)s) and testrunid=%(testrunid)s;',locals()) self.assert_(cur.fetchall()[0][0]==0) pages = [ {'url':'http://www.egovmon.no/en/'}, {'url':'http://www.egovmon.no/en/research/indicators/efficiency/'}, {'url':'http://www.egovmon.no/en/research/'}, {'url':'http://www.egovmon.no/en/research/indicators/impact/'}, {'url':'http://www.egovmon.no/en/research/large_scale_benchmarking/'}, {'url':'http://www.egovmon.no/en/research/indicators/accessibility/'}, {'url':'http://www.egovmon.no/en/research/indicators/transparency/'}, {'url':'http://www.egovmon.no/en/research/policy_design_tool/'}, {'url':'http://www.egovmon.no/en/partners/'}, {'url':'http://www.egovmon.no/en/partners/municipalities/'}, {'url':'http://www.egovmon.no/en/research/background/'} ] for page in pages: page['site'] = 'www.egovmon.no' page['contenttype'] = 'MobileOK' self.egovmondb.writeAllScenarios(pages) os.system('sampler %(domain)s %(testrunid)s MobileOK'%locals()) #Checking that data is there cur.execute('select sitescore from SiteMobileOKResults natural join WebSite where testrunid=%(testrunid)s and site=%(site)s;',locals()) cur.fetchall()[0][0] cur.execute('select endchecktime from SiteMobileOKResults natural join WebSite where testrunid=%(testrunid)s and site=%(site)s;',locals()) self.assert_(cur.fetchall()[0][0]) def testrunninghtml(self): import sc sc = sc.SystemConfiguration() domain = 'www.egovmon.no' testrunid = '1' #Setup towards URL repositoriy con = psycopg2.connect(host=sc.egovmondbhost,user=sc.egovmondbusername,database=sc.egovmondbdatabase,password=sc.egovmondbpassword) cur = con.cursor() site,title,source,coverage,category,testrunid = 'www.egovmon.no','eGovernment Monitoring','maintainer@egovmon.no','','','1' self.egovmondb.currentTestRun = testrunid cur.execute("insert into egovmondb.testrun (testrunid,started,responsible,urllistid) select %(testrunid)s,timestamp 'now',%(source)s,1 where not exists (select True from egovmondb.testrun where testrunid = %(testrunid)s);",locals()) con.commit() cur.execute('insert into egovmondb.WebSite (site,title) select %(site)s,%(title)s where not exists (select True from egovmondb.WebSite where site=%(site)s);',locals()) cur.execute('update egovmondb.WebSite set smallsite=True where site=%(site)s;',locals()) cur.execute('delete from egovmondb.SiteWAMResults where siteid in (select siteid from website where site=%(site)s) and testrunid=%(testrunid)s;',locals()) cur.execute('insert into egovmondb.SiteWAMResults (siteid,testrunid) select (select siteid from website where site=%(site)s),%(testrunid)s;',locals()) cur.execute('delete from WebPage where siteid in (select siteid from website where site=%(site)s) and testrunid=%(testrunid)s;',locals()) con.commit() #Checking that the eGovMonDB is empty. cur.execute('select count(*) from WebPage where siteid in (select siteid from website where site=%(site)s) and testrunid=%(testrunid)s;',locals()) self.assert_(cur.fetchall()[0][0]==0) pages = [ {'url':'http://www.egovmon.no/en/'}, {'url':'http://www.egovmon.no/en/research/indicators/efficiency/'}, {'url':'http://www.egovmon.no/en/research/'}, {'url':'http://www.egovmon.no/en/contact/'}, {'url':'http://www.egovmon.no/en/research/indicators/impact/'}, {'url':'http://www.egovmon.no/en/research/large_scale_benchmarking/'}, {'url':'http://www.egovmon.no/en/research/indicators/accessibility/'}, {'url':'http://www.egovmon.no/en/research/indicators/transparency/'}, {'url':'http://www.egovmon.no/en/research/policy_design_tool/'}, {'url':'http://www.egovmon.no/en/partners/'}, {'url':'http://www.egovmon.no/en/partners/municipalities/'}, {'url':'http://www.egovmon.no/en/research/background/'} ] for page in pages: page['site'] = 'www.egovmon.no' page['contenttype'] = 'HTML' self.egovmondb.writeAllScenarios(pages) os.system('sampler %(domain)s %(testrunid)s HTML'%locals()) #Checking that data is there cur.execute('select sitescore from site where testrunid=%(testrunid)s and site=%(site)s;',locals()) cur.fetchall()[0][0] cur.execute('select endchecktime from site where testrunid=%(testrunid)s and site=%(site)s;',locals()) self.assert_(cur.fetchall()[0][0]) #checking QA data cur.execute('select stddev,siteaverage,crawlercount,successfullchecks,numberoftests,numberofpassedtests from siteqa natural join site where testrunid=%(testrunid)s and site=%(site)s;',locals()) stddev,siteaverage,crawlercount,successfullchecks,numberoftests,numberofpassedtests = cur.fetchall()[0] #self.assert_(stddev) #self.assert_(siteaverage) self.assert_(crawlercount) self.assert_(successfullchecks) self.assert_(numberoftests) self.assert_(numberofpassedtests) if __name__=="__main__": unittest.main()