Add some first unit tests

This commit is contained in:
2024-02-23 20:42:16 +00:00
parent 229281c5ff
commit 81fe923fb3
6 changed files with 149 additions and 24 deletions
+29 -17
View File
@@ -2,6 +2,7 @@ import configparser
import logging
from pprint import pprint
from ActiveCollabAPI import AC_LOGIN_BASE_URL
from ActiveCollabAPI.ACAuthenticator import ACAuthenticator
from ActiveCollabAPI.ACClient import ACClient
from ActiveCollabAPI.ACTokenAuthenticator import ACTokenAuthenticator
@@ -19,7 +20,8 @@ requests_log = logging.getLogger("urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
if __name__ == "__main__":
def main():
config = configparser.ConfigParser()
config.read('config.ini')
@@ -28,32 +30,37 @@ if __name__ == "__main__":
account_name = config['LOGIN']['account_name']
# 1. you need to log in to get a session and a list of accounts
auth = ACAuthenticator()
session = auth.login(username, password)
pprint(session)
user = session['user']
auth = ACAuthenticator(AC_LOGIN_BASE_URL)
auth.login_with_check(username, password)
# use first account
account = auth.find_account(account_name)
# 2. you need to get a token for this account
# token = ACTokenAuthenticator(account, user).issue_token_intent()
token = ACTokenAuthenticator(account, auth.user).issue_token_intent()
# pprint(token)
# 3. now you can query the API
# ac = ACClient(account, token)
ac = ACClient(account, token)
# check version
res = ac.get_info()
ac_version = res.json()
pprint(ac_version)
if ac_version['version'] != '7.4.337':
raise Exception("Supporting only Version 7.4.337!")
# get a list of all projects
# res = ac.get_projects()
# pprint(res.json())
# get task with sub tasks
# https://app.activecollab.com/416910/projects/310/tasks/6274
# get task with sub-tasks
# "https://app.activecollab.com/416910/projects/310/tasks/6260"
# project_id = 310
# task_id = 6281
# task_id = 6260
# task_res = ac.get_project_task(project_id, task_id)
# pprint(task_res.json())
# task = task_res.json()
# res = ac.unassign_all_sub_task(task)
# ac.delete_all_open_subtasks(task)
# create a new subtask for the task without assignment
# subtask = {
@@ -66,10 +73,10 @@ if __name__ == "__main__":
# pprint(res.json())
# # bulk create subtasks
subtask_texts = []
with open("sub-tasks.txt", "r", encoding="utf-8") as fh:
for line in fh:
subtask_texts.append(line.rstrip('\n'))
# subtask_texts = []
# with open("sub-tasks.txt", "r", encoding="utf-8") as fh:
# for line in fh:
# subtask_texts.append(line.rstrip('\n'))
# create
# for text in subtask_texts:
# subtask['body'] = text
@@ -98,5 +105,10 @@ if __name__ == "__main__":
# res = ac.delete_subtask(subtask)
# pprint(res.json())
# res = ac.get_info()
# pprint(res.json())
res = ac.get_projects()
if res.status_code == 200:
pprint(res.json())
if __name__ == "__main__":
main()