Esempio n. 1
0
 def testKnownText( self ):
     """ SdeSkemaScraper : use known data to get known result """
     parser = SdeSkemaScraper()
     parser.feed( SimpleSkemaData )
     parser.close()
     self.assertEqual(len( parser.Appointments ), len(SimpleSkemaDataResult))
     self.assertEqual(parser.Appointments , SimpleSkemaDataResult)  
Esempio n. 2
0
 def testWebPageInput5weeks(self):
     """ SdeSkemaScraper : use webpage source from webgetter - 5 weeks """
     parser = SdeSkemaScraper(DateFormat = "%d-%m-%Y")
     parser.feed( WebPageFromHtmlGetter43_48_72lektioner )
     parser.close()
     i = len(parser.Appointments)
     self.assertEqual(i,72)
     pass
Esempio n. 3
0
 def testDateAndDateFromHours(self):
     """ SdeSkemaScraper : Compare 'date' with date from 'hours' """
     parser = SdeSkemaScraper(DateFormat = "%d-%m-%Y")
     parser.feed( WebPageFromChrome43_43_19lektioner )
     parser.close()
     for app in parser.Appointments:
         self.assertEqual( app['Hours'][0].date(), app['Date'] )
     pass
Esempio n. 4
0
 def testWebPageInput1week_c(self):
     """ SdeSkemaScraper : use webpage source from chrome - 1 week """
     parser = SdeSkemaScraper(DateFormat = "%d-%m-%Y")
     parser.feed( WebPageFromChrome43_43_19lektioner )
     parser.close()
     i = len(parser.Appointments)
     self.assertEqual(i,19)
     pass
Esempio n. 5
0
 def testKnownTextBadChars( self ):
     """ SdeSkemaScraper : use known data to get known result (including øæå) """
     parser = SdeSkemaScraper()
     parser.feed( SkemaDataBadChars )
     parser.close()
     self.assertEqual(len( parser.Appointments ), len(SkemaDataBadCharsResult))  
     
     for i in range(0, len( parser.Appointments ) ):
         self.assertEqual(parser.Appointments[i] , SkemaDataBadCharsResult[i])  
Esempio n. 6
0
 def testSdeSkemaIterator(self):
     """ SdeSkemaScraper : test iterator functionality """
     parser = SdeSkemaScraper()
     parser.feed(SimpleSkemaData)
     parser.close()
     
     i = 0
     for entry in SdeSkema( SimpleSkemaData ):
         self.assertEqual( entry, parser.Appointments[i] )
         i = i+1
Esempio n. 7
0
 def testGetSkemaWithPost_1(self):
     ''' HtmlGetter : do a POST 1 week'''
     myLoader = loadWeb.htmlGetter()
     try:
         self._htmlResponse = myLoader.getSkemaWithPost(3735, 43, 43, 2010)
     except IOError:
         self.fail("IOError. No internet?")
     parser = SdeSkemaScraper(DateFormat = "%d-%m-%Y")
     parser.feed( self._htmlResponse.read() )
     parser.close()
     i = len(parser.Appointments)
     self.assertEqual(i,19)
     pass
Esempio n. 8
0
 def testGetSkemaWithPost_2(self):
     ''' HtmlGetter : do a POST 5 weeks '''
     # TODO : can we change this into a static test? As it is now it requires net-access and fails if changes are made
     myLoader = loadWeb.htmlGetter()
     try:
         self._htmlResponse = myLoader.getSkemaWithPost(3735, 43, 48, 2010)
     except IOError:
         self.fail("IOError. No internet?")
     parser = SdeSkemaScraper(DateFormat = "%d-%m-%Y")
     parser.feed( self._htmlResponse.read() )
     parser.close()
     i = len(parser.Appointments)
     self.assertEqual(i,75)
     pass
Esempio n. 9
0
 def testGetSkemaWithPostWithSpecifiedYear(self):
     ''' HtmlGetter : do a POST 1 week with the year specified'''
     myLoader = loadWeb.htmlGetter()
     try:
         self._htmlResponse = myLoader.getSkemaWithPost(3735, 04, 04, 2011)
     except IOError:
         self.fail("IOError. No internet?")
     parser = SdeSkemaScraper(DateFormat = "%d-%m-%Y")
     parser.feed( self._htmlResponse.read() )
     parser.close()
     
     fp = open( Filename_pfl_2011_04, "r" )
     Filecontent = fp.read()
     fp.close()
     parser2 = SdeSkemaScraper(DateFormat = "%d-%m-%Y")
     parser2.feed( Filecontent )
     parser2.close()
     
     self.assertEqual(parser.Appointments, parser2.Appointments)
     pass
Esempio n. 10
0
def ImportSdeSkema( config, ConfigSet = "SkemaScraper" ):
    ''' Config parameters: TeacherId, FirstWeek, LastWeek, Year, InputDateformat, 
            Infile (if set, read from file)
    '''
    # read data from file or net
    if config.has_option(ConfigSet, "Infile"):
        Data = open(config.get(ConfigSet, "Infile")).read()
    else:
        myLoader = loadWeb.htmlGetter( config.get(ConfigSet, "Site") )
        Data = myLoader.getSkemaWithPost(config.get(ConfigSet, "TeacherId"), 
                                     config.get(ConfigSet, "FirstWeek"), 
                                     config.get(ConfigSet, "LastWeek"), 
                                     config.get(ConfigSet, "Year")).read()
                                     
    # and process data
    parser = SdeSkemaScraper( config.get(ConfigSet, "InputDateformat"),
                              Teacher = config.get(ConfigSet, "Teacher" ) )
    parser.feed( Data )
    parser.close()
    
    # TODO: Decide on name for this, Appointments or Events
    return  parser.Appointments 
Esempio n. 11
0
 def testNonTextData( self ):
     """ SdeSkemaScraper : use integer instead of text in parser """
     parser = SdeSkemaScraper()
     self.assertRaises(TypeError, parser.feed, 1)
     parser.close()
Esempio n. 12
0
 def testBogusTextData( self ):
     """ SdeSkemaScraper : use non-HTML text in parser """
     parser = SdeSkemaScraper()
     parser.feed("ThisHasNothingToDoWithHtml")
     parser.close()
     self.assertEqual(parser.Appointments , [])                  
Esempio n. 13
0
 def testEmptyData( self ):
     """ SdeSkemaScraper : use empty text in parser """
     parser = SdeSkemaScraper()
     parser.feed("")
     parser.close()
     self.assertEqual(parser.Appointments , [])