diff --git a/CommuniApi/__init__.py b/CommuniApi/__init__.py index a304322..468bd0b 100644 --- a/CommuniApi/__init__.py +++ b/CommuniApi/__init__.py @@ -60,7 +60,8 @@ def login(self): logging.warn(f'Login with App-ID:{self.communi_appid} did not return groups - either APP-ID wrong or empty app') return False else: - del self.user_id + if hasattr(self,'user_id'): + del self.user_id logging.debug("Login failed with {}".format(response.content)) return False diff --git a/README.md b/README.md index 151bc6c..d5cf0a3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Setup -This code requires a config.py within the "secure" folder in order to work +CommuniApi class requires params for your Communi configuration. ## Initial configuration This package requires the ChurchToolsApi to be installed. @@ -9,8 +9,9 @@ If you only downloaded this code without package management you will need to ins Check https://github.com/bensteUEM/ChurchToolsAPI/releases for the latest realease. -### Server connection +### How to use with config.py By default some changes need to be made to config.py before first use. +(if you want to use it as config params) 1 Get your REST access token from your instance e.g. https://YOURINSTANCE.communiapp.de/page/integration/tab/rest @@ -21,16 +22,17 @@ token = 'ENTER-YOUR-TOKEN-HERE' All requests are executed against the central REST server of communi which is part of the default config This part does likely not need any change unless you have a special configuration. ``` -rest_server = 'api.communiapp.de/rest/' +rest_server = 'https://api.communiapp.de/rest' ``` In order to addres your own instance (matching to the token) you need to change the communiApp in the config +Please note that the AppID is NOT the same as the primary group ID. As this is undocumented please consult with Communi to retrieve your ID or reverse engineer using a web-client. ``` communiApp = 0 ``` In addition the login details for a ChurchTools instance is required for CT specific access ``` -ct_domain = 'http://XXX' +ct_domain = 'https://XXX' ct_token = ### ``` @@ -38,8 +40,9 @@ ct_users = {'username': 'test'} # Usage -The script was coded using PyCharm Community edition. It is highly recomended to run the test cases successfully before use. -Please be aware that some of the test cases require specific IDs to be present on your instance. +The script is maintained using VS Studio Code. +Test cases are run against my own instance - please adapt to yours before changing any code and make sure they run successfully! +Be aware that some of the test cases require specific IDs to be present on your instance. The respective function do have a hint like the one below in the docstring of the respective functions ``` IMPORTANT - This test method and the parameters used depend on the target system! @@ -47,7 +50,7 @@ IMPORTANT - This test method and the parameters used depend on the target system ## Compatibility -Tested against the current CommuniAPIs as of January 2023. +Tested against the current CommuniAPIs as of July 2023. More information is provided on the respective Communi pages. # License diff --git a/tests/test_CommuniApi.py b/tests/test_CommuniApi.py index b2848b9..aa3beef 100644 --- a/tests/test_CommuniApi.py +++ b/tests/test_CommuniApi.py @@ -148,22 +148,26 @@ def test_userGroupList(self): IMPORTANT - This test method and the parameters used depend on the target system! :return: """ - userId = 28057 - groupId = 21037 + user_id = 28057 + group_id = self.api.createGroup("_test_userGroupList ", 'If this group exists some test failed - please delete')['id'] + self.api.changeUserGroup(userId=user_id, groupId=group_id, add_user=True) result = self.api.getUserGroupList() self.assertGreater(len(result), 0) - result = self.api.getUserGroupList(user=userId) + result = self.api.getUserGroupList(user=user_id) self.assertGreater(len(result), 1) - result = self.api.getUserGroupList(group=groupId) + result = self.api.getUserGroupList(group=group_id) self.assertGreater(len(result), 1) - result = self.api.getUserGroupList(group=groupId, user=userId) + result = self.api.getUserGroupList(group=group_id, user=user_id) self.assertEqual(1, len(result)) - self.assertEqual(result[0]['user'], userId) - self.assertEqual(result[0]['group'], groupId) + self.assertEqual(result[0]['user'], user_id) + self.assertEqual(result[0]['group'], group_id) + + result = self.api.deleteGroup(id=group_id) + self.assertTrue(result) def test_changeUserGroup(self): """ @@ -172,21 +176,25 @@ def test_changeUserGroup(self): Testing with userID 28057 (admin) and groupID 21037 (_TEST Gruppe - UserAdd) :return: """ - userID = 28057 - groupID = 21037 + user_id = 28057 + group_id= self.api.createGroup("_test_changeUserGroup ", 'If this group exists some test failed - please delete')['id'] self.assertFalse(self.api.changeUserGroup(0, 0, False)) - self.assertTrue(self.api.changeUserGroup(userID, groupID, True)) + self.assertTrue(self.api.changeUserGroup(user_id, group_id, True)) - test_result = self.api.getUserGroupList(user=userID, group=groupID) + test_result = self.api.getUserGroupList(user=user_id, group=group_id) self.assertEqual(len(test_result), 1) self.assertEqual(test_result[0]['status'], 2) self.assertFalse(self.api.changeUserGroup(0, 0, False)) - self.assertTrue(self.api.changeUserGroup(userID, groupID, False)) - test_result = self.api.getUserGroupList(user=userID, group=groupID) + self.assertTrue(self.api.changeUserGroup(user_id, group_id, False)) + test_result = self.api.getUserGroupList(user=user_id, group=group_id) self.assertEqual(test_result[0]['status'], 4) + result = self.api.deleteGroup(id=group_id) + self.assertTrue(result) + + def test_message(self): """ Attempts to post a chat message text into a test group @@ -194,12 +202,16 @@ def test_message(self): groupID 21037 (_TEST Gruppe - UserAdd) :return: """ - groupId = 21037 + group_id= self.api.createGroup("_test_message ", 'If this group exists some test failed - please delete')['id'] + timestamp = datetime.now() - result = self.api.message(groupId=groupId, + result = self.api.message(groupId=group_id, text="Hello World from test_postInGroup - on {}".format(timestamp)) self.assertTrue(result) + result = self.api.deleteGroup(id=group_id) + self.assertTrue(result) + def test_create_event_chats(self): """ Testing method to check if event creation and user update works diff --git a/versions.py b/versions.py index 1e203dc..a8fb374 100644 --- a/versions.py +++ b/versions.py @@ -1,6 +1,6 @@ import os -VERSION = '1.0.3' +VERSION = '1.0.4' if __name__ == '__main__': os.environ['VERSION'] = VERSION