Changeset 3194


Ignore:
Timestamp:
Jun 21, 2006, 3:42:57 PM (18 years ago)
Author:
ole
Message:

More testing of flood database

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/demos/test_flood_database.py

    r3191 r3194  
    1010
    1111base_url = 'http://www.ga.gov.au:8500/oracle/flood/'
    12 
     12servlet_base_url = 'http://www.ga.gov.au:8500/'
    1313
    1414def test_site():
    15   """Test flood database
    16   """
     15    """Test flood database
     16    """
    1717 
    18   top_url = 'flood_input_hide.jsp'
     18    top_url = 'flood_input_hide.jsp'
    1919
    20   url = base_url+top_url
    21   live = False 
    22   print 'Trying to connect to %s' %url
    23   T = get_page(url)
     20    url = base_url+top_url
     21    live = False 
     22    print 'Testing %s. ' %url,
     23    T = get_page(url)
    2424
    25   for line in T:
    26     #print line.strip()
    27     if line.startswith('<title>Geoscience Australia: Online Flood Search'):
    28       live = True
    29       break
     25    for line in T:
     26        #print line.strip()
     27        if line.startswith('<title>Geoscience Australia: Online Flood Search'):
     28            live = True
     29            break
    3030
    31   if live is True:   
    32     print 'OK: Page %s is live' %url
    33   else:
    34     msg = 'Page %s is not live' %url         
    35     raise msg
     31    if live is True:   
     32        print 'OK: Page is live'
     33    else:
     34        msg = 'Page %s is not live' %url         
     35        raise msg
     36
     37    print
    3638
    3739
    3840def test_database(filename):
    39   """Read list of studies from html and try them one by one
    40   """
     41    """Read list of studies from html and try them one by one
     42    """
    4143
    42   print 'Reading %s' %filename
    43   fid = open(filename)
     44    print 'Reading %s' %filename
     45    fid = open(filename)
    4446
    45   for line in fid.readlines():
    46     print line.strip()
     47    for link in get_individual_studies(fid.readlines()):
     48        url = base_url+htmlmap(link)
     49     
     50        live = False 
     51        print 'Testing %s...' %link[:72],
     52        T = get_page(url)
     53
     54        live = False
     55        for line in T:
     56            if line.startswith('<tr><th>Dataset Name</th>') or\
     57                   line.startswith('<h2>Study title only available.</h2>'):
     58              live = True
     59              break
     60
     61        if live is True:   
     62            print 'OK: Link is live'
     63        else:
     64            msg = 'FAIL: Link is not live: %s' %url
     65            raise msg
    4766
    4867
     68        # Secon tier links 
     69        for link in get_second_tier_links(T):
     70            url = servlet_base_url+htmlmap(link)
     71     
     72            live = False 
     73            print 'Testing %s...' %link[:80],
     74            T = get_page(url)
     75
     76            live = False
     77            for line in T:
     78                #print line.strip()
     79                if line.startswith('<tr><td><h3>Participants in '):
     80                  live = True
     81                  break
     82
     83            if live is True:   
     84                print 'OK: Detail link is live'
     85            else:
     86                for line in T:
     87                    print line.strip()               
     88                msg = 'FAIL: Detail link is not live'
     89                print msg
     90           
     91
     92
     93def get_second_tier_links(lines):
     94    """Scan html lines for flood details and yield
     95    """   
     96    for line in lines:
     97     
     98        index = line.find('<a href="/servlet/FloodDetailServlet?sno')
     99        if index >= 0:
     100            start_index = line.find('servlet', index)
     101            end_index = line.find('">', start_index)
     102            yield line[start_index:end_index]
     103
     104     
     105
     106def get_individual_studies(lines):
     107    """Scan html lines for individual flood studies and yield links
     108    """
    49109 
     110    for line in lines:
     111        index = line.find('<a href="flood_infolist.jsp?sno')
     112        if index >= 0:
     113            start_index = line.find('flood_infolist', index)
     114            end_index = line.find('">', start_index)
     115
     116            yield line[start_index:end_index]
     117
     118     
    50119def get_page(URL):
    51   """General routine for getting and caching URL pages
    52   """
     120    """General routine for getting and caching URL pages
     121    """
    53122 
    54   from caching import cache
    55 
    56   def _GetPage(URL):
    57123    import urllib
    58 
    59     #params = urllib.urlencode({'rivers': 'avoca'})
    60     #F = urllib.urlopen(URL, params)
    61124
    62125    F = urllib.urlopen(URL)   
     
    64127    return(T)
    65128
    66   #T = cache(_GetPage,URL,verbose=0)
    67   T = _GetPage(URL) 
    68   return(T)   
    69129
    70130
    71131def htmlmap(s):
    72   import types
    73   from string import replace, strip
     132    import types
     133    from string import replace, strip
    74134
    75   s = replace(s,'<b>','')
    76   s = replace(s,'</b>','')
    77   s = replace(s,'<sup>','')
    78   s = replace(s,'</sup>','')
    79   s = replace(s,'<SUP>','')
    80   s = replace(s,'</SUP>','')
    81   s = replace(s,'<SUB>','')
    82   s = replace(s,'</SUB>','')
    83   s = replace(s,'&#135;','?')
    84   return(strip(s))
     135    s = replace(s,' ','%20')   
     136    return(strip(s))
    85137         
    86138 
     
    88140       
    89141test_site()
    90 #test_database('')
     142test_database('flood_studies_all.html')
    91143
    92144
Note: See TracChangeset for help on using the changeset viewer.