コード例 #1
0
 def test_render_entity(self):
     data = {
         "Property": "Property:Task goals",
         "name": "Task goals",
         "label": "Goals",
         "type": "Special:Types/Page",
         "index": None,
         "sortPos": None,
         "primaryKey": False,
         "mandatory": False,
         "namespace": None,
         "size": None,
         "uploadable": False,
         "defaultValue": None,
         "inputType": "tokens",
         "allowedValues": None,
         "documentation":
         "Goals that must be achieved to complete the task",
         "values_from": "concept=Goal",
         "showInGrid": False,
         "isLink": False,
         "nullable": False,
         "topic": "Concept:Task",
         "regexp": None
     }
     exp_template_oneliner = "{{Property|name=Task goals|label=Goals|type=Special:Types/Page|primaryKey=false|mandatory=false|uploadable=false|inputType=tokens|documentation=Goals that must be achieved to complete the task|values from=concept=Goal|showInGrid=false|isLink=false|nullable=false|topic=Concept:Task}}"
     exp_template_pretty = exp_template_oneliner.replace("|",
                                                         "\n|").replace(
                                                             "}}", "\n}}")
     property = Property(properties=data)
     self.assertEqual(exp_template_oneliner,
                      property.render_entity(oneliner=True))
     self.assertEqual(exp_template_pretty,
                      property.render_entity(oneliner=False))
コード例 #2
0
 def test_render_sample_entity_with_properties(self):
     exp_oneliner = "{{Event|EventTitle=Some Title|EventYear=Some Year}}"
     exp_pretty = "{{Event\n|EventTitle=Some Title\n|EventYear=Some Year\n}}"
     event = Topic({"pageName": "Concept:Event", "name": "Event", "pluralName": "Events"})
     properties = [Property({"pageName": "Property:Event title", "name": "EventTitle", "label": "Title"}),
                   Property({"pageName": "Property:Event year", "name": "EventYear", "label": "Year"})]
     self.assertEqual(exp_oneliner, SMW.render_sample_entity_with_properties(event, properties))
     self.assertEqual(exp_pretty, SMW.render_sample_entity_with_properties(event, properties, oneliner=False))
コード例 #3
0
 def test_set_entity_parameter(self):
     exp_oneliner = "{{#set:isA=Event|Event title={{{EventTitle|}}}|Event year={{{EventYear|}}}}}"
     exp_pretty = "{{#set:isA=Event\n|Event title={{{EventTitle|}}}\n|Event year={{{EventYear|}}}\n}}"
     event = Topic({"name": "Event", "pluralName": "Events"})
     event = Topic({"pageTitle": "Concept:Event", "name": "Event", "pluralName": "Events"})
     properties = [Property({"pageTitle": "Property:Event title", "name": "EventTitle", "label": "Title"}),
                   Property({"pageTitle": "Property:Event year", "name": "EventYear", "label": "Year"})]
     self.assertEqual(exp_oneliner, SMW.set_entity_parameter(event, properties, oneliner=True))
     self.assertEqual(exp_pretty, SMW.set_entity_parameter(event, properties, oneliner=False))
コード例 #4
0
 def test_get_incoming_edges(self):
     data = {
         "Property": "Property:Task goals",
         "name": "Task goals",
         "label": "Goals",
         "type": "Special:Types/Page",
         "index": None,
         "sortPos": None,
         "primaryKey": False,
         "mandatory": False,
         "namespace": None,
         "size": None,
         "uploadable": False,
         "defaultValue": None,
         "inputType": "tokens",
         "allowedValues": None,
         "documentation":
         "Goals that must be achieved to complete the task",
         "values_from": "concept=Goal",
         "showInGrid": False,
         "isLink": False,
         "nullable": False,
         "topic": "Concept:Task",
         "regexp": None
     }
     property = Property(properties=data)
     expected_res = {
         "target": "Goal",
         "source": "Task",
         "source_cardinality": "*",
         "target_cardinality": "*",
         "property": property
     }
     u = property.is_used_for()
     res = UML.get_incoming_edges_reduced(properties=[property],
                                          entity_name="Goal")
     self.assertTrue(len(res) == 1)
     for key in expected_res.keys():
         self.assertEqual(res[0][key], expected_res[key])
     # Change Property inputType to test if cardinality is extracted correctly
     property.inputType = "combobox"
     res_2 = UML.get_incoming_edges_reduced(properties=[property],
                                            entity_name="Goal")
     self.assertEqual(res_2[0]["target_cardinality"], "1")
     # Test if only the properties of the given entity are used for the extraction
     self.assertTrue(
         len(
             UML.get_incoming_edges_reduced(properties=[property],
                                            entity_name="NoTopic")) == 0)
