コード例 #1
0
 def test_all_js_placeholders_removed(self):
     """Check to see if all of the JavaScript placeholders have been replaced."""
     placeholders = ["IMAGE_SRC_INSTALLED"]
     page = StartPage.handle()
     for placeholder in placeholders:
         self.assertNotIn(
             placeholder, page,
             "{} was not removed from the JS".format(placeholder))
コード例 #2
0
    def test_all_css_placeholders_removed(self):
        """Check to see if all of the CSS placeholders have been replaced."""
        placeholders = [
            "BACKGROUND", "BGTCOLOR", "FONTFAMILY", "FONTSIZE", "LINKCOLOR",
            "TEXTCOLOR", "BOXCOLOR", "BASECOLOR", "SHADOW"
        ]

        page = StartPage.handle()
        for placeholder in placeholders:
            self.assertNotIn(
                placeholder, page,
                "{} was not removed from the CSS".format(placeholder))
コード例 #3
0
    def test_files_do_not_contain_backslashes(self):
        # This would be caught by the W3C validator if we didn't sanitize the filenames before sending them.
        page = StartPage.handle()
        fileRE = re.compile(r'"file:///(.*?)"')
        results = fileRE.findall(string=page)

        badFilenames = []
        for result in results:
            if result.find("\\") != -1:
                badFilenames.append(result)

        if len(badFilenames) > 0:
            self.fail(
                "The following filenames contain backslashes, which is prohibited in HTML: {}"
                .format(badFilenames))
コード例 #4
0
 def test_all_html_placeholders_removed(self):
     """Check to see if all of the HTML placeholders have been replaced."""
     placeholders = [
         "T_TITLE", "VERSIONSTRING", "T_DOCUMENTS", "T_HELP", "T_ACTIVITY",
         "SECTION_RECENTFILES", "T_TIP", "T_ADJUSTRECENT",
         "SECTION_EXAMPLES", "SECTION_CUSTOM", "T_CUSTOM", "T_NOTES",
         "T_GENERALDOCUMENTATION", "IMAGE_SRC_USERHUB", "T_USERHUB",
         "T_DESCR_USERHUB", "IMAGE_SRC_POWERHUB", "T_POWERHUB",
         "T_DESCR_POWERHUB", "IMAGE_SRC_DEVHUB", "T_DEVHUB",
         "T_DESCR_DEVHUB", "IMAGE_SRC_MANUAL", "T_MANUAL", "T_DESCR_MANUAL",
         "T_WBHELP", "T_DESCR_WBHELP", "UL_WORKBENCHES", "T_COMMUNITYHELP",
         "T_DESCR_COMMUNITYHELP1", "T_DESCR_COMMUNITYHELP2",
         "T_DESCR_COMMUNITYHELP3", "T_ADDONS", "T_DESCR_ADDONS",
         "T_OFFLINEPLACEHOLDER", "T_OFFLINEHELP", "T_EXTERNALLINKS",
         "T_RECENTCOMMITS", "T_DESCR_RECENTCOMMITS", "T_EXTERNALLINKS",
         "T_SEEONGITHUB", "T_FORUM", "T_DESCR_FORUM"
     ]
     page = StartPage.handle()
     for placeholder in placeholders:
         self.assertNotIn(
             placeholder, page,
             "{} was not removed from the HTML".format(placeholder))
コード例 #5
0
import WebGui
from StartPage import StartPage
WebGui.openBrowserHTML(
    StartPage.handle(),
    'file://' + App.getResourceDir() + 'Mod/Start/StartPage/', 'Start page')
App.setActiveDocument("Unnamed")
App.ActiveDocument = App.getDocument("Unnamed")
Gui.ActiveDocument = Gui.getDocument("Unnamed")
from FreeCAD import Vector
from pyooml import *
a1 = -60
a2 = 70
L1 = 40
L2 = 40
v1 = Vector(L1, 0, 0)
v2 = Vector(L2, 0, 0)
f0 = frame()
f1 = frame()
f2 = frame()
sv1 = svector(v1).color("yellow")
sv2 = svector(v2).color("yellow")
import HMatrix
Ma = HMatrix.Roty(a1)
Mb = HMatrix.Translation(v1)
Mc = HMatrix.Roty(a2)
Md = HMatrix.Translation(v2)
sv1.T = Ma
f1.T = Ma * Mb
sv2.T = Ma * Mb * Mc
f2.T = Ma * Mb * Mc * Md
vr = f2.T.multiply(Vector(0, 0, 0))
コード例 #6
0
    def test_html_validates(self):
        # Send the generated html to the W3C validator for analysis (removing potentially-sensitive data first)
        import urllib.request
        import os
        import json
        page = self.sanitize(
            StartPage.handle())  # Remove potentially sensitive data

        # For debugging, if you want to ensure that the sanitization worked correctly:
        # from pathlib import Path
        # home = str(Path.home())
        # f=open(home+"/test.html", "w")
        # f.write(page)
        # f.close()

        validation_url = "https://validator.w3.org/nu/?out=json"
        data = page.encode('utf-8')  # data should be bytes
        req = urllib.request.Request(validation_url, data)
        req.add_header("Content-type", "text/html; charset=utf-8")
        errorCount = 0
        warningCount = 0
        infoCount = 0
        validationResultString = ""
        try:
            with urllib.request.urlopen(req) as response:
                text = response.read()

                responseJSON = json.loads(text)

                for message in responseJSON["messages"]:
                    if "type" in message:
                        if message["type"] == "info":
                            if "subtype" in message:
                                if message["subtype"] == "warning":
                                    warningCount += 1
                                    validationResultString += "WARNING: {}\n".format(
                                        ascii(message["message"]))
                            else:
                                infoCount += 1
                                validationResultString += "INFO: {}\n".format(
                                    ascii(message["message"]))
                        elif message["type"] == "error":
                            errorCount += 1
                            validationResultString += "ERROR: {}\n".format(
                                ascii(message["message"]))
                        elif message["type"] == "non-document-error":
                            FreeCAD.Console.PrintWarning(
                                "W3C validator returned a non-document error:\n {}"
                                .format(message))
                            return

        except urllib.error.HTTPError as e:
            FreeCAD.Console.PrintWarning(
                "W3C validator returned response code {}".format(e.code))

        except urllib.error.URLError:
            FreeCAD.Console.PrintWarning(
                "Could not communicate with W3C validator")

        if errorCount > 0 or warningCount > 0:
            StartPage.exportTestFile()
            FreeCAD.Console.PrintWarning(
                "HTML validation failed: Start page source written to your home directory for analysis."
            )
            self.fail(
                "W3C Validator analysis shows the Start page has {} errors and {} warnings:\n\n{}"
                .format(errorCount, warningCount, validationResultString))
        elif infoCount > 0:
            FreeCAD.Console.PrintWarning(
                "The Start page is valid HTML, but the W3C sent back {} informative messages:\n{}."
                .format(infoCount, validationResultString))