def test_retrieve_group_items(self): """ Test retrieving group content """ print(self.basetestpath) endpoint = self.basetestpath + '/group_items_fake_qgis_http_endpoint' with open(sanitize(endpoint + '_groups/', 'ab1?f=json&start=1&num=2'), 'wb') as f: f.write("""{ "total": 3, "start": 1, "num": 2, "nextStart": 3, "items": [ { "id": "74", "title": "Item 1" }, { "id": "20", "title": "Item 2" } ] }""".encode('UTF-8')) with open( sanitize(endpoint + '_groups/', 'ab1?f=json&start=3&num=2'), 'wb') as f: f.write("""{ "total": 3, "start": 3, "num": 1, "nextStart": 3, "items": [ { "id": "75", "title": "Item 3" } ] }""".encode('UTF-8')) res = QgsArcGisPortalUtils.retrieveGroupContent('http://' + endpoint, 'ab1', '', pageSize=2) # no errors self.assertFalse(res[1]) self.assertFalse(res[2]) self.assertEqual(res[0], [{ 'id': '74', 'title': 'Item 1' }, { 'id': '20', 'title': 'Item 2' }, { 'id': '75', 'title': 'Item 3' }])
def testUserInfoExplicit(self): """ Test retrieving explicitly specified user info """ print(self.basetestpath) endpoint = self.basetestpath + '/user_fake_qgis_http_endpoint' with open(sanitize(endpoint + '_users/', 'some_user?f=json'), 'wb') as f: f.write("""{ "username": "******", "id": "2b", "groups": [ { "id": "c4", "title": "A Group" }, { "id": "d4", "title": "Another Group" } ] }""".encode('UTF-8')) headers = {'referer': 'http://google.com'} res = QgsArcGisPortalUtils.retrieveUserInfo('http://' + endpoint, 'some_user', '', headers) # no errors self.assertFalse(res[1]) self.assertFalse(res[2]) self.assertEqual( res[0], { 'groups': [{ 'id': 'c4', 'title': 'A Group' }, { 'id': 'd4', 'title': 'Another Group' }], 'id': '2b', 'username': '******' })
def testUserInfoSelf(self): """ Test retrieving logged on user info """ print(self.basetestpath) endpoint = self.basetestpath + '/user_fake_qgis_http_endpoint' with open(sanitize(endpoint, '/self?f=json'), 'wb') as f: f.write("""{ "username": "******", "id": "2a", "groups": [ { "id": "c4", "title": "A Group" }, { "id": "d4", "title": "Another Group" } ] }""".encode('UTF-8')) res = QgsArcGisPortalUtils.retrieveUserInfo('http://' + endpoint, '', '') # no errors self.assertFalse(res[1]) self.assertFalse(res[2]) self.assertEqual( res[0], { 'groups': [{ 'id': 'c4', 'title': 'A Group' }, { 'id': 'd4', 'title': 'Another Group' }], 'id': '2a', 'username': '******' })
def test_retrieve_groups(self): """ Test retrieving user groups """ print(self.basetestpath) endpoint = self.basetestpath + '/group_fake_qgis_http_endpoint' with open(sanitize(endpoint + '_users/', 'some_user?f=json'), 'wb') as f: f.write("""{ "username": "******", "id": "2b", "groups": [ { "id": "c4", "title": "A Group" }, { "id": "d4", "title": "Another Group" } ] }""".encode('UTF-8')) res = QgsArcGisPortalUtils.retrieveUserGroups('http://' + endpoint, 'some_user', '') # no errors self.assertFalse(res[1]) self.assertFalse(res[2]) self.assertEqual(res[0], [{ 'id': 'c4', 'title': 'A Group' }, { 'id': 'd4', 'title': 'Another Group' }])