def test_generate_yaml(self):
		# To do - this test does not work
		id = "AT-3"
		c = SecControl(id)
		c_yaml = yaml.load(c.get_control_yaml())
		# print c_yaml
		self.assertTrue(c_yaml["id"] == c.id)
		self.assertTrue(c_yaml["title"] == c.title)
		self.assertTrue(c_yaml["description"] == c.description)
		self.assertTrue(c_yaml["responsible"] == c.responsible)
		self.assertTrue(c_yaml["supplemental_guidance"] == c.supplemental_guidance)
示例#2
0
 def test_generate_yaml(self):
     # To do - this test does not work
     id = "AT-3"
     c = SecControl(id)
     c_yaml = yaml.load(c.get_control_yaml())
     # print c_yaml
     self.assertTrue(c_yaml["id"] == c.id)
     self.assertTrue(c_yaml["title"] == c.title)
     self.assertTrue(c_yaml["description"] == c.description)
     self.assertTrue(c_yaml["responsible"] == c.responsible)
     self.assertTrue(
         c_yaml["supplemental_guidance"] == c.supplemental_guidance)
示例#3
0
    def controllist(self, ids="AU-4,AU-6", format="html"):
        cherrypy.response.headers['Content-Type'] = 'application/json'
        controllist = []
        j = dict()
        y = dict()
        # return ids.split(',')
        for id in ids.split(','):
            id = id.upper()
            sc = SecControl(id)
            if sc.title is None and sc.description is None and format == "html":
                # control does not exist, return 404
                print "\n*** control does not exist"
                raise cherrypy.HTTPError("404 Not Found", "The requested resource does not exist")
            controllist.append(sc.get_control_json())
            j[id] = sc.get_control_json()
            y[id] = sc.get_control_yaml()

        # render yaml
        if format == "yaml":
            if sc.title is None and sc.description is None:
                raise cherrypy.HTTPError("404 Not Found", "The requested resource does not exist")
            cherrypy.response.headers['Content-Type'] = 'text/yaml'
            return yaml.safe_dump(y, default_flow_style=False)

        #  render for 18F's control-masonry YAML format with separate subsections
        if format == "control-masonry":
            cherrypy.response.headers['Content-Type'] = 'text/yaml'
            tmpl = env.get_template('control-masonry.yaml')
            return tmpl.render(controllist=controllist)

        # render json
        if format == "json":
            cherrypy.response.headers['Content-Type'] = 'application/json'
            if sc.title is None and sc.description is None:
                raise cherrypy.HTTPError("404 Not Found", "The requested resource does not exist")
            return json.dumps(controllist)
        else:
            # render html
            cherrypy.response.headers['Content-Type'] = 'text/html'
            tmpl = env.get_template('controllist.html')
            return tmpl.render(controllist=controllist)