Skip to content

Commit

Permalink
save check of user ID and Readme&version upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
bensteUEM committed Jul 2, 2023
1 parent 8f7df19 commit 64363e0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
3 changes: 2 additions & 1 deletion CommuniApi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand All @@ -21,33 +22,35 @@ 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 = ###
```

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!
```

## 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
Expand Down
42 changes: 27 additions & 15 deletions tests/test_CommuniApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -172,34 +176,42 @@ 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
IMPORTANT - This test method and the parameters used depend on the target system!
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
Expand Down
2 changes: 1 addition & 1 deletion versions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

VERSION = '1.0.3'
VERSION = '1.0.4'

if __name__ == '__main__':
os.environ['VERSION'] = VERSION
Expand Down

0 comments on commit 64363e0

Please sign in to comment.