class TestConfluence(unittest.TestCase): def setUp(self): self.space = 'SPACE' self.slug = "example-page" self.api = Confluence(api_url='https://wiki.example.com/rest/api', username='******', password='******') def testPostExists(self): response = { "results": [ { "id": "1234567", "type": "page", "status": "current", "title": "Example Page", "restrictions": {}, }, ], "start": 0, "limit": 25, "size": 1 } client = MockConfluenceClient(response=response, status=200, is_json=True) self.api._session = client got = self.api.exists(slug=self.slug) self.assertTrue(got) def testPostDoesntExist(self): response = { "results": [], "start": 0, "limit": 25, "size": 0, } client = MockConfluenceClient(response=response, status=200, is_json=True) self.api._session = client got = self.api.exists(slug=self.slug) self.assertFalse(got) def testLabelCreation(self): slug = 'example-post' tags = ['knowledge', 'testing'] expected = [{ 'prefix': DEFAULT_LABEL_PREFIX, 'name': slug }, { 'prefix': DEFAULT_LABEL_PREFIX, 'name': 'knowledge' }, { 'prefix': DEFAULT_LABEL_PREFIX, 'name': 'testing' }] client = MockConfluenceClient(response={}, status=200, is_json=True) self.api._session = client self.api.create_labels(page_id='12345', slug=slug, tags=tags) sent = self.api._session.requests[0] self.assertEqual(len(sent['json']), len(expected)) for label in expected: self.assertIn(label, sent['json']) def testGetAuthor(self): userKey = '1234567890' expected = { "type": "known", "username": "******", "userKey": userKey, "profilePicture": { "path": "/download/attachments/123456/user-avatar", "width": 48, "height": 48, "isDefault": False }, "displayName": "Foo Bar" } client = MockConfluenceClient(response=expected, status=200, is_json=True) self.api._session = client got = self.api.get_author('foo') self.assertEqual(got['userKey'], userKey)