Beispiel #1
0
    def testTopicFromJson(self):
        '''
        test loading/constructing from Json
        '''
        jsonStr = """{
  "data": [{
    "pageTitle": "Concept:Commit",
    "name": "Commit",
    "pluralName": "Commits",
    "documentation": "A Git commit",
    "wikiDocumentation": "see https://git-scm.com/docs/git-commit",
    "cargo": "true"
  }]
}"""

        topic = Topic.from_wiki_json(jsonStr)
        self.assertTrue(isinstance(topic, Topic))
        self.assertEqual("Commits", topic.pluralName)
        self.assertEqual("Commit", topic.name)
        self.assertTrue(topic.cargo)

        # Test with properties
        json_props = """{ "data":[
            {
                "name":"property 1"
            },
            {
                "name":"property 2"
            },
            {
                "name":"property 3"
            }
        ]}"""
        prop_list = ["property 1", "property 2", "property 3"]
        topic_with_props = Topic.from_wiki_json(jsonStr, json_props)
        self.assertTrue(len(topic_with_props.properties) == 3)
        # Check if each item in properties is a Property and corresponds to exactly one of the given property configs
        for p in topic_with_props.properties:
            self.assertTrue(isinstance(p, Property))
            self.assertTrue(p.name in prop_list)
            prop_list.remove(p.name)
Beispiel #2
0
 def test_from_wiki_json(self):
     raw_data = {
         "data": [{
             "name": "Topic",
             "pluralName": "Topics",
             "listLimit": 42,
             "cargo": "f"
         }]
     }
     topic = Topic.from_wiki_json(json.dumps(raw_data), None)
     self.assertEqual("Topic", topic.name)
     self.assertEqual("Topics", topic.pluralName)
     self.assertTrue(topic.listLimit == 42)
     self.assertFalse(topic.cargo)
     topic_with_properties = Topic.from_wiki_json(
         json.dumps(raw_data),
         json.dumps({"data": [{
             "name": "prop1"
         }, {
             "name": "prop2"
         }]}))
     self.assertTrue(len(topic_with_properties.properties) == 2)
    def testWikiRender(self):
        if self.inPublicCI():
            return
        topicJson = """{"data": [{"pageName": "Concept:Task", "name": "Task", "pluralName": "Tasks", "documentation": "Problem or issue that needs to be solved", "wikiDocumentation": "Problem or issue that needs to be solved"}]}
        """
        propJson = """{
  "data": [{
    "pageName": "Property:Task goals",
    "name": "Task goals",
    "label": "Goals",
    "type": null,
    "index": null,
    "sortPos": null,
    "primaryKey": "f",
    "mandatory": "f",
    "namespace": null,
    "size": null,
    "uploadable": "f",
    "defaultValue": null,
    "inputType": "textarea",
    "allowedValues": null,
    "documentation": "Goals that must be achieved to complete the task",
    "values_from": null,
    "showInGrid": "f",
    "isLink": "f",
    "nullable": "f",
    "topic": "Concept:Task",
    "regexp": null
  }, {
    "pageName": "Property:Task procedure",
    "name": "Task procedure",
    "label": "Procedure",
    "type": null,
    "index": null,
    "sortPos": null,
    "primaryKey": "f",
    "mandatory": "f",
    "namespace": null,
    "size": null,
    "uploadable": "f",
    "defaultValue": null,
    "inputType": "textarea",
    "allowedValues": null,
    "documentation": "Explanation or hints how the task should be solved.",
    "values_from": null,
    "showInGrid": "f",
    "isLink": "f",
    "nullable": "f",
    "topic": "Concept:Task",
    "regexp": null
  }, {
    "pageName": "Property:Task task",
    "name": "Task task",
    "label": "Task",
    "type": null,
    "index": null,
    "sortPos": null,
    "primaryKey": "f",
    "mandatory": "f",
    "namespace": null,
    "size": null,
    "uploadable": "f",
    "defaultValue": null,
    "inputType": "text",
    "allowedValues": null,
    "documentation": "Description of the task defining briefly the topic of the task.",
    "values_from": null,
    "showInGrid": "f",
    "isLink": "f",
    "nullable": "f",
    "topic": "Concept:Task",
    "regexp": null
  }, {
    "pageName": "Property:Task workpackage",
    "name": "Task workpackage",
    "label": "assigned to",
    "type": "Special:Types/Page",
    "index": null,
    "sortPos": null,
    "primaryKey": "f",
    "mandatory": "f",
    "namespace": null,
    "size": null,
    "uploadable": "f",
    "defaultValue": null,
    "inputType": null,
    "allowedValues": null,
    "documentation": "Workpackage the task is assigned to",
    "values_from": "concept=Workpackage",
    "showInGrid": "f",
    "isLink": "f",
    "nullable": "f",
    "topic": "Concept:Task",
    "regexp": null
  }]
}"""
        topic = Topic.from_wiki_json(topicJson, propJson)
        self.assertEqual(4, len(topic.properties))
        wikiRender = WikiRender(debug=True)
        wikiRender.generateTopic(topic,
                                 path="/tmp/wikirender/unittest",
                                 overwrite=True)

        pass
Beispiel #4
0
    def main(self, argv=None):
        if argv is None:
            argv = sys.argv

        # Modes of operation
        UPDATE_TEMPLATES_MODE = "update_templates"
        CREATE_FILE_MODE = "create"
        GENERATE_ENTITY_PAGES = "generate_entity_pages"
        modes = [
            UPDATE_TEMPLATES_MODE, CREATE_FILE_MODE, GENERATE_ENTITY_PAGES
        ]

        # Setup argument parser
        self.getParser()
        try:
            # Process arguments
            args = self.parser.parse_args(argv)
            self.debug = args.debug
            if args.mode not in modes:
                raise Exception(
                    f"Please select of of the operation modes: {modes}")
            if args.mode == GENERATE_ENTITY_PAGES:
                # Check if necessary parameters are set
                if not args.properties_file or not args.topic_file:
                    raise Exception(
                        "The parameters --properties and --topics must be defined for this mode"
                    )
                if args.templates_folder:
                    # update templateEnv
                    self.template_env = self.getTemplateEnv(
                        additional_loader=args.template_folder)
                properties_json = ""
                print(1)
                with open(args.properties_file) as json_file:
                    properties_json = json_file.read()
                topic_json = ""
                with open(args.topic_file) as json_file:
                    topic_json = json_file.read()
                topic = Topic.from_wiki_json(topic_json=topic_json,
                                             prop_json=properties_json)
                # Generate and save the entity pages
                self.generateTopic(topic, args.backupPath, args.overwrite)
            elif args.mode == UPDATE_TEMPLATES_MODE:
                data = {}
                if "data_input" in args:
                    with open(args.data_input) as json_file:
                        data_str = json_file.read()
                        data = json.loads(data_str)
                elif args.stdin:
                    data = json.load(sys.stdin)
                else:
                    pass
                template_data = data.get(args.template)
                exclude_keys = ["pageTitle"]
                self.update_or_create_templates(template_data,
                                                name_id="pageTitle",
                                                template_name=args.template,
                                                exclude_keys=exclude_keys,
                                                backup_path=args.backupPath,
                                                overwrite=args.overwrite)

            if args.mode == CREATE_FILE_MODE:
                # ToDo
                pass

        except KeyboardInterrupt:
            ### handle keyboard interrupt ###
            return 1
        except Exception as e:
            raise e