<commit_before>#!/usr/bin/python2.6
# -*- coding: us-ascii -*-
# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
# 
# $Id$
#
#    Copyright (C) 2009 <NAME> <<EMAIL>>
#
#    This library is free software; you can redistribute it and/or
#    modify it under the terms of the GNU Lesser General Public
#    License as published by the Free Software Foundation; either
#    version 2.1 of the License, or (at your option) any later version.
#
#    This library 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
#    Lesser General Public License for more details.

"""
Web interface for QA reports and tools.

This depends on the storage server also running.

"""

import itertools

from pycopia.WWW import framework
from pycopia.WWW.middleware import auth

from pycopia.aid import IF
from pycopia.db import types
from pycopia.db import models
from pycopia.db import webhelpers


from sqlalchemy.exc import DataError, IntegrityError
#from sqlalchemy import and_, or_



TC_METAMAP = dict((c.colname, c) for c in models.get_metadata(models.TestCase))
#TR_METAMAP = dict((c.colname, c) for c in models.get_metadata(models.TestResult))


TINY_MCE_EDIT_INIT="""
    tinyMCE.init({ 
        mode : "textareas", 
        theme : "advanced", 
        editor_selector : "TEXT",
        theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,|,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "none"
        });
"""


def testcase_edit_constructor(request, **kwargs):
    doc = framework.get_acceptable_document(request)
    doc.stylesheet = request.get_url("css", name="qawebui.css")
    doc.add_javascript2head(url=request.get_url("js", name="MochiKit.js"))
    doc.add_javascript2head(url=request.get_url("js", name="proxy.js"))
    doc.add_javascript2head(url=request.get_url("js", name="db.js"))
    doc.add_javascript2head(url=request.get_url("js", name="tiny_mce/tiny_mce.js"))
    doc.add_javascript2head(text=TINY_MCE_EDIT_INIT)
    for name, val in kwargs.items():
        setattr(doc, name, val)
    build_framing(request, doc, "Edit Test Case")
    return doc


def testcase_view_constructor(request, **kwargs):
    doc = framework.get_acceptable_document(request)
    doc.stylesheet = request.get_url("css", name="qawebui.css")
    doc.add_javascript2head(url=request.get_url("js", name="MochiKit.js"))
    doc.add_javascript2head(url=request.get_url("js", name="proxy.js"))
    doc.add_javascript2head(url=request.get_url("js", name="db.js"))
    for name, val in kwargs.items():
        setattr(doc, name, val)
    build_framing(request, doc, "Test Case")
    return doc

#def testcase_delete_constructor(request, **kwargs):
#    doc = framework.get_acceptable_document(request)
#    doc.stylesheet = request.get_url("css", name="qawebui.css")
#    for name, val in kwargs.items():
#        setattr(doc, name, val)
#    build_framing(request, doc, "Delete Test Case")
#    return doc


def testcase_run_constructor(request, **kwargs):
    doc = framework.get_acceptable_document(request)
    doc.stylesheet = request.get_url("css", name="qawebui.css")
    for name, val in kwargs.items():
        setattr(doc, name, val)
    build_framing(request, doc, "Run Test Case")
    return doc


def testcase_list_constructor(request, **kwargs):
    doc = framework.get_acceptable_document(request)
    doc.stylesheet = request.get_url("css", name="qawebui.css")
    doc.add_javascript2head(url=request.get_url("js", name="MochiKit.js"))
    doc.add_javascript2head(url=request.get_url("js", name="proxy.js"))
    doc.add_javascript2head(url=request.get_url("js", name="db.js"))
    for name, val in kwargs.items():
        setattr(doc, name, val)
    build_framing(request, doc, "Test Cases")
    return doc


def testcase_create_constructor(request, **kwargs):
    doc = framework.get_acceptable_document(request)
    doc.stylesheet = request.get_url("css", name="qawebui.css")
    for name, val in kwargs.items():
        setattr(doc, name, val)
    doc.add_javascript2head(url=request.get_url("js", name="MochiKit.js"))
    doc.add_javascript2head(url=request.get_url("js", name="proxy.js"))
    doc.add_javascript2head(url=request.get_url("js", name="db.js"))
    doc.add_javascript2head(url=request.get_url("js", name="tiny_mce/tiny_mce.js"))
    doc.add_javascript2head(text=TINY_MCE_EDIT_INIT)
    build_framing(request, doc, "New Test Case")
    return doc


