Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revisited add-admin action #241

Merged
merged 93 commits into from
Jun 14, 2024
Merged
Changes from 1 commit
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
38900b0
drafted approach to re-do add-admin user action
codethulu May 2, 2024
7a56ca3
fixed linting, small bugs, typos
codethulu May 3, 2024
25f27f5
fixes
codethulu May 4, 2024
86745c4
added patches
codethulu May 14, 2024
4edeef8
blank
codethulu May 15, 2024
9608a39
feat: singular rake file to have both create user and promtoe admin a…
codethulu May 15, 2024
af7cc0a
fixed tests and linting
codethulu May 15, 2024
72bf7db
re-added check to rock
codethulu May 15, 2024
b450e82
Merge branch 'main' into feat/ISD-1064
codethulu May 15, 2024
a2e900f
bug fixed: changed rockcraft to patch rake.patch
codethulu May 15, 2024
9f6c673
fixes
codethulu May 16, 2024
76f168d
fixed bug in lp patch
codethulu May 16, 2024
6846e2e
fixed rock
codethulu May 17, 2024
1747d3c
force enable https
codethulu May 22, 2024
3b9e437
fixes
codethulu May 22, 2024
b2d0abb
minor changes to rake file
codethulu May 22, 2024
f6baa42
blank
codethulu May 22, 2024
361fdfd
fix
codethulu May 22, 2024
ac18402
using admin:create instead
codethulu May 23, 2024
e922412
relevant changes
codethulu May 23, 2024
00720d4
removed unnecessary line
codethulu May 23, 2024
bfbff5e
minor fixes
codethulu May 24, 2024
8cd79e3
fixed event set results typo
codethulu May 24, 2024
68c90e4
using secrets instead of random
codethulu May 24, 2024
0010a60
replace email with user
codethulu May 24, 2024
13b2d2b
blank
codethulu May 26, 2024
bc94146
changed config
codethulu May 26, 2024
df3ef14
Update config.yaml
codethulu May 27, 2024
be80aae
Update conftest.py
codethulu May 27, 2024
d95c61c
Update conftest.py
codethulu May 27, 2024
fb1a9db
updat3ed ops
codethulu May 28, 2024
4c43eaf
refactor test
codethulu May 28, 2024
6be5dab
Merge branch 'main' into feat/ISD-1064
codethulu May 29, 2024
bfd05e5
resolved
codethulu May 29, 2024
14a94b1
refactored test
codethulu May 29, 2024
9419b10
added saml testing module
codethulu May 29, 2024
3e4fa46
parameters
codethulu May 29, 2024
db9d829
updated workflow
codethulu May 30, 2024
8933ba4
updated descriptions
codethulu May 30, 2024
992a6c8
Merge branch 'main' into feat/ISD-1064
codethulu May 30, 2024
7b44ed2
blank
codethulu May 30, 2024
42f99f3
Update requirements.txt
codethulu May 30, 2024
88bccca
Update actions.yaml
codethulu May 31, 2024
97bfa31
addressed changes
codethulu Jun 3, 2024
879cdee
make sure action fails
codethulu Jun 3, 2024
1e0bed2
linting
codethulu Jun 3, 2024
ba37983
linting fix
codethulu Jun 3, 2024
d70cd85
linting
codethulu Jun 3, 2024
cb2b7f3
blank
codethulu Jun 4, 2024
5bccdf9
updated rockcraft/patches
codethulu Jun 5, 2024
4e29b90
fixes, new integration test and fix for unit test
codethulu Jun 5, 2024
10328ed
linting fixes
codethulu Jun 5, 2024
ea6f495
addressed comments
codethulu Jun 6, 2024
8930351
using response.ok
codethulu Jun 6, 2024
9664cbf
Merge branch 'main' into feat/ISD-1064
codethulu Jun 6, 2024
373a6fe
readded touch
codethulu Jun 6, 2024
2fc84da
rock and unit test
codethulu Jun 6, 2024
fcc9fa3
uhm
codethulu Jun 6, 2024
d801445
blank
codethulu Jun 6, 2024
5c5c212
Dblank
codethulu Jun 6, 2024
af951d1
addressed changes, fixed linting
codethulu Jun 6, 2024
b9012a8
fixed unit test
codethulu Jun 7, 2024
c56b177
updated rock
codethulu Jun 7, 2024
107c780
added user activation
codethulu Jun 10, 2024
952b9a6
fixed linting
codethulu Jun 10, 2024
4abe096
improved and fixed unit test
codethulu Jun 10, 2024
b1a736f
improved and fixed unit test
codethulu Jun 10, 2024
589dad6
fixes
codethulu Jun 10, 2024
b0853d9
added timeout
codethulu Jun 10, 2024
eb30e65
Merge branch 'main' into feat/ISD-1064
codethulu Jun 10, 2024
4ad16cd
flagged test upgrade
codethulu Jun 11, 2024
1bc23b4
activate
codethulu Jun 11, 2024
e26c0c9
fixed integration test
codethulu Jun 11, 2024
4ba9a42
changed cindition, added some logging statements
codethulu Jun 12, 2024
814cb2c
Update rockcraft.yaml
codethulu Jun 12, 2024
45d0bb7
added try except, figure out whats failing in ci
codethulu Jun 12, 2024
80e3755
wait for idle
codethulu Jun 12, 2024
a4bf637
pinned redis channel to 28/edge
codethulu Jun 12, 2024
5e60183
latest/stable
codethulu Jun 12, 2024
f4c5ab7
rev 28
codethulu Jun 12, 2024
300d64f
moved user testing to separate module
codethulu Jun 12, 2024
a2c0d7d
addressed changes
codethulu Jun 13, 2024
3121bc5
fixed unit test exit code
codethulu Jun 13, 2024
125a24b
Update rockcraft.yaml
codethulu Jun 14, 2024
1c0bc3f
fixed unit tests
codethulu Jun 14, 2024
db34e09
fixed unit tests
codethulu Jun 14, 2024
de4b0ac
fixed all unit tests
codethulu Jun 14, 2024
2a7c8b9
changes
codethulu Jun 14, 2024
8b74d84
unit test coverage
codethulu Jun 14, 2024
3285716
refactor
codethulu Jun 14, 2024
ef2e9aa
lint
codethulu Jun 14, 2024
79d3e57
raise w/o arguments
codethulu Jun 14, 2024
6df0442
removed arguments of raise
codethulu Jun 14, 2024
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
Prev Previous commit
Next Next commit
unit test coverage
codethulu committed Jun 14, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 8b74d84ca46cc0fb99cdedcb903217f185f1d7fc
2 changes: 1 addition & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
@@ -696,7 +696,7 @@ def _activate_charm(self) -> None:
if self._is_config_valid() and container.can_connect():
self._start_service()
self.model.unit.status = ActiveStatus()

