Main.py :  » Web-Frameworks » Webware » Webware-1.0.2 » WebKit » Testing » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Webware 
Webware » Webware 1.0.2 » WebKit » Testing » Main.py
from WebKit.SidebarPage import SidebarPage
from WebKit.Application import Application
import os


class Main(SidebarPage):
  """Testing - read TestCases.data and display them.

  TO DO
    * Reload TestCases.data only load when modified (by checking mod date).

  """

  def title(self):
    return 'Testing'

  def cornerTitle(self):
    return 'WebKit Testing'

  def writeContent(self):
    self.writeln('<h2 style="text-align:center">Test cases</h2>')
    self.writeTestCases()
    self.writeNotes()

  def writeTestCases(self):
    wr = self.writeln
    req = self.request()
    servletPath = req.servletPath()
    filename = self.serverSidePath('TestCases.data')
    self._cases = self.readFileNamed(filename)
    wr('<table align="center" style="margin-left:auto;margin-right:auto"'
      ' border="0" cellpadding="3" cellspacing="2">')
    wr('<tr style="color:white;background-color:#555">'
      '<td>#</td><td>URL</td><td>Expectation</td></tr>')
    caseNum = 1
    for case in self._cases:
      # For each URL, fix it up and make a name. Put in urls list.
      urls = []
      for url in case['URLs']:
        url = servletPath + url
        if url:
          urlName = self.htmlEncode(url)
          urls.append((url, urlName))
      if not urls:
        continue
      expectation = case['Expectation'] # self.htmlEncode(case['Expectation'])
      bgcolor = ['EEE', 'DDD'][caseNum % 2]
      wr('<tr style="background-color:#%s">'
        '<td>%d.</td><td>' % (bgcolor, caseNum))
      for url, urlName in urls:
        wr('<a href="%s">%s</a><br>' % (url, urlName))
      wr('<td>%s</td></tr>' % expectation)
      caseNum += 1
    wr('</table>')

  def readFileNamed(self, filename):
    """Return a list of test cases.

    Each of them is a dictionary, as defined the given file.
    See TestCases.data for information on the format.

    """
    f = open(filename)
    cases = self.readFile(f)
    f.close()
    return cases

  def readFile(self, file):
    return self.readContent(file.read())

  def readContent(self, content):
    lines = map(lambda line: line.strip(), content.split('\n'))
    lineNum = 1
    cases = []
    urls = []
    for line in lines:
      if line and line[0] != '#':
        if line[-1] == '\\': # continuation line;
          # means there are multiple URLs for this case
          urls.append(line[:-1].strip())
        else:
          parts = line.split('-->')
          if len(parts) != 2:
            self.error('Invalid line at %d.' % lineNum)
          urls.append(parts[0].strip())
          cases.append({
            'URLs': urls,
            'Expectation': parts[1].strip(),
          })
          urls = [] # reset list of URLs
      lineNum += 1
    return cases

  def writeNotes(self):
    self.writeln('''<h4>Notes</h4>
<ul>
<li>Test all links in all pages of all contexts (Examples, Admin, Testing, etc.),
including links found in the headers and footers of the pages.</li>
<li>Test functionality of interactive pages, like CountVisits and ListBox.</li>
<li>Test each link more than once.</li>
<li>Test with multiple adapters (WebKit.cgi, OneShot.cgi, etc.).</li>
</ul>''')

  def error(self, msg):
    raise Exception, msg
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.