Ejemplo n.º 1
0
    def test_proxiesListing(self):
        """
        Resource principals will have their proxies listed in a table.
        """
        def fakeResourceById(request, resid):
            return FakePrincipalResource(self, request, resid,
                                         recordType="resources")

        self.resource.getResourceById = fakeResourceById
        document = yield self.renderPage(dict(resourceId=["qux"]))
        proxiesForm = document.getElementById("frm_proxies")
        [proxiesTable] = getElementsByTagName(proxiesForm, "table")
        rows = getElementsByTagName(proxiesTable, "tr")

        # header + 3 data rows (see FakePrincipalResource)
        self.assertEquals(len(rows), 4)
        firstRowCells = getElementsByTagName(rows[1], "td")
        # name, buttons, name, buttons
        self.assertEquals(len(firstRowCells), 4)
        lastRowCells = getElementsByTagName(rows[-1], "td")
        # name, buttons, blank space
        self.assertEquals(len(lastRowCells), 3)
        self.assertEquals(lastRowCells[-1].getAttribute("colspan"), "2")

        self.assertNotIn("This resource has no proxies.",
                         ''.join(gatherTextNodes(document)))
Ejemplo n.º 2
0
 def parseXML(self, res, device):
    descr={'location': 'Unknown',
           'manufacturer': 'Unknown',
           'manufacturerURL': 'Unknown',
           'modelDescription': 'Unknown',
           'modelName': 'Unknown',
           'modelNumber': 'Unknown',
           'deviceType': 'Unknown',
           'host': 'Unknown'}
    try:
       xmlstring=xml.parseXMLString(res)
    except:
       log.info("Cannot parse XML for "+str(device))
       return
    log.debug('RAW DEVICE XML: '+str(res)+' FOR DEVICE: '+str(device))
    xmldev=xml.getElementsByTagName(xmlstring, 'device')[0]
    for k in descr.keys():
       try:
          descr[k] = xml.getElementsByTagName(xmlstring, k)[0].firstChild().toxml()
       except:
          try:
             descr[k] = getattr(device, k, None)
          except:
             descr[k] = 'Unknown'
    log.debug('DEVICE DATA: '+str(descr))
    if 'Network Camera' in descr['deviceType']:
       log.debug("FOUND A CAMERA TO ADD")
       self.core.addMediaSource(descr)
Ejemplo n.º 3
0
    def test_proxySearch(self):
        """
        When the user searches for a proxy, the results are displayed in a
        table, in a form that will allow them to submit it to add new read or
        write proxies.
        """
        self.expectSomeRecords()
        self.resource.getResourceById = partial(FakePrincipalResource, self)
        document = yield self.renderPage(dict(resourceId=["qux"],
                                              proxySearch=["bob"]))

        # Form is filled out with existing input.
        self.assertEquals(
            document.getElementById("txt_proxySearch").getAttribute("value"),
            "bob"
        )
        proxyAddForm = document.getElementById("frm_proxyAdd")
        [proxyResultsTable] = getElementsByTagName(proxyAddForm, "table")

        rows = getElementsByTagName(proxyResultsTable, 'tr')
        self.assertEquals(len(rows), 3)
        firstRowCells = getElementsByTagName(rows[1], 'td')
        self.assertEquals(
            [gatherTextNodes(cell) for cell in firstRowCells[1:]],
            ["User", "bob", "[email protected], [email protected]", ""]
        )
        self.assertNotIn(
            "No matches found for proxy resource bob",
            gatherTextNodes(document)
        )
Ejemplo n.º 4
0
    def test_resourceSearch(self):
        """
        Searching for resources should result in an HTML table resource search.
        """
        self.expectSomeRecords()
        document = yield self.renderPage(dict(resourceSearch=["bob"]))

        # Form is filled out with existing input.
        self.assertEquals(
            document.getElementById("txt_resourceSearch").getAttribute("value"),
            "bob"
        )
        tables = getElementsByTagName(document, "table")
        # search results are the first table
        rows = getElementsByTagName(tables[0], 'tr')
        self.assertEquals(len(rows), 3)
        firstRowCells = getElementsByTagName(rows[1], 'td')
        self.assertEquals(
            [gatherTextNodes(cell) for cell in firstRowCells[1:]],
            ["Bob Bobson", "User", "bob", "boblogin",
             "[email protected], [email protected]"]
        )
        [resourceLink] = getElementsByTagName(
            firstRowCells[0], 'a')
        self.assertEquals(
            resourceLink.getAttribute("href"),
            "/admin/?resourceId=users:bob"
        )
        self.assertEquals(gatherTextNodes(resourceLink), "select")
        self.assertNotIn(
            "No matches found for resource bob",
            gatherTextNodes(document)
        )
