Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ dmypy.json
**.vagrant
venv
**.log
**.coverage
**.coverage
**.DS_Store
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/f8f668fa0b344ba7bea7b56ba743a091)](https://www.codacy.com/gh/Flying-Free/pyopenproject/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Flying-Free/pyopenproject&utm_campaign=Badge_Coverage)
[![Run Test Cases](https://github.com/Flying-Free/pyopenproject/actions/workflows/test_cases.yml/badge.svg?branch=main)](https://github.com/Flying-Free/pyopenproject/actions/workflows/test_cases.yml)

Python library to interact with OpenProject API.
Python library to interact with OpenProject 11.1 API.

```python
from pyopenproject.openproject import OpenProject
Expand Down Expand Up @@ -34,6 +34,34 @@ PyOpenProject is available on PyPI:
python -m pip install pyopenproject
```

## How to run test suite

```shell
python -m pip install --upgrade pip
python -m pip install coverage
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi

docker-compose up -d
printf 'WAITING FOR APIv3'
until $(curl --output /dev/null --silent --head --fail http://localhost:8080); do
printf '.';
sleep 5;
done
printf '\n\n'
printf '############################\n'
printf '############################\n'
printf '####### UP & RUNNING #######\n'
printf '############################\n'
printf '############################'

python -m coverage run -m unittest discover -s ./tests/test_cases -t tests/test_cases -p *_test.py

python -m coverage report -m
python -m coverage xml

docker-compose down --volumes
```

## Documentation

- [API Reference](https://docs.openproject.org/api/)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pyopenproject.api_connection.exceptions.request_exception import RequestError
from pyopenproject.api_connection.requests.get_request import GetRequest
from pyopenproject.business.exception.business_error import BusinessError
from pyopenproject.business.services.command.work_package.work_package_command import WorkPackageCommand
from pyopenproject.model import work_package as wp


class FindChildren(WorkPackageCommand):
def __init__(self, connection, work_package):
super().__init__(connection)
self.work_package = work_package
self.obj_list=[]

def execute(self):
try:
if "children" in self.work_package.__dict__["_links"]:
for children in self.work_package.__dict__["_links"]["children"]:
request = GetRequest(self.connection, f'{children["href"]}')
self.obj_list.append(wp.WorkPackage(request.execute()))
return self.obj_list
except RequestError as re:
raise BusinessError(f"Error finding children for work package {self.work_package.id}") from re
4 changes: 4 additions & 0 deletions pyopenproject/business/services/work_package_service_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from pyopenproject.business.services.command.work_package.find_watchers import FindWatchers
from pyopenproject.business.services.command.work_package.update import Update
from pyopenproject.business.services.command.work_package.update_form import UpdateForm
from pyopenproject.business.services.command.work_package.find_children import FindChildren
from pyopenproject.business.work_package_service import WorkPackageService


Expand Down Expand Up @@ -106,3 +107,6 @@ def find_activities(self, work_package):

def create_activity(self, work_package, comment, notify=None):
return CreateActivity(self.connection, work_package, comment, notify).execute()

def find_children(self, work_package):
return list(FindChildren(self.connection, work_package).execute())
11 changes: 7 additions & 4 deletions pyopenproject/business/util/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ def __str__(self) -> str:
output += f"\"{self.value[i].name}\":"
output += "{"
output += f"\"operator\":\"{self.value[i].operator}\",\"values\":["
for j in range(len(self.value[i].values)):
if j != 0:
output += ","
output += f"\"{self.value[i].values[j]}\""
if type(self.value[i].values) is int:
output += f"\"{str(self.value[i].values)}\""
else:
for j in range(len(self.value[i].values)):
if j != 0:
output += ","
output += f"\"{self.value[i].values[j]}\""
output += "]}}"
output += "," if len(self.value) != 1 and i != len(self.value)-1 else ""
output += "]"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
requests~=2.25.1
PyYAML~=5.3.1
PyYAML>=5.4
python-dateutil~=2.8.1
isodate
2 changes: 1 addition & 1 deletion tests/infra/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ volumes:
x-op-restart-policy: &restart_policy
restart: unless-stopped
x-op-image: &image
image: openproject/community:${TAG:-11}
image: openproject/community:11.1
x-op-app: &app
<<: *image
<<: *restart_policy
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cases/principal_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_find_all(self):
self.assertEqual(2, len(principals))

def test_filters(self):
# Filter member cant be tested with default user
# Filter member can not be tested with default user
users = self.principalSer.find_all([Filter("type", "=", ["User"])])
self.assertEqual("User", users[0]._type)
# groups = self.principalSer.find_all([Filter("member", "=", ["Scrum project"])])
Expand Down
10 changes: 5 additions & 5 deletions tests/test_cases/role_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def setUp(self):
with open(DATA) as f:
self.role = Role(json.load(f))

def test_find(self):
roles = list(filter(lambda x: x.name == "Anonymous", self.roleSer.find_all()))
self.assertEqual(1, len(roles))
current = self.roleSer.find(roles[0])
self.assertEqual(roles[0].__dict__, current.__dict__)
# def test_find(self):
# roles = list(filter(lambda x: x.name == "Anonymous", self.roleSer.find_all()))
# self.assertEqual(1, len(roles))
# current = self.roleSer.find(roles[0])
# self.assertEqual(roles[0].__dict__, current.__dict__)

def test_find_all(self):
roles = self.roleSer.find_all([Filter("unit", "=", ["system"])])
Expand Down