Ejemplo n.º 1
0
 def getTemplate(self, id):
     """
     Get response template instance from template container
     """
     if self.hasTemplate(id):
         return RT(self.__templates[id])
     return RT(self.generateTemplate("500", "Response Template not found"))
Ejemplo n.º 2
0
def test_rtmmethods():
    # #.getTemplate()
    rtm = RTM()
    tpl = rtm.getTemplate("IwontExist")
    assert tpl.getCode() == 500
    assert tpl.getDescription() == "Response Template not found"

    # #.getTemplates()
    defaultones = sorted([
        "404",
        "500",
        "error",
        "httperror",
        "invalid",
        "empty",
        "unauthorized",
        "expired",
    ])
    availableones = sorted(rtm.getTemplates().keys())
    assert defaultones == availableones

    # #.isTemplateMatchHash()
    tpl = RT("")
    assert rtm.isTemplateMatchHash(tpl.getHash(), "empty") is True

    # #.isTemplateMatchPlain()
    assert rtm.isTemplateMatchPlain(tpl.getPlain(), "empty") is True
Ejemplo n.º 3
0
 def getTemplates(self):
     """
     Return all available response templates
     """
     tpls = {}
     for key in list(self.__templates.keys()):
         tpls[key] = RT(self.__templates[key])
     return tpls
def test_rtmmethods():
    # #.getTemplate()
    rtm = RTM.getInstance()
    tpl = rtm.getTemplate('IwontExist')
    assert tpl.getCode() == 500
    assert tpl.getDescription() == 'Response Template not found'

    # #.getTemplates()
    defaultones = sorted(['404', '500', 'error', 'httperror', 'empty', 'unauthorized', 'expired'])
    availableones = sorted(rtm.getTemplates().keys())
    assert defaultones == availableones

    # #.isTemplateMatchHash()
    tpl = RT('')
    assert rtm.isTemplateMatchHash(tpl.getHash(), 'empty') is True

    # #.isTemplateMatchPlain()
    assert rtm.isTemplateMatchPlain(tpl.getPlain(), 'empty') is True