def build_framing(request, doc, title):
    nav = doc.add_section("navigation")
    NM = doc.nodemaker
    nav.append(NM("P", None,
         NM("A", {"href":"/"}, "Home"), NM("ASIS", None, "&nbsp;"),
         IF(request.path.count("/") > 2, NM("A", {"href":".."}, "Up")), NM("ASIS", None, "&nbsp;"),
    ))
    nav.append(NM("P", {"class_": "title"}, title))
    nav.append(NM("P", None, 
            NM("A", {"href": "/auth/logout"}, "logout")))
    doc.add_section("messages", id="messages")



def render_testcase(doc, dbrow):
    doc.add_header(2, dbrow.name)
    NM = doc.nodemaker
    sect = doc.add_section("testcasebody", id="rowid_%s" % dbrow.id)
    if dbrow.functionalarea:
        sect.add_header(3, "Area Tested")
        dl = sect.add_definition_list()
        dl.add_definition("Testing area:", " ".join(map(str, dbrow.functionalarea)))

    sect.add_header(3, "Implementation")
    if dbrow.automated:
        if dbrow.testimplementation:
            sect.new_para("Implemented in: '%s'%s." % (dbrow.testimplementation, 
                    IF(dbrow.interactive, " (user interactive test)", "")))
        else:
            sect.new_para("Test is automated but has no implementation!", class_="error")
    else:
        if dbrow.testimplementation:
            sect.new_para("Manual test implemented in: '%s'." % (dbrow.testimplementation,))<commit_msg>Update to new API (&nbsp; is not allowed in HTML5).<commit_after>#!/usr/bin/python2.6
# -*- coding: us-ascii -*-
# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
# 
# $Id$
#
#    Copyright (C) 2009 <NAME> <<EMAIL>>
#
#    This library is free software; you can redistribute it and/or
#    modify it under the terms of the GNU Lesser General Public
#    License as published by the Free Software Foundation; either
#    version 2.1 of the License, or (at your option) any later version.
#
#    This library 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
#    Lesser General Public License for more details.

"""
Web interface for QA reports and tools.

This depends on the storage server also running.

"""

import itertools

from pycopia.WWW import framework
from pycopia.WWW.middleware import auth

from pycopia.aid import IF
from pycopia.db import types
from pycopia.db import models
from pycopia.db import webhelpers


from sqlalchemy.exc import DataError, IntegrityError
#from sqlalchemy import and_, or_



TC_METAMAP = dict((c.colname, c) for c in models.get_metadata(models.TestCase))
#TR_METAMAP = dict((c.colname, c) for c in models.get_metadata(models.TestResult))


TINY_MCE_EDIT_INIT="""
    tinyMCE.init({ 
        mode : "textareas", 
        theme : "advanced", 
        editor_selector : "TEXT",
        theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,bullist,numlist,undo,redo,|,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "none"
        });
"""


def testcase_edit_constructor(request, **kwargs):
    doc = framework.get_acceptable_document(request)
    doc.stylesheet = request.get_url("css", name="qawebui.css")
    doc.add_javascript2head(url=request.get_url("js", name="MochiKit.js"))
    doc.add_javascript2head(url=request.get_url("js", name="proxy.js"))
    doc.add_javascript2head(url=request.get_url("js", name="db.js"))
    doc.add_javascript2head(url=request.get_url("js", name="tiny_mce/tiny_mce.js"))
    doc.add_javascript2head(text=TINY_MCE_EDIT_INIT)
    for name, val in kwargs.items():
        setattr(doc, name, val)
    build_framing(request, doc, "Edit Test Case")
    return doc


