-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from nebari-dev/20230531eae
- Loading branch information
Showing
11 changed files
with
437 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: "Tests" | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- ".github/workflows/tests.yml" | ||
- "nebari_workflow_controller/**" | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
pre-commit: | ||
name: "pre-commit" | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Checkout repo" | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: "Setup Python" | ||
uses: actions/setup-python@v3 | ||
|
||
- name: "Run pre-commit" | ||
uses: pre-commit/[email protected] | ||
|
||
pytest: | ||
name: "pytest" | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: | ||
- "3.8" | ||
- "3.9" | ||
- "3.10" | ||
- "3.11" | ||
fail-fast: false | ||
steps: | ||
- name: "Checkout repo" | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: "Setup Python" | ||
uses: actions/setup-python@v3 | ||
|
||
- name: "Install package" | ||
run: | | ||
pip install .[dev] | ||
- name: "Test package" | ||
run: | | ||
pytest --version | ||
pytest -vvv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,3 +131,6 @@ dmypy.json | |
|
||
# vscode | ||
.vscode/ | ||
|
||
# Mac | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
import pytest | ||
import yaml | ||
from keycloak.exceptions import KeycloakGetError | ||
|
||
from nebari_workflow_controller.models import KeycloakGroup, KeycloakUser | ||
|
||
|
@@ -41,6 +42,28 @@ def all_request_paths(valid_request_paths, invalid_request_paths): | |
return valid_request_paths + invalid_request_paths | ||
|
||
|
||
def _valid_service_account_request_paths(): | ||
return sorted( | ||
[ | ||
str(p) | ||
for p in Path("./tests/test_data/requests/valid-service-account").glob( | ||
"*.yaml" | ||
) | ||
] | ||
) | ||
|
||
|
||
def _invalid_service_account_request_paths(): | ||
return sorted( | ||
[ | ||
str(p) | ||
for p in Path("./tests/test_data/requests/invalid-service-account").glob( | ||
"*.yaml" | ||
) | ||
] | ||
) | ||
|
||
|
||
def load_request(request_path): | ||
with open(request_path) as f: | ||
return yaml.load(f, Loader=yaml.FullLoader) | ||
|
@@ -102,3 +125,57 @@ def mocked_get_user_pod_spec(mocker): | |
"nebari_workflow_controller.app.get_user_pod_spec", | ||
return_value=jupyterlab_pod_spec, | ||
) | ||
|
||
|
||
class MockedKeycloakAdmin: | ||
def get_user(self, *args, **kwargs): | ||
raise KeycloakGetError("mocked error") | ||
|
||
def get_users(self, *args, **kwargs): | ||
return [ | ||
{ | ||
"id": "a1234567-abcd-89ef-0123-456789abcdef", | ||
"username": "[email protected]", | ||
"email": "[email protected]", | ||
"firstName": "Valid", | ||
"lastName": "User", | ||
"enabled": True, | ||
"groups": ["admin", "users"], | ||
}, | ||
] | ||
|
||
def get_user_groups(self, *args, **kwargs): | ||
return [ | ||
{ | ||
"id": "group123-id", | ||
"name": "admin", | ||
"path": "/admin", | ||
"attributes": {}, | ||
}, | ||
{ | ||
"id": "group456-id", | ||
"name": "users", | ||
"path": "/users", | ||
"attributes": {}, | ||
}, | ||
] | ||
|
||
|
||
VALID_ARGO_ROLES = ["argo-admin", "argo-developer"] | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def mock_special_case(mocker): | ||
mocker.patch( | ||
"nebari_workflow_controller.utils.create_keycloak_admin", | ||
return_value=MockedKeycloakAdmin(), | ||
) | ||
mocker.patch("nebari_workflow_controller.utils.config", return_value=None) | ||
mocker.patch( | ||
"nebari_workflow_controller.utils.sent_by_argo", | ||
return_value="workflows.argoproj.io/creator", | ||
) | ||
mocker.patch( | ||
"nebari_workflow_controller.utils.valid_argo_roles", | ||
return_value=VALID_ARGO_ROLES, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.