Ejemplo n.º 5
0
   def _syncAnalogs(self, res=None):
      boardname=str(xml.getElementsByTagName(self.boardXML, 'cfg_hostname')[0].firstChild().toxml())
      boardip=str(xml.getElementsByTagName(self.boardXML, 'cfg_ip')[0].firstChild().toxml())
      log.info("Syncing board "+str(boardname)+" at "+str(boardip))
      for i in xrange(self.firstAna, self.firstAna+self.numAna):
         aname=xml.getElementsByTagName(self.ioXML, 'i'+str(i))[0].firstChild().toxml()
         for n in xrange(1, 5):
            sconf=str(xml.getElementsByTagName(self.ioXML, 'i'+str(i)+'s'+str(n))[0].firstChild().toxml()).split(';')
            d=dmdb.IOConfAnalogs()
            d.boardname=boardname
            d.boardip=boardip
            d.ananum=i-self.firstAna+1
            d.ananame=aname
            d.status_num=n
            d.status_name=sconf[0]
            d.enabled='yes' if sconf[2]=='1' else 'no'
            d.anatype=int(sconf[3])
            d.mintime=int(sconf[1])
            d.minval=int(sconf[28])
            d.maxval=int(sconf[29])
            d.continuos_domain=str(sconf[4])
            d.continuos_msg=int(sconf[8])
            d.continuos_ctx=int(sconf[7])
            d.continuos_act=int(sconf[9])
            d.continuos_time=int(sconf[6])
            d.continuos_opt=int(sconf[10])
            d.continuos_optstring=str(sconf[11])
            d.continuos_dst=str(sconf[5])
            d.min_domain=str(sconf[12])
            d.min_msg=int(sconf[16])
            d.min_ctx=int(sconf[15])
            d.min_act=int(sconf[17])
            d.min_level=int(sconf[14])
            d.min_opt=int(sconf[18])
            d.min_optstring=str(sconf[19])
            d.min_dst=str(sconf[13])
            d.max_domain=str(sconf[20])
            d.max_msg=int(sconf[24])
            d.max_ctx=int(sconf[23])
            d.max_act=int(sconf[25])
            d.max_level=int(sconf[22])
            d.max_opt=int(sconf[26])
            d.max_optstring=str(sconf[27])
            d.max_dst=str(sconf[21])
            d.save() 

      self.analogLock=False
      self.sendUnLock()
Ejemplo n.º 6
0
    def test_autoScheduleModeMenu(self):
        """
        When rendering a resource, an "Auto-Schedule Mode" menu with various options
        should be displayed.
        """

        modes = ("default", "none", "accept-always", "decline-always", "accept-if-free", "decline-if-busy", "automatic",)

        for ctr, expectValue in enumerate(modes):

            self.resource.getResourceById = partial(FakePrincipalResource, self,
                                                    recordType='resources',
                                                    autosched=True,
                                                    autoschedmode=expectValue)
            document = yield self.renderPage(dict(resourceId=["qux"]))
            autoScheduleModeMenu = document.getElementById("sel_autoScheduleMode")
            self.assertEquals(autoScheduleModeMenu.getAttribute("name"),
                              "autoScheduleMode")

            popup = getElementsByTagName(autoScheduleModeMenu, 'option')

            # Sanity checks to make sure we got the right items
            for i, mode in enumerate(modes):
                self.assertEquals(popup[i].getAttribute("value"), mode)

            popupValues = [popup[i] for i in range(len(modes))]
            for i in range(len(modes)):
                self.assertEquals(popupValues[i].hasAttribute("selected"), ctr == i)
            self.assertEquals(popupValues[ctr].getAttribute("selected"), "selected")
Ejemplo n.º 7
0
    def test_autoScheduleMenu(self):
        """
        When rendering a resource, an "Auto-Schedule" menu with "Yes/No" options
        should be displayed.
        """
        for expectValue in [True, False]:

            self.resource.getResourceById = partial(FakePrincipalResource, self,
                                                    recordType='resources',
                                                    autosched=expectValue)
            document = yield self.renderPage(dict(resourceId=["qux"]))
            autoScheduleMenu = document.getElementById("sel_autoSchedule")
            self.assertEquals(autoScheduleMenu.getAttribute("name"),
                              "autoSchedule")

            yesno = getElementsByTagName(autoScheduleMenu, 'option')

            # Sanity checks to make sure we got the right items
            self.assertEquals(yesno[0].getAttribute("value"), "true")
            self.assertEquals(yesno[1].getAttribute("value"), "false")

            [expectedTrue, expectedFalse] = [yesno[not expectValue],
                                             yesno[expectValue]]

            self.assertEquals(expectedTrue.hasAttribute("selected"), True)
            self.assertEquals(expectedFalse.hasAttribute("selected"), False)
            self.assertEquals(expectedTrue.getAttribute("selected"), "selected")
