Skip to content

Commit

Permalink
try different permissions, better tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Germandrummer92 committed Sep 7, 2023
1 parent fc536c9 commit df25ab8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:

build_and_push_docker_image:
permissions:
packages: write
packages: write-all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 4 additions & 2 deletions sched_slack_bot/model/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,11 @@ def from_modal_submission(cls, submission_body: SlackBody) -> Schedule:

if schedule_id.startswith(CREATE_NEW_SCHEDULE_VIEW_ID_PREFIX):
schedule_id = str(uuid.uuid4())

if SCHEDULE_VIEW_ID_SCHEDULE_ID_DELIMITER in schedule_id:
elif SCHEDULE_VIEW_ID_SCHEDULE_ID_DELIMITER in schedule_id:
schedule_id = schedule_id.split(SCHEDULE_VIEW_ID_SCHEDULE_ID_DELIMITER)[0]
else:
raise ValueError(f"external id of schedule doesn't contain delimiter '{SCHEDULE_VIEW_ID_SCHEDULE_ID_DELIMITER}'"
f"nor prefix '{CREATE_NEW_SCHEDULE_VIEW_ID_PREFIX}', received instead: '{schedule_id}'")

return Schedule(
id=schedule_id,
Expand Down
28 changes: 26 additions & 2 deletions test_sched_slack_bot/model/test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
get_datetime_block_ids,
FIRST_ROTATION_LABEL,
SECOND_ROTATION_LABEL,
SCHEDULE_VIEW_ID_SCHEDULE_ID_DELIMITER,
CREATE_NEW_SCHEDULE_VIEW_ID_PREFIX,
)


Expand Down Expand Up @@ -81,7 +83,7 @@ def _add_valid_datetime_values(
def valid_slack_body(minimum_slack_body: SlackBody, schedule: Schedule) -> SlackBody:
valid_slack_body = copy.deepcopy(minimum_slack_body)

valid_slack_body["view"]["external_id"] = schedule.id
valid_slack_body["view"]["external_id"] = f"{schedule.id}{SCHEDULE_VIEW_ID_SCHEDULE_ID_DELIMITER}{str(uuid.uuid4())}"

# mypy cant deal with dynamic typed dicts
valid_slack_body["view"]["state"]["values"][DISPLAY_NAME_BLOCK_ID] = {
Expand Down Expand Up @@ -231,7 +233,7 @@ def test_schedule_from_modal_submission_raises_with_missing_values(
Schedule.from_modal_submission(submission_body=valid_slack_body)


def test_schedule_from_modal_submission_works(schedule: Schedule, valid_slack_body: SlackBody) -> None:
def test_schedule_from_modal_submission_works_for_edit(schedule: Schedule, valid_slack_body: SlackBody) -> None:
from_modal = Schedule.from_modal_submission(submission_body=valid_slack_body)

assert from_modal.display_name == schedule.display_name
Expand All @@ -241,3 +243,25 @@ def test_schedule_from_modal_submission_works(schedule: Schedule, valid_slack_bo
assert from_modal.current_index == schedule.current_index
assert from_modal.time_between_rotations == schedule.time_between_rotations
assert from_modal.id == schedule.id


def test_schedule_from_modal_submission_works_for_create(schedule: Schedule, valid_slack_body: SlackBody) -> None:
valid_slack_body["view"][
"external_id"
] = f"{CREATE_NEW_SCHEDULE_VIEW_ID_PREFIX}{SCHEDULE_VIEW_ID_SCHEDULE_ID_DELIMITER}{str(uuid.uuid4())}"

from_modal = Schedule.from_modal_submission(submission_body=valid_slack_body)

assert from_modal.display_name == schedule.display_name
assert from_modal.members == schedule.members
assert from_modal.channel_id_to_notify_in == schedule.channel_id_to_notify_in
assert from_modal.next_rotation == schedule.next_rotation
assert from_modal.current_index == schedule.current_index
assert from_modal.time_between_rotations == schedule.time_between_rotations
assert from_modal.id != schedule.id


def test_schedule_from_modal_submission_raises_with_wrong_external_id(schedule: Schedule, valid_slack_body: SlackBody) -> None:
valid_slack_body["view"]["external_id"] = "broken"
with pytest.raises(ValueError):
Schedule.from_modal_submission(submission_body=valid_slack_body)

0 comments on commit df25ab8

Please sign in to comment.