lsd_test_suite.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:lcp-testing-tools 作者: edrlab 项目源码 文件源码
def test_fetch_license(self):
        """ Fetch a license from the URL found in the status doc, then validates it """

        try:
            license = next((l for l in self.lsd['links'] if l['rel'] == 'license'))
        except StopIteration as err:
            raise TestSuiteRunningError(
                "Missing a 'license' link in the status document")

        license_url = license['href']
        LOGGER.debug("Fetch license at url %s:", license_url)   

        # fetch the license
        r = requests.get(license_url)
        try:
            self.lcpl = r.json()            
        except ValueError as err:
            LOGGER.debug(r.text)
            raise TestSuiteRunningError("Malformed JSON License Document")
        LOGGER.debug("The License is available")   

        # validate the license
        lcpl_json_schema_path = os.path.join(
            JSON_SCHEMA_DIR_PATH, 'lcpl_schema.json')

        with open(lcpl_json_schema_path) as schema_file:
            lcpl_json_schema = json.loads(schema_file.read())
            try:
                jsonschema.validate(self.lcpl, lcpl_json_schema, format_checker=jsonschema.FormatChecker())
            except jsonschema.ValidationError as err:
                raise TestSuiteRunningError(err)

        LOGGER.debug("The up to date License is available and valid")

        # display some license values
        LOGGER.info("date issued {}, updated {}".format(
            self.lcpl['issued'], self.lcpl['updated'] if "updated" in self.lcpl else "never"))
        LOGGER.info("rights print {}, copy {}".format(
            self.lcpl['rights']['print'], self.lcpl['rights']['copy']))
        LOGGER.info("rights start {}, end {}".format(
            self.lcpl['rights']['start'] if "start" in self.lcpl['rights'] else "none", 
            self.lcpl['rights']['end'] if "end" in self.lcpl['rights'] else "none"))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号