Ejemplo n.º 8
0
    def test_selectResourceById(self):
        """
        When a resource is selected by a 'resourceId' parameter,
        """
        self.resource.getResourceById = partial(FakePrincipalResource, self)
        document = yield self.renderPage(dict(resourceId=["qux"]))
        [detailsTitle] = getElementsByTagName(document, 'h3')
        detailString = gatherTextNodes(detailsTitle)
        self.assertEquals(detailString,
                          "Resource Details: Hello Fake Resource: 'qux'")
        hiddenResourceId = document.getElementById(
            "hdn_resourceId").getAttribute("value")
        self.assertEquals(hiddenResourceId, "qux")

        autoScheduleMenu = document.getElementById("sel_autoSchedule")

        # Now, some assertions about features that are covered in other tests
        # which should be turned _off_ here since we're not asking for them.

        # Not an auto-schedule resource; there should be no auto-schedule menu.
        self.assertIdentical(autoScheduleMenu, None)
        # No resource search present; we shouldn't be performing the search.
        self.assertNotIn("No matches found for resource",
                         gatherTextNodes(document))
        self.assertIdentical(document.getElementById("tab_searchResults"), None)
        # I'm not attempting to retrieve a property, there's nothing to fail to
        # parse.
        self.assertNotIn("Unable to parse property", gatherTextNodes(document))
        # I'm not searching for proxies, so there shouldn't be any results.
        self.assertNotIn("No matches found for proxy resource",
                         gatherTextNodes(document))
Ejemplo n.º 9
0
   def sendUnLock(self):
      def _send(res):
         if res:
            return self.core.boardOK(res.id)
      if (not self.analogLock
         and not self.inputLock
         and not self.outputLock
         and not self.pwmLock):

         boardname=str(xml.getElementsByTagName(self.boardXML, 'cfg_hostname')[0].firstChild().toxml())
         boardip=str(xml.getElementsByTagName(self.boardXML, 'cfg_ip')[0].firstChild().toxml())
         log.info("Unlocking board module "+str(boardname)+" at "+str(boardip))

         if not self.boardid:
            return dmdb.DMBoards.find(where=["name='%s' and ip='%s'" %(boardname, boardip)], limit=1).addCallback(_send)
         return self.core.boardOK(boardid)      
Ejemplo n.º 10
0
 def test_scrubTrustsH1(self):
     """
     Test that L{xquotient.scrubber.Scrubber} considers h1 to be a safe tag.
     Added because of #1895.
     """
     node = parseString("<h1>Foo</h1>").documentElement
     scrubbed = scrub(node)
     h1s = getElementsByTagName(scrubbed, 'h1')
     self.assertEquals(len(h1s), 1)
     self.assertEquals(gatherTextNodes(h1s[0]).strip(), "Foo")
Ejemplo n.º 11
0
 def test_scrubTrustsH1(self):
     """
     Test that L{xquotient.scrubber.Scrubber} considers h1 to be a safe tag.
     Added because of #1895.
     """
     node = parseString("<h1>Foo</h1>").documentElement
     scrubbed = scrub(node)
     h1s = getElementsByTagName(scrubbed, 'h1')
     self.assertEquals(len(h1s), 1)
     self.assertEquals(gatherTextNodes(h1s[0]).strip(), "Foo")
Ejemplo n.º 12
0
 def _getAnalogIOConf(self, res, num, status, dataonly=False, bname=False):
    boardname=bname
    boardip=self.host
    if not bname:
       boardname=str(xml.getElementsByTagName(self.boardXML, 'cfg_hostname')[0].firstChild().toxml())
    #sqlstring="SELECT * FROM ioconf_analogs WHERE boardname='%s' AND boardip='%s'" % (boardname, boardip)
    sqlstring="boardname='%s' AND boardip='%s' and ananum='%s'" % (boardname, boardip, str(num))
    if genutils.is_number(status) and status != '*':
       sqlstring+=" AND status_num='%s'" % str(status)
    elif status!='*':
       sqlstring+=" AND DMDOMAIN(status, '%s')=1"
    #dmdb.runQuery(sqlstring).addCallback(self._sendAnalogIOConf, dataonly)
    return dmdb.IOConfAnalogs.find(where=[sqlstring]).addCallback(self._sendAnalogIOConf, dataonly)
