Skip to content

Commit 5c2902a

Browse files
authored
Merge pull request #13 from Flying-Free/dev
v0.4
2 parents 0220226 + 3d19305 commit 5c2902a

File tree

7 files changed

+59
-2
lines changed

7 files changed

+59
-2
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION="v0.3"
1+
VERSION="v0.4"

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2121
}
2222
```
2323

24+
## [v0.4](https://github.com/Flying-Free/pyopenproject/releases/tag/v0.4) - 2021-03-08
25+
26+
Beta version of pyopenproject library. This library is a way to enable Python developers to communicate with
27+
the [OpenProject API](https://docs.openproject.org/api/) with simplicity. Take in consideration that this development is
28+
only available for Python 3.6 or more.
29+
30+
### Added
31+
32+
- Users's FindByContext class. Now, _pyopenproject_ can requests a user by its context.
33+
34+
## [v0.4-beta.1](https://github.com/Flying-Free/pyopenproject/releases/tag/v0.4-beta.1) - 2021-03-08
35+
36+
Beta version of pyopenproject library. This library is a way to enable Python developers to communicate with
37+
the [OpenProject API](https://docs.openproject.org/api/) with simplicity. Take in consideration that this development is
38+
only available for Python 3.6 or more.
39+
40+
### Added
41+
42+
- Users's FindByContext class. Now, _pyopenproject_ can requests a user by its context.
43+
2444
## [v0.3](https://github.com/Flying-Free/pyopenproject/releases/tag/v0.3) - 2021-03-03
2545

2646
Beta version of pyopenproject library. This library is a way to enable Python developers to communicate with

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ env_up:
3333

3434
pytest:
3535
- ${PYTHON} -m coverage run -m unittest discover -s ./tests/test_cases -t tests/test_cases -p *_test.py
36-
- ${PYTHON} -m coverage report -m
3736

3837
env_down:
3938
cd ./tests/infra && \
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from pyopenproject.api_connection.exceptions.request_exception import RequestError
2+
from pyopenproject.api_connection.requests.get_request import GetRequest
3+
from pyopenproject.business.exception.business_error import BusinessError
4+
from pyopenproject.business.services.command.user.user_command import UserCommand
5+
from pyopenproject.model.user import User
6+
7+
8+
class FindByContext(UserCommand):
9+
10+
def __init__(self, connection, context):
11+
"""
12+
Contructor for class FindByContext, from UserCommand
13+
14+
:param connection: The connection data
15+
:param context: The user's url context
16+
"""
17+
super().__init__(connection)
18+
self.context = context
19+
20+
def execute(self):
21+
try:
22+
json_obj = GetRequest(self.connection, f"{self.context}").execute()
23+
return User(json_obj)
24+
except RequestError as re:
25+
raise BusinessError(f"Error finding user by context: {self.context}") from re

pyopenproject/business/services/user_service_impl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from pyopenproject.business.services.command.user.delete import Delete
33
from pyopenproject.business.services.command.user.find import Find
44
from pyopenproject.business.services.command.user.find_all import FindAll
5+
from pyopenproject.business.services.command.user.find_by_context import FindByContext
56
from pyopenproject.business.services.command.user.invite import Invite
67
from pyopenproject.business.services.command.user.lock import Lock
78
from pyopenproject.business.services.command.user.unlock import Unlock
@@ -26,6 +27,9 @@ def find_all(self, filters=None, sort_by=None):
2627
def find(self, user):
2728
return Find(self.connection, user).execute()
2829

30+
def find_by_context(self, context):
31+
return FindByContext(self.connection, context).execute()
32+
2933
def update(self, user):
3034
return Update(self.connection, user).execute()
3135

pyopenproject/business/user_service.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def find_all(self, filters, sort_by): raise NotImplementedError
1919
@abstractmethod
2020
def find(self, user): raise NotImplementedError
2121

22+
@abstractmethod
23+
def find_by_context(self, context): raise NotImplementedError
24+
2225
@abstractmethod
2326
def lock(self, user): raise NotImplementedError
2427

tests/test_cases/user_service_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ def test_find(self):
4242
expected = self.usrSer.find(self.user)
4343
self.assertEqual(self.user.name, expected.name)
4444

45+
def test_find_by_context(self):
46+
current = self.usrSer.find(self.user)
47+
expected = self.usrSer.find_by_context(self.user.__dict__["_links"]["self"]["href"])
48+
self.assertEqual(self.user.name, expected.name)
49+
self.assertEqual(current.__dict__, expected.__dict__)
50+
4551
def test_not_found(self):
4652
user = User({"id": 50})
4753
# Result is 404

0 commit comments

Comments
 (0)