Skip to content

Commit

Permalink
[BB-242] _load_configs_for_credentials test (#245)
Browse files Browse the repository at this point in the history
* _load_configs_for_credentials test

* coveralls integration

* fix indentation

* trying xml format

* skip docker image for unit tests

* missing quote
  • Loading branch information
Franr authored Feb 20, 2024
1 parent 5b41cbf commit 8055a71
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 9 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/tests-unit-and-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: build_image
- name: install_requirements
run: |
echo "[INFO] Building image"
make build-image
shell: bash
echo "[INFO] Installing requirements..."
pip install -r dev-requirements.txt
- name: run_unit_tests
run: |
echo "[INFO] Running unit tests"
make test-unit-no-cov
echo "[INFO] Running unit tests and generate coverage report"
pytest --verbose
shell: bash

- name: Report Coveralls
uses: coverallsapp/github-action@v2

integration_tests:
runs-on: ubuntu-latest
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ leverage.egg-info
**/__pycache__*
.pytest_cache
coverage
coverage.xml
.coverage

.idea
3 changes: 2 additions & 1 deletion leverage/leverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from leverage._internals import pass_state

from leverage.modules.aws import aws
from leverage.modules import run, project, terraform, credentials, tfautomv, kubectl, shell
from leverage.modules.credentials import credentials
from leverage.modules import run, project, terraform, tfautomv, kubectl, shell


@click.group(invoke_without_command=True)
Expand Down
1 change: 0 additions & 1 deletion leverage/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .run import run
from .project import project
from .terraform import terraform
from .credentials import credentials
from .tfautomv import tfautomv
from .kubectl import kubectl
from .shell import shell
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ console_scripts =
leverage = leverage:leverage

[tool:pytest]
addopts = --cov=leverage --cov-report html:coverage
addopts = --cov=leverage --cov-report xml

[coverage:run]
branch = True
Expand Down
61 changes: 61 additions & 0 deletions tests/test_modules/test_credentials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from unittest import mock
from unittest.mock import Mock

from leverage.modules.credentials import _load_configs_for_credentials


@mock.patch(
"leverage.modules.credentials._load_project_yaml",
Mock(
return_value={
"short_name": "test",
"region": "us-test-1",
"organization": {
"accounts": [
{"name": "acc2"},
]
},
}
),
)
@mock.patch(
"leverage.modules.credentials.AWSCLI",
Mock(
env_conf={
"PROJECT": "test",
"MFA_ENABLED": "true",
},
paths=Mock(
common_conf={
"project_long": "test-prjt",
"region_secondary": "us-test-2",
"accounts": {
"acc1": {
"email": "[email protected]",
"id": "123456",
}
},
},
),
),
)
def test_load_configs_for_credentials(with_click_context):
assert _load_configs_for_credentials() == {
"mfa_enabled": "true",
"organization": {
"accounts": [
{
"email": "[email protected]",
"id": "123456",
"name": "acc1",
},
{
"name": "acc2",
},
]
},
"primary_region": "us-test-1",
"project_name": "test-prjt",
"secondary_region": "us-test-2",
"short_name": "test",
}

0 comments on commit 8055a71

Please sign in to comment.