def _user_exists(self, email: str) -> bool:
"""Check if a user with the given email exists.
109 changes: 101 additions & 8 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
@@ -7,16 +7,13 @@
# Protected access check is disabled in tests as we're injecting test data

import secrets
import typing
from unittest.mock import DEFAULT, MagicMock, patch
from unittest.mock import MagicMock, patch

import ops
import pytest
from ops.charm import ActionEvent
from ops.model import ActiveStatus, BlockedStatus, WaitingStatus
from ops.pebble import ExecError

from charm import CONTAINER_NAME, DATABASE_NAME, DISCOURSE_PATH, SERVICE_NAME, DiscourseCharm
from charm import CONTAINER_NAME, DATABASE_NAME, DISCOURSE_PATH, SERVICE_NAME
from tests.unit import helpers


@@ -311,7 +308,7 @@ def test_db_relation():
), "database name should be set after relation joined"


def test_promote_user():
def test_promote_user_success():
"""
arrange: an email and a password
act: when the _on_promote_user_action method is executed
@@ -347,7 +344,7 @@ def bundle_handler(args: ops.testing.ExecArgs) -> None:
assert expected_exec_call_was_made


def test_create_user():
def test_promote_user_fail():
"""
arrange: an email
act: when the _on_create_user_action method is executed
@@ -366,7 +363,65 @@ def mock_create_user(args: ops.testing.ExecArgs) -> None:
if (
args.environment != harness.charm._create_discourse_environment_settings()
or args.working_dir != DISCOURSE_PATH
or email not in args.stdin
or email not in str(args.stdin)
or args.user != "_daemon_"
or args.timeout != 60
):
raise ValueError(f"{args.command} wasn't made with the correct args.")

harness.handle_exec(
SERVICE_NAME,
[f"{DISCOURSE_PATH}/bin/bundle", "exec", "rake", "admin:create"],
handler=mock_create_user,
)

stdout = "ERROR: User with email f{email} not found"

# Exit code 2 means that the user cannot be found in the rake task.
harness.handle_exec(
SERVICE_NAME,
[f"{DISCOURSE_PATH}/bin/bundle", "exec", "rake", f"users:exists[{email}]"],
result=ops.testing.ExecResult(exit_code=2, stdout=stdout, stderr=""),
)
try:
harness.run_action("promote-user", {"email": email})
assert False
except ops.testing.ActionFailed as e:
assert e.message == f"User with email {email} does not exist"

# Exit code 1 means that the rake task failed.
harness.handle_exec(
SERVICE_NAME,
[f"{DISCOURSE_PATH}/bin/bundle", "exec", "rake", f"users:exists[{email}]"],
result=ops.testing.ExecResult(exit_code=1, stdout=stdout, stderr=""),
)
try:
harness.run_action("promote-user", {"email": email})
assert False
except ops.pebble.ExecError as e:
assert "non-zero exit code 1" in str(e)


def test_create_user_success():
"""
arrange: an email
act: when the _on_create_user_action method is executed
assert: the create user rake command is executed upon failure of the user existence check.
"""
harness = helpers.start_harness()

# We catch the exec call that we expect to register it and make sure that the
# args passed to it are correct.
expected_exec_call_was_made = False
email = "[email protected]"

def mock_create_user(args: ops.testing.ExecArgs) -> None:
nonlocal expected_exec_call_was_made
expected_exec_call_was_made = True
if (
args.environment != harness.charm._create_discourse_environment_settings()
or args.working_dir != DISCOURSE_PATH
or email not in str(args.stdin)
or args.user != "_daemon_"
or args.timeout != 60
):
@@ -389,6 +444,44 @@ def mock_create_user(args: ops.testing.ExecArgs) -> None:
assert expected_exec_call_was_made


def test_create_user_fail():
"""
arrange: an email
act: when the _on_create_user_action method is executed
assert: the create user rake command is executed upon failure of the user existence check.
"""
harness = helpers.start_harness()

# We catch the exec call that we expect to register it and make sure that the
# args passed to it are correct.
expected_exec_call_was_made = False
email = "[email protected]"

def mock_create_user(args: ops.testing.ExecArgs) -> None:
nonlocal expected_exec_call_was_made
expected_exec_call_was_made = True
if (
args.environment != harness.charm._create_discourse_environment_settings()
or args.working_dir != DISCOURSE_PATH
or email not in str(args.stdin)
or args.user != "_daemon_"
or args.timeout != 60
):
raise ValueError(f"{args.command} wasn't made with the correct args.")

harness.handle_exec(
SERVICE_NAME,
[f"{DISCOURSE_PATH}/bin/bundle", "exec", "rake", "admin:create"],
handler=mock_create_user,
)

try:
harness.run_action("create-user", {"email": email})
assert False
except ops.testing.ActionFailed as e:
assert e.message == f"User with email {email} already exists"


def test_anonymize_user():
"""
arrange: set up discourse