def test_create_group_with_valid_json(): a = Content({ "id": "att35459744", "type": "attachment", "status": "current", "title": "Puppet Architecture.png", "metadata": { "comment": "Added by UWC, the Universal Wiki Converter", "mediaType": "image/png", "labels": { "results": [], "start": 0, "limit": 200, "size": 0, } }, "extensions": { "mediaType": "image/png", "fileSize": 61601, "comment": "Added by UWC, the Universal Wiki Converter" }, "_links": { "download": "/download/attachment/123454/Puppet%20Architecture.png" } }) assert str(a) == '35459744 - Puppet Architecture.png'
def test_create_with_minimal_json(): p = Content({ 'id': 1, 'title': 'Hello', 'status': 'current', 'type': 'page' }) assert str(p) == '1 - Hello'
def test_create_group_with_valid_json(): c = Content({ "id": "39128239", "type": "comment", "status": "current", "title": "Re: Puppet: Architecture Overview", "extensions": { "location": "inline", "_expandable": { "inlineProperties": "", "resolution": "" } } }) assert str(c) == '39128239 - Re: Puppet: Architecture Overview'
def __init__(self, json): # type: (Dict[str, Any]) -> None # All fields always exist on the json object self.id = json['id'] # type: int self.key = json['key'] # type: str self.name = json['name'] # type: str self.type = SpaceType(json['type']) # type: SpaceType # Description is expandable if 'description' in json: pass # TODO - Description comes back with `view` & `plain` expandable, not clear whether that's a common object so not handling for now # Homepage is an expandable full page object if 'homepage' in json: from confluence.models.content import Content self.homepage = Content(json['homepage']) # icon is expandable if 'icon' in json: self.icon = Icon(json['icon']) # metadata (inc labels) is expandable if 'metadata' in json: self.metadata = json['metadata'] # type: Dict[str, Any]
def test_create_complete(): p = Content({ "id": "65577", "type": "page", "status": "current", "title": "SandBox", "space": { "id": 98306, "key": "SAN", "name": "SandBox", "type": "global" }, "history": { "latest": True, "createdBy": { "type": "anonymous", "profilePicture": { "path": "anonymous.png", "width": 48, "height": 48, "isDefault": True }, "displayName": "Anonymous" }, "createdDate": "2017-09-22T11:03:07.420+01:00" }, "version": { "by": { "type": "known", "username": "******", "userKey": "12345", "profilePicture": { "path": "default.png", "width": 48, "height": 48, "isDefault": True }, "displayName": "user" }, "when": "2017-10-28T17:05:56.026+01:00", "message": "", "number": 8, "minorEdit": False, "hidden": False }, "body": { "storage": { "value": "", "representation": "storage", "_expandable": { "content": "/rest/api/content/65577" } } }, "metadata": { }, "extensions": { "position": "none" } }) assert p.body.storage == '' assert p.body.storage_representation == 'storage' assert not hasattr(p.body, 'edit') assert p.history.latest assert p.space.id == 98306