Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit 5f7a8e3

Browse files
committed
feat/aws-auditor: run tests
1 parent ec3a104 commit 5f7a8e3

File tree

5 files changed

+160
-0
lines changed

5 files changed

+160
-0
lines changed

.github/workflows/tests.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
name: Tests
3+
4+
on:
5+
push:
6+
branches: [main, develop, feat/aws-auditor]
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
name: Run Tests
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.x'
22+
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install -e ".[test]"
27+
28+
- name: Run tests
29+
run: |
30+
pytest cpk_lib_python_aws/tests/ -v
31+
32+
33+
test-installation:
34+
name: Test Package Installation
35+
runs-on: ubuntu-latest
36+
37+
steps:
38+
- name: Checkout code
39+
uses: actions/checkout@v4
40+
41+
- name: Set up Python
42+
uses: actions/setup-python@v5
43+
with:
44+
python-version: '3.x'
45+
46+
- name: Install package
47+
run: |
48+
python -m pip install --upgrade pip
49+
pip install -e .
50+
51+
- name: Test CLI command
52+
run: |
53+
aws-sso-auditor --help

cpk_lib_python_aws/tests/__init__.py

Whitespace-only changes.

cpk_lib_python_aws/tests/aws_sso_auditor/__init__.py

Whitespace-only changes.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import os
2+
import pytest
3+
from cpk_lib_python_aws.aws_sso_auditor.config import Config
4+
from cpk_lib_python_aws.aws_sso_auditor.exceptions import ConfigurationError
5+
6+
7+
def test_default_config_values():
8+
"""Test that default configuration values are set correctly."""
9+
config = Config()
10+
assert config.aws_region == "us-east-1"
11+
assert config.output_formats == ["json", "yaml"]
12+
assert config.output_directory == "."
13+
assert config.include_timestamp is True
14+
assert config.debug is False
15+
assert config.quiet is False
16+
assert config.timeout == 30
17+
assert config.aws_profile is None
18+
19+
20+
def test_config_validation_valid_formats():
21+
"""Test that valid output formats pass validation."""
22+
config = Config(output_formats=["json"])
23+
config.validate() # Should not raise
24+
25+
config = Config(output_formats=["yaml"])
26+
config.validate() # Should not raise
27+
28+
config = Config(output_formats=["both"])
29+
config.validate() # Should not raise
30+
31+
32+
def test_config_validation_invalid_format():
33+
"""Test that invalid output formats raise ConfigurationError."""
34+
config = Config(output_formats=["invalid"])
35+
with pytest.raises(ConfigurationError, match="Invalid output format: invalid"):
36+
config.validate()
37+
38+
39+
def test_config_validation_invalid_timeout():
40+
"""Test that invalid timeout raises ConfigurationError."""
41+
config = Config(timeout=0)
42+
with pytest.raises(ConfigurationError, match="Timeout must be greater than 0"):
43+
config.validate()
44+
45+
config = Config(timeout=-5)
46+
with pytest.raises(ConfigurationError, match="Timeout must be greater than 0"):
47+
config.validate()
48+
49+
50+
def test_environment_variable_override():
51+
"""Test that environment variables override default values."""
52+
# Set environment variables
53+
os.environ["AWS_REGION"] = "eu-west-1"
54+
os.environ["AWS_SSO_AUDITOR_DEBUG"] = "true"
55+
os.environ["AWS_SSO_AUDITOR_QUIET"] = "true"
56+
57+
try:
58+
config = Config()
59+
assert config.aws_region == "eu-west-1"
60+
assert config.debug is True
61+
assert config.quiet is True
62+
finally:
63+
# Clean up environment variables
64+
os.environ.pop("AWS_REGION", None)
65+
os.environ.pop("AWS_SSO_AUDITOR_DEBUG", None)
66+
os.environ.pop("AWS_SSO_AUDITOR_QUIET", None)
67+
68+
69+
def test_constructor_overrides():
70+
"""Test that constructor parameters override defaults."""
71+
config = Config(
72+
aws_region="ap-southeast-1",
73+
output_directory="/tmp/test",
74+
debug=True,
75+
timeout=60
76+
)
77+
assert config.aws_region == "ap-southeast-1"
78+
assert config.output_directory == "/tmp/test"
79+
assert config.debug is True
80+
assert config.timeout == 60

pyproject.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ dependencies = [
2121
]
2222

2323
[project.optional-dependencies]
24+
test = [
25+
"pytest>=7.0.0",
26+
"pytest-cov>=4.0.0",
27+
"pytest-mock>=3.10.0",
28+
]
2429
dev = [
2530
"pytest>=7.0.0",
2631
"pytest-cov>=4.0.0",
@@ -94,3 +99,25 @@ ignored-modules = [
9499
[tool.pylint.imports]
95100
# Allow relative imports within the package
96101
allow-any-import-level = true
102+
103+
104+
[tool.pytest.ini_options]
105+
testpaths = [
106+
"cpk_lib_python_aws/tests"
107+
]
108+
python_files = ["test_*.py"]
109+
python_classes = ["Test*"]
110+
python_functions = ["test_*"]
111+
addopts = [
112+
"--strict-markers",
113+
"--strict-config",
114+
"--verbose",
115+
"--cov=cpk_lib_python_aws",
116+
"--cov-report=term-missing",
117+
"--cov-report=html"
118+
]
119+
markers = [
120+
"unit: Unit tests with mocked responses",
121+
"integration: Integration tests with real AWS API calls",
122+
"slow: Slow running tests"
123+
]

0 commit comments

Comments
 (0)