コード例 #5
0
 def test_get_related_topics(self):
     # Test data containing one incoming and one outgoing edge from related topics
     data_properties = [{
         "Property": "Property:Task goals",
         "name": "Task goals",
         "label": "Goals",
         "type": "Special:Types/Page",
         "inputType": "tokens",
         "values_from": "concept=Goal",
         "topic": "Concept:Task"
     }, {
         "Property": "Property:Task ",
         "name": "Task description",
         "label": "Goals",
         "type": "Special:Types/Page",
         "inputType": "tokens",
         "values_from": "property=Task description",
         "topic": "Concept:Task"
     }, {
         "Property": "Property:Project tasks",
         "name": "Project tasks",
         "label": "Goals",
         "type": "Special:Types/Page",
         "inputType": "tokens",
         "values_from": "concept=Task",
         "topic": "Concept:Project"
     }]
     properties = [Property(x) for x in data_properties]
     rel_topic_names = Topic({
         "name": "Task",
         "pluralName": "Tasks"
     }).get_related_topics(properties)
     self.assertTrue(len(rel_topic_names) == 2)
     for name in rel_topic_names:
         self.assertTrue(name in ["Project", "Goal"])
コード例 #6
0
 def test_field(self):
     test_field = "{{{field|Country|input type=combobox|placeholder=e.g Germany|values from concept=Country|uploadable|unique}}}"
     data = {
         "property": "Property:Has location country",
         "name": "Country",
         "label": "Country",
         "type": "Special:Types/Page",
         "index": None,
         "sortPos": None,
         "primaryKey": True,
         "mandatory": False,
         "namespace": None,
         "size": None,
         "uploadable": True,
         "defaultValue": None,
         "inputType": "combobox",
         "allowedValues": None,
         "documentation": "Used to describe the country where something is located in.",
         "values_from": "concept=Country",
         "showInGrid": False,
         "isLink": False,
         "nullable": False,
         "topic": None,
         "regexp": None,
         "used_for": "Concept:Event",
         "placeholder": "e.g Germany"
     }
     property = Property(data)
     self.assertEqual(test_field, Form.field(property))
コード例 #7
0
 def test_get_page_link(self):
     p = Property({
         "name": "title",
         "label": "Title",
         "pageTitle": "Property:Event title"
     })
     self.assertEqual("[[Property:Event title|Title]]", p.get_page_link())
     p_without_pageTitle = Property({"name": "title", "label": "Title"})
     self.assertEqual("[[Property:title|Title]]",
                      p_without_pageTitle.get_page_link())
     p_without_label = Property({
         "name": "title",
         "pageTitle": "Property:Event title"
     })
     self.assertEqual("[[Property:Event title]]",
                      p_without_label.get_page_link())
コード例 #8
0
 def test_get_property_properties(self):
     #self.fail()
     # ToDo: Decide what the final Property properties are and test for them here
     property_properties = Property.get_property_properties()
     print(len(property_properties))
     self.assertTrue(len(property_properties) == 18)
     for property in property_properties:
         self.assertEqual("Property", property.topic)
     # test sorting of properties
     self.assertEqual("name", property_properties[0].name)
     self.assertEqual("label", property_properties[1].name)
     self.assertEqual("type", property_properties[2].name)
