示例#1
0
    def get(self, version):
        """Get the plain-text test list of the specified guideline version."""
        # Remove the .json from version if it is there.
        version.replace('.json', '')
        g = guidelines.Guidelines()
        json = g.get_guideline_contents(version)

        if not json:
            return 'Error getting JSON content for version: ' + version

        if pecan.request.GET.get(const.TYPE):
            types = pecan.request.GET.get(const.TYPE).split(',')
        else:
            types = None

        if pecan.request.GET.get('alias'):
            alias = api_utils.str_to_bool(pecan.request.GET.get('alias'))
        else:
            alias = True

        if pecan.request.GET.get('flag'):
            flag = api_utils.str_to_bool(pecan.request.GET.get('flag'))
        else:
            flag = True

        target = pecan.request.GET.get('target', 'platform')
        try:
            target_caps = g.get_target_capabilities(json, types, target)
            test_list = g.get_test_list(json, target_caps, alias, flag)
        except KeyError:
            return 'Invalid target: ' + target

        return '\n'.join(test_list)
示例#2
0
    def put(self, id, **kw):
        """Handler for update item. Should return full info with updates."""
        product = db.get_product(id)
        vendor_id = product['organization_id']
        vendor = db.get_organization(vendor_id)
        is_admin = (api_utils.check_user_is_foundation_admin()
                    or api_utils.check_user_is_vendor_admin(vendor_id))
        if not is_admin:
            pecan.abort(403, 'Forbidden.')

        product_info = {'id': id}
        if 'name' in kw:
            product_info['name'] = kw['name']
        if 'description' in kw:
            product_info['description'] = kw['description']
        if 'product_ref_id' in kw:
            product_info['product_ref_id'] = kw['product_ref_id']
        if 'public' in kw:
            # user can mark product as public only if
            # his/her vendor is public(official)
            public = api_utils.str_to_bool(kw['public'])
            if (vendor['type'] not in (const.OFFICIAL_VENDOR, const.FOUNDATION)
                    and public):
                pecan.abort(403, 'Forbidden.')
            product_info['public'] = public
        if 'properties' in kw:
            product_info['properties'] = json.dumps(kw['properties'])
        db.update_product(product_info)

        pecan.response.status = 200
        product = db.get_product(id)
        product['can_manage'] = True
        return product
示例#3
0
 def test_str_to_bool(self):
     self.assertTrue(api_utils.str_to_bool('True'))
     self.assertTrue(api_utils.str_to_bool('1'))
     self.assertTrue(api_utils.str_to_bool('YES'))
     self.assertFalse(api_utils.str_to_bool('False'))
     self.assertFalse(api_utils.str_to_bool('no'))
示例#4
0
 def test_str_to_bool(self):
     self.assertTrue(api_utils.str_to_bool('True'))
     self.assertTrue(api_utils.str_to_bool('1'))
     self.assertTrue(api_utils.str_to_bool('YES'))
     self.assertFalse(api_utils.str_to_bool('False'))
     self.assertFalse(api_utils.str_to_bool('no'))