Skip to content

Commit

Permalink
Merge pull request #719 from ScilifelabDataCentre/dev
Browse files Browse the repository at this point in the history
New release: v2.8.1
  • Loading branch information
valyo authored Oct 22, 2024
2 parents ccc7f91 + a906269 commit ea7438f
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 210 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
==========

.. _2.8.1:

2.8.1 - 2024-10-22
~~~~~~~~~~~~~~~~~~~
- New features:
- Added a new option to the motd send command to allow sending to unit personnel only

.. _2.8.0:

2.8.0 - 2024-09-24
Expand Down
6 changes: 6 additions & 0 deletions SPRINTLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,9 @@ _Empty sprint_
# 2024-09-24 - 2024-10-04

- New version and changelog([#714](https://github.com/ScilifelabDataCentre/dds_cli/pull/714))
- Added a new option to the motd send command to allow sending to unit personnel only ([#717](https://github.com/ScilifelabDataCentre/dds_cli/pull/717))

# 2024-10-07 - 2024-10-18

- Update MOTD command according to post merge review ([#720](https://github.com/ScilifelabDataCentre/dds_cli/pull/720))
- New version: 2.8.1([#719](https://github.com/ScilifelabDataCentre/dds_cli/pull/719))
11 changes: 9 additions & 2 deletions dds_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2070,15 +2070,22 @@ def deactivate_motd(click_ctx, motd_id):
# -- dds motd send -- #
@motd_group_command.command(name="send")
@click.argument("motd_id", metavar="[MOTD_ID]", nargs=1, type=int, required=True)
@click.option(
"--unit-only",
is_flag=True,
required=False,
default=False,
help="Only send MOTD to Unit Admins and Unit Personnel.",
)
@click.pass_obj
def send_motd(click_ctx, motd_id):
def send_motd(click_ctx, motd_id, unit_only):
"""Send motd as email to all users."""
try:
with dds_cli.motd_manager.MotdManager(
no_prompt=click_ctx.get("NO_PROMPT", False),
token_path=click_ctx.get("TOKEN_PATH"),
) as sender:
sender.send_motd(motd_id=motd_id)
sender.send_motd(motd_id=motd_id, unit_only=unit_only)
except (
dds_cli.exceptions.AuthenticationError,
dds_cli.exceptions.ApiResponseError,
Expand Down
4 changes: 2 additions & 2 deletions dds_cli/motd_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ def deactivate_motd(self, motd_id) -> None:
)
LOG.info(response_message)

def send_motd(self, motd_id: int) -> None:
def send_motd(self, motd_id: int, unit_only=False) -> None:
"""Send specific MOTD to users."""
response_json, _ = dds_cli.utils.perform_request(
endpoint=DDSEndpoint.MOTD_SEND,
headers=self.token,
method="post",
json={"motd_id": motd_id},
json={"motd_id": motd_id, "unit_only": unit_only},
error_message="Failed sending the MOTD to users",
)

Expand Down
2 changes: 1 addition & 1 deletion dds_cli/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# Do not change bump the major version unless absolutely necessary - makes incompatible with API
# If mid or minor version reaches 9, continue to 10, 11 etc.
__version__ = "2.8.0"
__version__ = "2.8.1"
174 changes: 87 additions & 87 deletions img/dds-help-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
174 changes: 87 additions & 87 deletions img/dds-help-2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 12 additions & 12 deletions img/dds-version.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions img/python-version.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions img/python3-version.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion tests/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ requests-mock==1.9.3
pytest==7.1.2
pytest-cov==3.0.0
pyfakefs==5.3.0
Werkzeug==2.2.3
27 changes: 27 additions & 0 deletions tests/test_motd_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,30 @@ def test_add_new_motd_ok(caplog: LogCaptureFixture):
logging.INFO,
"Response from API about adding a MOTD.",
) in caplog.record_tuples


# send_motd


def test_send_motd_all(caplog: LogCaptureFixture):
"""Send a MOTD to all users."""

motd_id = 1
response_message = "Response from API about sending a MOTD."
returned_response: Dict = {"message": response_message}

with caplog.at_level(logging.INFO):
# Create mocker
with Mocker() as mock:
# Create mocked request - real request not executed
mock.post(DDSEndpoint.MOTD_SEND, status_code=200, json=returned_response)

with motd_manager.MotdManager(authenticate=False, no_prompt=True) as mtdm:
mtdm.token = {} # required, otherwise none
mtdm.send_motd(motd_id=motd_id, unit_only=False) # Send motd

assert (
"dds_cli.motd_manager",
logging.INFO,
response_message,
) in caplog.record_tuples

0 comments on commit ea7438f

Please sign in to comment.