コード例 #9
0
 def test_get_primitive_properties(self):
     data = [{
         "name": "Property text",
         "type": "Special:Types/Text",
         "topic": "Concept:Test"
     }, {
         "name": "Property boolean",
         "type": "Special:Types/Boolean",
         "topic": "Concept:Test"
     }, {
         "name": "Property Number",
         "type": "Special:Types/Number",
         "topic": "Concept:Test"
     }, {
         "name": "Property Page",
         "type": "Special:Types/Page",
         "topic": "Concept:NonPrimitiveProperty"
     }]
     properties = [Property(x) for x in data]
     primtive_properties = Property.get_primitive_properties(
         entity_name="Test", properties=properties)
     self.assertTrue(len(primtive_properties) == len(data) - 1)
     for property in primtive_properties:
         self.assertEqual(property.topic, "Concept:Test")
コード例 #10
0
 def test_get_entity_properties(self):
     data = [{
         "name": "Property text",
         "type": "Special:Types/Text",
         "topic": "Concept:Test"
     }, {
         "name": "Property boolean",
         "type": "Special:Types/Boolean",
         "topic": "Concept:Test"
     }, {
         "name": "Property Number",
         "type": "Special:Types/Number",
         "topic": "Concept:Test2"
     }, {
         "name": "Property Page",
         "type": "Special:Types/Page",
         "topic": "Concept:Test3"
     }]
     properties = [Property(x) for x in data]
     properties_test = Property.get_entity_properties(entity_name="Test",
                                                      properties=properties)
     self.assertTrue(len(properties_test) == 2)
     for property in properties_test:
         self.assertEqual("Concept:Test", property.topic)
コード例 #11
0
 def testMetaModel(self):
     '''
     test the meta model
     '''
     context = Context({"name": "MetaModel"})
     self.assertEqual("MetaModel", context.name)
     topic = None
     # try:
     #    topic=Topic({"name":"Context","label":"Context"})
     #    self.fail("there should be an exception")
     # except Exception as ex:
     #    self.assertTrue("Invalid property 'label'" in str(ex))
     self.assertIsNone(topic)
     topic = Topic({"name": "Context", "pluralName": "Contexts"})
     self.assertEqual("Context", topic.name)
     self.assertEqual("Contexts", topic.pluralName)
     prop = Property({"name": "name", "label": "name"})
     self.assertEqual("name", prop.name)
     self.assertEqual("name", prop.label)
     self.assertIsNone(prop.type)
     pass
コード例 #12
0
ファイル: smw.py プロジェクト: tholzheim/wikirender
 def field(property: Property):
     """
     Get the form field of the given property
     Args:
         property: property for which the field should be rendered
     Returns:
         Returns a form field of given property
     """
     prop_map = {
         "inputType": "input_type",
         "placeholder": "placeholder",
         "defaultValue": "default",
         "values_from": "values_from",
         "uploadable": "uploadable",
         "primaryKey": "unique",
         "allowedValues": "values"
     }
     parameters = {}
     for prop in prop_map.keys():
         if prop == "inputType":
             if property.__dict__[prop] is None:
                 property.__dict__[prop] = "text"
             elif property.__dict__[prop].lower() == "textarea":
                 parameters["editor"] = "wikieditor"
         if prop in property.__dict__ and property.__dict__[
                 prop] is not None:
             if prop == "values_from":
                 # values_from contains data like "concept=Country" so we add an auxiliary property "values from concept" with the value "Country"
                 vals = property.__dict__[prop].split("=")
                 parameters[f"{prop_map[prop]} {vals[0]}"] = vals[1]
             else:
                 parameters[prop_map[prop]] = property.__dict__[prop]
             if prop == "inputType" and property.__dict__[prop] == "regexp":
                 parameters.update(Form.regexps.get(property.regexp))
     return Form.page_form_function(tag="field",
                                    **{
                                        property.name: True,
                                        **parameters
                                    })
コード例 #13
0
    def testPropertyFromJson(self):
        '''
        test loading/constructing from Json
        '''
        jsonStr = """{
        "data": 
[{
    "": "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
  }]
}"""
        props = Property.from_wiki_json(jsonStr)
        self.assertTrue(isinstance(props, Property))
        self.assertEqual("Goals", props.label)
        self.assertFalse(props.showInGrid)
        # check if null in converted to None
        self.assertIsNone(props.values_from)