Ejemplo n.º 13
0
 def getInputsNames(self):
    if not self.inplist:
       ret = {}
       for i in xrange(1, self.numInp+1):
          inp=BoardInput()
          inp.name = xml.getElementsByTagName(self.ioXML, 'i'+str(i))[0].firstChild().toxml()
          inp.num = i
          inp.host = self.host
          inp.section = 'none'
          inp.enabled = 1
          inp.button_name = inp.name.replace(".", " ").capitalize()
          ret[inp.num]=inp
       self.inplist=ret
       return ret
    return self.inplist
Ejemplo n.º 14
0
 def getAnalogsNames(self):
    if not self.analist:
       ret = {}
       for i in xrange(self.firstAna, self.firstAna+self.numAna):
          ana=BoardAnalog()
          ana.name = xml.getElementsByTagName(self.ioXML, 'i'+str(i))[0].firstChild().toxml()
          ana.num = i-12
          ana.host = self.host
          ana.section = 'none'
          ana.enabled = 1
          ana.button_name = ana.name.replace(".", " ").capitalize()
          ret[ana.num] = ana
       self.analist=ret
       return ret
    return self.analist
Ejemplo n.º 15
0
    def test_scrubTrustsSpan(self):
        """
        Test that L{xquotient.scrubber.Scrubber} considers span to be a safe
        tag. Added because of #1641.
        """

        node = parseString("""
        <html>
            <span style='font-weight: bold; font-family:"Book Antiqua"'>
            Hello
            </span>
        </html>
        """).documentElement

        scrubbed = scrub(node)
        spans = getElementsByTagName(scrubbed, 'span')
        self.assertEquals(len(spans), 1)
        self.assertEquals(gatherTextNodes(spans[0]).strip(), "Hello")
Ejemplo n.º 16
0
    def test_scrubTrustsSpan(self):
        """
        Test that L{xquotient.scrubber.Scrubber} considers span to be a safe
        tag. Added because of #1641.
        """

        node = parseString("""
        <html>
            <span style='font-weight: bold; font-family:"Book Antiqua"'>
            Hello
            </span>
        </html>
        """).documentElement

        scrubbed = scrub(node)
        spans = getElementsByTagName(scrubbed, 'span')
        self.assertEquals(len(spans), 1)
        self.assertEquals(gatherTextNodes(spans[0]).strip(), "Hello")
