Esempio n. 1
0
    def test_bedepend(self):
        """
            Dependent databases are listed and there is only one,
            transmitted database name in the generated database
        """
        parameter = {
            "packagename": ["a"],
            "depend_type": "bedep",
            "parameter": {
                "db_priority": ["test", "test"],
                "with_subpack": False
            }
        }
        result, error = validate(DependSchema, parameter)
        self.assertIsNotNone(result)
        self.assertNotEqual({}, error)

        parameter = {
            "packagename": ["a"],
            "depend_type": "installdep",
            "parameter": {
                "db_priority": ["test"],
                "packtype": "source",
                "with_subpack": False,
                "search_type": "install"
            }
        }
        result, error = validate(DependSchema, parameter)
        self.assertIsNotNone(result)
        self.assertNotEqual({}, error)
 def test_packages_not_dict(self):
     """
     The data type of the test transfer is not a dictionary
     """
     new_list = []
     with self.assertRaises(TypeError):
         validate(PackageSchema, new_list)
     new_str = ""
     with self.assertRaises(TypeError):
         validate(PackageSchema, new_str)
 def test_single_error(self):
     """
     Test a single package validator, missing a required pass parameter
     """
     parameters_one = {"database_name": 1, "pkg_name": 1}
     result, errors = validate(SingleSchema, parameters_one)
     self.assertIsNotNone(result)
     self.assertNotEqual(errors, {})
     parameters_two = {"database_name": "a", "pkg_name": ""}
     result, errors = validate(SingleSchema, parameters_two)
     self.assertNotEqual(errors, {})
     parameters_three = {"database_name": "", "pkg_name": "a"}
     result, errors = validate(SingleSchema, parameters_three)
     self.assertIsNotNone(result)
     self.assertNotEqual(errors, {})
 def test_database_name_error(self):
     """
     The transmitted database name is not in the system
     """
     parameters_one = {"database_name": "c", "pkg_name": "a"}
     result, errors = validate(SingleSchema, parameters_one)
     self.assertIsNotNone(result)
     self.assertNotEqual(errors, {})
Esempio n. 5
0
 def get_depend_result(self, path):
     """
     Obtain comparative data
     """
     _data = self.read_file_content(
         path=os.path.join(self.data_folder, path))
     request_param, edges = self._extract_edges_paramter(data=_data)
     _param, _ = validate(DependSchema, request_param, load=True)
     return _param, edges
Esempio n. 6
0
    def get(self):
        """
        Get all package info from a database

        Args:
            database_name: Data base name
            page_num:
            page_size:
            query_pkg_name:
        Returns:
            for example::
               {
                   "code": "",
                    "total_count": xx,
                      "total_page": xx,
                      "resp": [
                        {
                          "pkg_name": "Judy",
                          "license": "Apache 2.0",
                          "version": "2.0.0",
                          "url":"http://www.xxx.com",
                          "database": "Mainline"
                        },
                        ...
                    "msg": ""
                }
        Raises:
        """
        data = request.args
        result, error = validate(PackageSchema, data, load=True)

        if error:
            response = self.rspmsg.body('param_error')
            response['total_count'] = None
            response['total_page'] = None
            return jsonify(response)

        page_num = result.get("page_num")
        page_size = result.get("page_size")
        query_pkg_name = [result.get("query_pkg_name")
                          ] if result.get("query_pkg_name") else None
        find_package = Package()
        try:
            result_all = find_package.all_src_packages(
                result.get("database_name"),
                page_num=page_num,
                page_size=page_size,
                package_list=query_pkg_name,
                command_line=result.get("command_line"))
        except (ElasticSearchQueryException, DatabaseConfigException):
            return jsonify(self.rspmsg.body('connect_db_error'))
        except PackageInfoGettingError:
            return jsonify(self.rspmsg.body('pack_name_not_found'))
        if result_all:
            return jsonify(self.parse_package(result_all, page_size))
        return jsonify(self.rspmsg.body("table_name_not_exist"))
    def validate_parameters(self, key=None, value=None):
        """
        Copy the new dictionary validation to return the validation result
        Args:
            key: A key in a dictionary
            value: Values in the dictionary

        Returns:
            errors: The verification results
        """
        new_parameters = copy.deepcopy(self.parameters)
        new_parameters[key] = value
        result, errors = validate(PackageSchema, new_parameters)
        return errors
Esempio n. 8
0
    def test_level_0_source_installdep(self):
        """
        Install dependent graph tests
        """
        request_param, _ = validate(DependSchema, {
            "packagename": ["Judy"],
            "depend_type": "installdep",
            "node_name": "Judy",
            "node_type": "source",
            "parameter": {
                "db_priority": ["os-version"]
            }
        },
                                    load=True)

        self._comparison_results(edges=[], request_param=request_param)
Esempio n. 9
0
 def test_download(self):
     """
         The database of the downloaded validator is a list and there is only one,
         the transmitted database name in the generated database
     """
     parameter = {
         "packagename": ["a"],
         "depend_type": "src",
         "parameter": {
             "db_priority": ["test"],
             "with_subpack": False
         }
     }
     result, error = validate(DownSchema, parameter)
     self.assertIsNotNone(result)
     self.assertNotEqual({}, error)
