Projet

Général

Profil

0001-toulouse_smart-ignore-smart-properties-having-unknow.patch

Nicolas Roche, 27 janvier 2022 17:46

Télécharger (2,88 ko)

Voir les différences:

Subject: [PATCH] toulouse_smart: ignore smart properties having unknown type
 (#60989)

 passerelle/contrib/toulouse_smart/models.py | 7 ++++++-
 tests/test_toulouse_smart.py                | 9 +++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
passerelle/contrib/toulouse_smart/models.py
60 60

  
61 61
        try:
62 62
            url = self.webservice_base_url + 'v1/type-intervention'
63 63
            response = self.requests.get(url)
64 64
            doc = ET.fromstring(response.content)
65 65
            intervention_types = []
66 66
            for xml_item in doc:
67 67
                item = xml.to_json(xml_item)
68
                for prop in item.get('properties', []):
68
                properties = item.pop('properties', [])
69
                for prop in properties:
69 70
                    prop['required'] = prop.get('required') == 'true'
70 71
                    if prop.get('restrictedValues'):
71 72
                        prop['type'] = 'item'
73
                    if prop.get('type') in ('string', 'int', 'boolean', 'item'):
74
                        if not 'properties' in item:
75
                            item['properties'] = []
76
                        item['properties'].append(prop)
72 77
                intervention_types.append(item)
73 78
            intervention_types.sort(key=lambda x: x['name'])
74 79
            for i, intervention_type in enumerate(intervention_types):
75 80
                intervention_type['order'] = i + 1
76 81
        except Exception:
77 82
            try:
78 83
                return self.get('intervention-types')
79 84
            except KeyError:
tests/test_toulouse_smart.py
151 151
              </restrictedValues>
152 152
           </properties>
153 153
           <properties>
154 154
              <name>FIELD2</name>
155 155
              <displayName>Champ 2</displayName>
156 156
              <type>int</type>
157 157
              <required>true</required>
158 158
           </properties>
159
           <properties>
160
              <name>IGNORED-FIELD-HAVING-NO-TYPE</name>
161
              <displayName>Champ 3</displayName>
162
           </properties>
163
          <properties>
164
              <name>IGNORED-FIELD-HAVING-UNKNOWN-TYPE</name>
165
              <displayName>Champ 3</displayName>
166
              <type>plop</type>
167
           </properties>
159 168
       </properties>
160 169
   </item>
161 170
   <item>
162 171
       <id>0002</id>
163 172
       <name>empty</name>
164 173
   </item>
165 174
</List>'''.encode()
166 175

  
167
-