Ejemplo n.º 1
0
 def fromJsonObj(cls, con: Connection, json_obj: Any):
     id = json_obj.get('id')
     if id is None:
         raise BaseError('Group "id" is missing')
     name = json_obj.get('name')
     if name is None:
         raise BaseError('Group "name" is missing')
     descriptions = LangString.fromJsonObj(json_obj.get('descriptions'))
     tmp = json_obj.get('project')
     if tmp is None:
         raise BaseError('Group "project" is missing')
     project = tmp.get('id')
     if project is None:
         raise BaseError('Group "project" has no "id"')
     selfjoin = json_obj.get('selfjoin')
     if selfjoin is None:
         raise BaseError("selfjoin is missing")
     status = json_obj.get('status')
     if status is None:
         raise BaseError("Status is missing")
     return cls(con=con,
                name=name,
                id=id,
                descriptions=descriptions,
                project=project,
                selfjoin=selfjoin,
                status=status)
Ejemplo n.º 2
0
 def test_langstring_fromjson(self) -> None:
     """Test reading a LangString from JSON as used in Knora Admin."""
     test = [{
         'language': 'en',
         'value': self.test_string_en
     }, {
         'language': 'de',
         'value': self.test_string_de
     }]
     ls = LangString.fromJsonObj(test)
     self.assertEqual(ls['de'], self.test_string_de)
     self.assertEqual(ls[Languages.EN], self.test_string_en)