Esempio n. 10
0
    def get(self, pkg_name):
        """
        Searching a package info

        Args:
            dbName: Database name, not required parameter
            sourceName: Source code package name, must pass
        Returns:
            for
            examples::
                {
                "code": "",
                "resp": [{
                "buildDep": [],
                "dbname": "",
                "license": "",
                "sourceName": "",
                "subpack": { },
                "version": ""}],
                "msg": ""
                 }
        Raises:
            DisconnectionError: Unable to connect to database exception
            AttributeError: Object does not have this property
            TypeError: Exception of type
            Error: Abnormal error
        """
        # Get verification parameters
        rspmsg = RspMsg()
        data = dict()
        data["database_name"] = request.args.get("database_name")
        data["pkg_name"] = pkg_name
        result, error = validate(SingleSchema, data, load=True)
        if error:
            response = rspmsg.body('param_error')
            return jsonify(response)
        pkg_name = [result.get("pkg_name")]
        database_name = [result.get("database_name")]
        find_binary_package = BinaryPackage()
        try:
            pkg_result = find_binary_package.bin_package_info(
                pkg_name, database_name)
        except (ElasticSearchQueryException, DatabaseConfigException) as e:
            return jsonify(rspmsg.body('connect_db_error'))
        if pkg_result:
            return jsonify(rspmsg.body('success', resp=pkg_result))
        return jsonify(rspmsg.body('pack_name_not_found'))
Esempio n. 11
0
    def get(self, pkg_name):
        """
        Searching a package info

        Args:
            database_name: Database name
            pkg_name: Source code package name
        Returns:
            for examples::
                {
                  "code":200,
                  "msg":"",
                  "resp": {
                    "openEuler:20.09":[
                        {
                          "pkg_name": "Judy",
                          "license": "Apache 2.0",
                          "version": "2.0",
                          "release":"oe.13",
                          "url": "http://www.xxx.com",
                          "summary":"xxxxxxxxxxxxxxxxx",
                          "description":"xxxxxxxxxx",
                          "buildrequired": ["build_rpm1","build_rpm2"],
                          "subpack":[
                            {
                              "bin_name":"Judy",
                              "provides": [
                                {
                                  "component":"Judy_com1",
                                  "required_by_bin":["CUnit-devel","tomcat"],
                                  "required_by_src":["CUnit","gcc"]
                                }
                              ],
                              "requires":[
                                {
                                  "component":"Judy_req1",
                                  "provided_by":["glibc"]
                                }]}]},
                        {
                          "pkg_name": "glibc",
                          "...": "..."
                        }
                    ]
                  }
                }
        Raises:
        """
        # Get verification parameters
        rspmsg = RspMsg()
        data = dict()
        data["database_name"] = request.args.get("database_name")
        data["pkg_name"] = pkg_name
        result, error = validate(SingleSchema, data, load=True)
        if error:
            response = rspmsg.body('param_error')
            return jsonify(response)
        pkg_name = [result.get("pkg_name")]
        database_name = [result.get("database_name")]
        find_source_package = SourcePackage()
        try:
            pkg_result = find_source_package.src_package_info(
                pkg_name, database_name)
        except (ElasticSearchQueryException, DatabaseConfigException) as e:
            return jsonify(rspmsg.body('connect_db_error'))
        if pkg_result:
            return jsonify(rspmsg.body('success', resp=pkg_result))
        return jsonify(rspmsg.body('pack_name_not_found'))
Esempio n. 12
0
    def test_data_type_error(self):
        """
        Incorrect data type, or out of range
        """
        parameter = {
            "packagename": "",
            "depend_type": "",
            "parameter": {
                "db_priority": [""],
                "packtype": "",
                "with_subpack": "",
                "search_type": ""
            }
        }
        result, error = validate(DependSchema, parameter)
        self.assertNotEqual({}, error)
        self.assertIsNotNone(result)
        parameter = {"packagename": "a", "depend_type": "a"}
        result, error = validate(DependSchema, parameter)
        self.assertIsNotNone(result)
        self.assertNotEqual({}, error)
        parameter = {
            "packagename": "a",
            "depend_type": "a",
            "parameter": {
                "with_subpack": "dd"
            }
        }
        result, error = validate(DependSchema, parameter)
        self.assertIsNotNone(result)
        self.assertNotEqual({}, error)
        parameter = {"packagename": ["a"], "depend_type": ["installdep"]}
        result, error = validate(DependSchema, parameter)
        self.assertNotEqual({}, error)
        self.assertIsNotNone(result)
        parameter = {
            "packagename": ["a"],
            "depend_type": "installdep",
            "parameter": {
                "db_priority": ["a"],
                "packtype": "a"
            }
        }
        result, error = validate(DependSchema, parameter)
        self.assertIsNotNone(result)
        self.assertNotEqual({}, error)
        parameter = {
            "packagename": ["a"],
            "depend_type": "installdep",
            "parameter": {
                "db_priority": ["a"],
                "packtype": "a"
            }
        }
        result, error = validate(DependSchema, parameter, True)
        self.assertIsNotNone(result)
        self.assertNotEqual({}, error)

        parameter = {
            "packagename": ["a"],
            "depend_type": "bedep",
            "parameter": {
                "db_priority": "a",
                "packtype": "a"
            }
        }
        result, error = validate(DependSchema, parameter)
        self.assertIsNotNone(result)
        self.assertNotEqual({}, error)
        parameter = {"packagename": ["a"], "depend_type": "bedep"}
        result, error = validate(DependSchema, parameter)
        self.assertIsNotNone(result)
        self.assertNotEqual({}, error)
        parameter = {
            "packagename": ["a"],
            "depend_type": "bedep",
            "parameter": {
                "db_priority": ["test", "test"],
                "packtype": "source",
                "with_subpack": False,
                "search_type": "install"
            }
        }
        result, error = validate(DependSchema, parameter)
        self.assertIsNotNone(result)
        self.assertNotEqual({}, error)