コード例 #14
0
 def test_get_incoming_edges_reduced(self):
     data = [{
         "Property": "Property:Task goals",
         "name": "Task goals",
         "label": "Goals",
         "type": "Special:Types/Page",
         "index": None,
         "sortPos": None,
         "primaryKey": False,
         "mandatory": False,
         "namespace": None,
         "size": None,
         "uploadable": False,
         "defaultValue": None,
         "inputType": "tokens",
         "allowedValues": None,
         "documentation":
         "Goals that must be achieved to complete the task",
         "values_from": "concept=Goal",
         "showInGrid": False,
         "isLink": False,
         "nullable": False,
         "topic": "Concept:Project",
         "regexp": None
     }, {
         "Property": "Property:Project goals",
         "name": "Project goals",
         "label": "Goals",
         "type": "Special:Types/Page",
         "index": None,
         "sortPos": None,
         "primaryKey": False,
         "mandatory": False,
         "namespace": None,
         "size": None,
         "uploadable": False,
         "defaultValue": None,
         "inputType": "tokens",
         "allowedValues": None,
         "documentation":
         "Goals that must be achieved to complete the task",
         "values_from": "concept=Goal",
         "showInGrid": False,
         "isLink": False,
         "nullable": False,
         "topic": "Concept:Project",
         "regexp": None
     }]
     properties = [Property(p) for p in data]
     expected_res = {
         "target": "Goal",
         "source": "Project",
         "source_cardinality": "*",
         "target_cardinality": "*",
         "properties": ["Task goals", "Project goals"]
     }
     res = UML.get_incoming_edges_reduced(properties=properties,
                                          entity_name="Goal")
     self.assertTrue(len(res) == 1)
     for key in expected_res.keys():
         self.assertEqual(res[0][key], expected_res[key])
     # Test if only the properties of the given entity are used for the extraction
     self.assertTrue(
         len(
             UML.get_incoming_edges_reduced(properties=properties,
                                            entity_name="NoTopic")) == 0)
コード例 #15
0
    def test_form_table(self):
        exp_form_table = """{| class="wikitable mw-collapsible" style="width:100%" 
|-
|colspan="2"  |Basic Information
|-
!style="text-align: left"  |[[Task goals::@@@|goals]]:
|{{{field|Task goals|input type=tokens|values from concept=Goal}}}
|-
!style="text-align: left"  |[[Task description::@@@|description]]<span style="color:#f00">*</span>:
|{{{field|description|input type=text}}}
|}"""
        data = [{
            "pageTitle": "Property:Task goals",
            "name": "Task goals",
            "label": "goals",
            "type": "Special:Types/Page",
            "index": None,
            "sortPos": None,
            "primaryKey": False,
            "mandatory": False,
            "namespace": None,
            "size": None,
            "uploadable": False,
            "defaultValue": None,
            "inputType": "tokens",
            "allowedValues": None,
            "documentation": "Goals that must be achieved to complete the task",
            "values_from": "concept=Goal",
            "showInGrid": False,
            "isLink": False,
            "nullable": False,
            "topic": "Concept:Task",
            "regexp": None
        },
            {
                "pageTitle": "Property:Task description",
                "name": "description",
                "label": "description",
                "type": "Special:Types/Test",
                "index": None,
                "sortPos": None,
                "primaryKey": False,
                "mandatory": True,
                "namespace": None,
                "size": None,
                "uploadable": False,
                "defaultValue": None,
                "inputType": "text",
                "allowedValues": None,
                "documentation": "Goals that must be achieved to complete the task",
                "values_from": None,
                "showInGrid": False,
                "isLink": False,
                "nullable": False,
                "topic": "Concept:Task",
                "regexp": None
            }
        ]
        properties = [Property(p) for p in data]
        actual_form_table = Form.form_table("Basic Information", properties)
        self.assertEqual(exp_form_table, actual_form_table)