Skip to content

Commit

Permalink
Merge pull request #76 from Crown-Commercial-Service/feature/DMP-632-…
Browse files Browse the repository at this point in the history
…add-system-message-parts

DMP-632 - Make updates for new system message model
  • Loading branch information
tim-s-ccs authored May 16, 2024
2 parents 2965102 + aadcc06 commit 6c0d7ba
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dmapiclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '25.9.0'
__version__ = '25.10.0'

from .errors import APIError, HTTPError, InvalidResponse # noqa
from .errors import REQUEST_ERROR_STATUS_CODE, REQUEST_ERROR_MESSAGE # noqa
Expand Down
4 changes: 4 additions & 0 deletions dmapiclient/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ class AuditTypes(Enum):
send_communication_message = "send_communication_message"
read_communication_message = "read_communication_message"

# System message
create_system_message = "create_system_message"
update_system_message = "update_system_message"

@staticmethod
def is_valid_audit_type(test_audit_type):

Expand Down
50 changes: 50 additions & 0 deletions dmapiclient/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1391,3 +1391,53 @@ def create_communication(
},
user=user,
)

def get_system_message(self, slug):
return self._get(
"/system-messages/{}".format(slug)
)

def create_system_message(
self,
slug,
data,
show=None,
user=None
):
system_message = {
"slug": slug,
"data": data,
}

if show is not None:
system_message["show"] = show

return self._post_with_updated_by(
"/system-messages",
data={
"systemMessages": system_message,
},
user=user,
)

def update_system_message(
self,
slug,
data,
show=None,
user=None
):
system_message = {
"data": data,
}

if show is not None:
system_message["show"] = show

return self._post_with_updated_by(
"/system-messages/{}".format(slug),
data={
"systemMessages": system_message,
},
user=user,
)
199 changes: 199 additions & 0 deletions tests/test_data_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3506,3 +3506,202 @@ def test_create_communication_with_attachment(self, data_client, rmock):
}
}
}


class TestSystemMessagesMethods(object):
def test_get_system_message(self, data_client, rmock):
rmock.get(
"http://baseurl/system-messages/test-system-message",
json={"systemMessages": "result"},
status_code=200)

result = data_client.get_system_message("test-system-message")

assert result == {"systemMessages": "result"}
assert rmock.called

def test_get_system_message_should_return_404(self, data_client, rmock):
rmock.get(
"http://baseurl/system-messages/test-system-message",
status_code=404)

try:
data_client.get_system_message("test-system-message")
except HTTPError:
assert rmock.called

def test_create_system_message(self, data_client, rmock):
rmock.post(
"http://baseurl/system-messages",
json={"systemMessages": {
'id': 123,
'slug': 'test-system-message',
'data': {
"system-message-key": "system-message-value"
},
'show': False,
}},
status_code=201,
)

result = data_client.create_system_message(
'test-system-message',
{
"system-message-key": "system-message-value"
},
user="test@example.com"
)

assert result == {
"systemMessages": {
'id': 123,
'slug': 'test-system-message',
'data': {
"system-message-key": "system-message-value"
},
'show': False,
}
}
assert rmock.called
assert rmock.last_request.json() == {
"updated_by": "test@example.com",
"systemMessages": {
'slug': 'test-system-message',
'data': {
"system-message-key": "system-message-value"
}
}
}

@pytest.mark.parametrize('show', (False, True))
def test_create_system_with_show(self, data_client, rmock, show):
rmock.post(
"http://baseurl/system-messages",
json={"systemMessages": {
'id': 123,
'slug': 'test-system-message',
'data': {
"system-message-key": "system-message-value"
},
'show': show,
}},
status_code=201,
)

result = data_client.create_system_message(
'test-system-message',
{
"system-message-key": "system-message-value"
},
show=show,
user="test@example.com"
)

assert result == {
"systemMessages": {
'id': 123,
'slug': 'test-system-message',
'data': {
"system-message-key": "system-message-value"
},
'show': show,
}
}
assert rmock.called
assert rmock.last_request.json() == {
"updated_by": "test@example.com",
"systemMessages": {
'slug': 'test-system-message',
'data': {
"system-message-key": "system-message-value"
},
'show': show
}
}

def test_update_system_message(self, data_client, rmock):
rmock.post(
"http://baseurl/system-messages/test-system-message",
json={"systemMessages": {
'id': 123,
'slug': 'test-system-message',
'data': {
"system-message-key": "system-message-value"
},
'show': False,
}},
status_code=200,
)

result = data_client.update_system_message(
'test-system-message',
{
"system-message-key": "system-message-value"
},
user="test@example.com"
)

assert result == {
"systemMessages": {
'id': 123,
'slug': 'test-system-message',
'data': {
"system-message-key": "system-message-value"
},
'show': False,
}
}
assert rmock.called
assert rmock.last_request.json() == {
"updated_by": "test@example.com",
"systemMessages": {
'data': {
"system-message-key": "system-message-value"
}
}
}

@pytest.mark.parametrize('show', (False, True))
def test_update_system_with_show(self, data_client, rmock, show):
rmock.post(
"http://baseurl/system-messages/test-system-message",
json={"systemMessages": {
'id': 123,
'slug': 'test-system-message',
'data': {
"system-message-key": "system-message-value"
},
'show': show,
}},
status_code=200,
)

result = data_client.update_system_message(
'test-system-message',
{
"system-message-key": "system-message-value"
},
show=show,
user="test@example.com"
)

assert result == {
"systemMessages": {
'id': 123,
'slug': 'test-system-message',
'data': {
"system-message-key": "system-message-value"
},
'show': show,
}
}
assert rmock.called
assert rmock.last_request.json() == {
"updated_by": "test@example.com",
"systemMessages": {
'data': {
"system-message-key": "system-message-value"
},
'show': show
}
}

0 comments on commit 6c0d7ba

Please sign in to comment.