Ejemplo n.º 17
0
   def getOutputsConfs(self):
      if not self.outlist:
         if not self.rellist: self.rellist={}
         ret = {}
         rel = {}
         for i in xrange(1, self.numOut+1):
            out=BoardOutput()
            out.num = i
            out.hasRelays=True
            out.hasPwms=False
            out.hasAmperometers=self.hasAmperometers
            rel[1],rel[2] = BoardRelay(),BoardRelay()
            outstring = xml.getElementsByTagName(self.ioXML, 'o'+str(i))[0].firstChild().toxml()
            if ';' in outstring:
               data=outstring.replace(" ", "").split(";")
            else:
               data=outstring.replace(" ", "").split("|")
            out.dname=data[0]
            out.button_name = out.dname.replace(".", " ").capitalize()
            out.ctx=data[1]
            out.section=context2section(out.ctx)
            out.runtime1=data[2]
            out.runtime2=data[3]
            if len(data) > 16:
               out.breakdelay1=data[4]
               out.rearm1=data[5]
               out.breakdelay2=data[6]
               out.rearm2=data[7]
               out.retard1=data[8]
               out.retard2=data[9]
               out.relay1=data[10]
               out.relay2=data[11]
               out.nanc1=data[12]
               out.nanc2=data[13]
               out.amax1=data[14]
               out.amax2=data[15]
               out.otype=data[16]
               out.enabled=data[17]
            else:
               out.breakdelay1=data[4]
               out.rearm1=0
               out.breakdelay2=data[5]
               out.rearm2=0
               out.retard1=data[6]
               out.retard2=data[7]
               out.relay1=data[8]
               out.relay2=data[9]
               out.nanc1=data[10]
               out.nanc2=data[11]
               out.amax1=data[12]
               out.amax2=data[13]
               out.otype=data[14]
               out.enabled=data[15]
            out.host = self.host
            rel[1].host, rel[2].host = out.host, out.host
            rel[1].dname, rel[2].dname = out.dname, out.dname
            rel[1].ctx, rel[2].ctx = out.ctx, out.ctx
            rel[1].section, rel[2].section = out.section, out.section
            rel[1].runtime = out.runtime1
            rel[2].runtime = out.runtime2
            rel[1].breakdelay = out.breakdelay1
            rel[1].rearm = out.rearm1
            rel[2].breakdelay = out.breakdelay2
            rel[2].rearm = out.rearm2
            rel[1].retard = out.retard1
            rel[2].retard = out.retard2
            rel[1].num = out.relay1
            rel[2].num = out.relay2
            rel[1].nanc = out.nanc1
            rel[2].nanc = out.nanc2
            rel[1].amax = out.amax1
            rel[2].amax = out.amax2
            rel[1].otype, rel[2].otype = out.otype, out.otype
            rel[1].enabled, rel[2].enabled = out.enabled, out.enabled
            rel[1].outnum, rel[2].outnum = i, i
            for r in rel.keys():
               if int(out.otype)==C.DM_OUTPUT_TYPE_ONOFF:
                  rel[r].act=int(C.IKAP_ACT_CHANGE)
                  rel[r].msgtype=C.IKAP_MSG_ACTION
                  rel[r].button_name=rel[r].dname.replace(".", " ").capitalize()
               elif int(out.otype)==C.DM_OUTPUT_TYPE_SIGNALING:
                  rel[r].act=int(C.IKAP_ACT_CHANGE)
                  rel[r].msgtype=C.IKAP_MSG_NOTIFY
                  rel[r].button_name=rel[r].dname.replace(".", " ").capitalize()
               elif int(out.otype)==C.DM_OUTPUT_TYPE_2_RELAY_EXCLUSIVE:
                  if r==1:
                     rel[r].act=int(C.IKAP_ACT_UP)
                     rel[r].button_name=rel[r].dname.replace(".", " ").capitalize()+" "+lang.iostring("up", self.lang)
                  else:
                     rel[r].act=int(C.IKAP_ACT_DOWN)
                     rel[r].button_name=rel[r].dname.replace(".", " ").capitalize()+" "+lang.iostring("down", self.lang)
                  rel[r].msgtype=C.IKAP_MSG_ACTION
               elif int(out.otype)==C.DM_OUTPUT_TYPE_2_RELAY_INCLUSIVE_ON  \
                  or int(out.otype)==C.DM_OUTPUT_TYPE_2_RELAY_INCLUSIVE_OFF:
                  rel[r].act=int(C.IKAP_ACT_CHANGE)
                  rel[r].msgtype=C.IKAP_MSG_ACTION
                  rel[r].button_name=rel[r].dname.replace(".", " ").capitalize()+" "+str(r)
               elif int(out.otype)==C.DM_OUTPUT_TYPE_OPEN_CLOSE_2_RELAYS:
                  if r==1:
                     rel[r].act=int(C.IKAP_ACT_OPEN)
                     rel[r].button_name=rel[r].dname.replace(".", " ").capitalize()+" "+lang.iostring("open", self.lang)
                  else:
                     rel[r].act=int(C.IKAP_ACT_CLOSE)
                     rel[r].button_name=rel[r].dname.replace(".", " ").capitalize()+" "+lang.iostring("close", self.lang)
                  rel[r].msgtype=C.IKAP_MSG_ACTION
               else:
                  rel[r].msgtype=C.IKAP_MSG_NULL
                  rel[r].act=C.IKAP_ACT_NULL
                  rel[r].button_name=rel[r].dname.replace(".", " ").capitalize()

            out.numrel = 1
            out.relays = [rel[1]]
            self.rellist[rel[1].num] = rel[1]
            if int(out.otype) >= C.DM_OUTPUT_TYPE_2_RELAY_EXCLUSIVE:
               out.numrel = 2
               out.relays.append(rel[2])
               self.rellist[rel[2].num] = rel[2]
            ret[out.num] = out

         self.outlist = ret
      return self.outlist
Ejemplo n.º 18
0
 def _ioAnalogsDelete(self, res=None):
    boardname=str(xml.getElementsByTagName(self.boardXML, 'cfg_hostname')[0].firstChild().toxml())
    boardip=str(xml.getElementsByTagName(self.boardXML, 'cfg_ip')[0].firstChild().toxml())
    return dmdb.runOperation("DELETE FROM ioconf_analogs WHERE boardname='%s' AND boardip='%s'" %(str(boardname), str(boardip)))