def testcase_view_constructor(request, **kwargs):
    doc = framework.get_acceptable_document(request)
    doc.stylesheet = request.get_url("css", name="qawebui.css")
    doc.add_javascript2head(url=request.get_url("js", name="MochiKit.js"))
    doc.add_javascript2head(url=request.get_url("js", name="proxy.js"))
    doc.add_javascript2head(url=request.get_url("js", name="db.js"))
    for name, val in kwargs.items():
        setattr(doc, name, val)
    build_framing(request, doc, "Test Case")
    return doc

#def testcase_delete_constructor(request, **kwargs):
#    doc = framework.get_acceptable_document(request)
#    doc.stylesheet = request.get_url("css", name="qawebui.css")
#    for name, val in kwargs.items():
#        setattr(doc, name, val)
#    build_framing(request, doc, "Delete Test Case")
#    return doc


def testcase_run_constructor(request, **kwargs):
    doc = framework.get_acceptable_document(request)
    doc.stylesheet = request.get_url("css", name="qawebui.css")
    for name, val in kwargs.items():
        setattr(doc, name, val)
    build_framing(request, doc, "Run Test Case")
    return doc


def testcase_list_constructor(request, **kwargs):
    doc = framework.get_acceptable_document(request)
    doc.stylesheet = request.get_url("css", name="qawebui.css")
    doc.add_javascript2head(url=request.get_url("js", name="MochiKit.js"))
    doc.add_javascript2head(url=request.get_url("js", name="proxy.js"))
    doc.add_javascript2head(url=request.get_url("js", name="db.js"))
    for name, val in kwargs.items():
        setattr(doc, name, val)
    build_framing(request, doc, "Test Cases")
    return doc


def testcase_create_constructor(request, **kwargs):
    doc = framework.get_acceptable_document(request)
    doc.stylesheet = request.get_url("css", name="qawebui.css")
    for name, val in kwargs.items():
        setattr(doc, name, val)
    doc.add_javascript2head(url=request.get_url("js", name="MochiKit.js"))
    doc.add_javascript2head(url=request.get_url("js", name="proxy.js"))
    doc.add_javascript2head(url=request.get_url("js", name="db.js"))
    doc.add_javascript2head(url=request.get_url("js", name="tiny_mce/tiny_mce.js"))
    doc.add_javascript2head(text=TINY_MCE_EDIT_INIT)
    build_framing(request, doc, "New Test Case")
    return doc


def build_framing(request, doc, title):
    nav = doc.add_section("navigation")
    NM = doc.nodemaker
    nav.append(NM("P", None,
         NM("A", {"href":"/"}, "Home"), NM("_", None),
         IF(request.path.count("/") > 2, NM("A", {"href":".."}, "Up")), NM("_", None),
    ))
    nav.append(NM("P", {"class_": "title"}, title))
    nav.append(NM("P", None, 
            NM("A", {"href": "/auth/logout"}, "logout")))
    doc.add_section("messages", id="messages")



def render_testcase(doc, dbrow):
    doc.add_header(2, dbrow.name)
    NM = doc.nodemaker
    sect = doc.add_section("testcasebody", id="rowid_%s" % dbrow.id)
    if dbrow.functionalarea:
        sect.add_header(3, "Area Tested")
        dl = sect.add_definition_list()
        dl.add_definition("Testing area:", " ".join(map(str, dbrow.functionalarea)))

    sect.add_header(3, "Implementation")
    if dbrow.automated:
        if dbrow.testimplementation:
            sect.new_para("Implemented in: '%s'%s." % (dbrow.testimplementation, 
                    IF(dbrow.interactive, " (user interactive test)", "")))
        else:
            sect.new_para("Test is automated but has no implementation!", class_="error")
    else:
        if dbrow.testimplementation:
            sect.new_para("Manual test implemented in: '%s'." % (dbrow.testimplementation,))
{'fraction_non_alphanumeric': 0.1394689978954185, 'fraction_numerical': 0.0055852355512384655, 'mean_word_length': 4.115942028985507, 'pattern_counts': {'":': 8, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2624451', 'n_tokens_mistral': 4136, 'n_tokens_neox': 4031, 'n_words': 866}