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

Commit f52107d

Browse files
committed
IDP-43-modular: add tests
1 parent 8d5af97 commit f52107d

File tree

8 files changed

+1185
-1
lines changed

8 files changed

+1185
-1
lines changed

.github/workflows/tests.yaml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
name: Tests
3+
4+
on:
5+
push:
6+
branches: [main, develop, IDP-43-modular]
7+
pull_request:
8+
branches: [main, develop]
9+
10+
jobs:
11+
test:
12+
name: Run Tests
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
python-version: ['3.9', '3.10', '3.11', '3.12']
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install -e ".[test]"
32+
33+
- name: Run tests
34+
run: |
35+
pytest cpk_lib_python_github/github_app_token_generator_package/tests/ -v
36+
37+
- name: Run tests with coverage
38+
run: |
39+
pytest cpk_lib_python_github/github_app_token_generator_package/tests/ \
40+
--cov=cpk_lib_python_github.github_app_token_generator_package.github_app_token_generator \
41+
--cov-report=term-missing
42+
43+
test-installation:
44+
name: Test Package Installation
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- name: Checkout code
49+
uses: actions/checkout@v4
50+
51+
- name: Set up Python
52+
uses: actions/setup-python@v5
53+
with:
54+
python-version: '3.11'
55+
56+
- name: Install package
57+
run: |
58+
python -m pip install --upgrade pip
59+
pip install -e .
60+
61+
- name: Test CLI command
62+
run: |
63+
github-app-token-generator --help

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*.swp
1515
.DS_Store
1616
.Python
17+
.coverage
1718
.eggs/
1819
.idea/
1920
.installed.cfg

.gitleaks.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
title = "Gitleaks Configuration"
2+
3+
[allowlist]
4+
description = "Allowlist for test files"
5+
paths = [
6+
'''cpk_lib_python_github/.*tests/.*''',
7+
'''.*conftest\.py''',
8+
'''.*test_.*\.py''',
9+
]

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ repos:
7272
rev: v8.27.2
7373
hooks:
7474
- id: gitleaks
75+
args: ['--config=.gitleaks.toml']
7576
# -----------------------------
7677
# # Generates Table of Contents in Markdown files
7778
# # -----------------------------

cpk_lib_python_github/github_app_token_generator_package/tests/__init__.py

Whitespace-only changes.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# -*- coding: utf-8 -*-
2+
"""Pytest configuration and fixtures for github_app_token_generator_package."""
3+
import pytest # pylint: disable=import-error
4+
5+
from ..github_app_token_generator.github_api import GitHubAPIClient
6+
7+
8+
@pytest.fixture
9+
def github_api_client():
10+
"""Create a GitHubAPIClient instance for testing."""
11+
return GitHubAPIClient(timeout=30)
12+
13+
14+
@pytest.fixture
15+
def sample_jwt_token():
16+
"""Sample JWT token for testing."""
17+
return (
18+
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9."
19+
"eyJpc3MiOiIxMjM0NTY3ODkwIiwiaWF0IjoxNjM5NjI2MDAwLCJleHAiOjE2Mzk2Mjk2MDB9."
20+
"sample_jwt_token"
21+
)
22+
23+
24+
@pytest.fixture
25+
def sample_installation_id():
26+
"""Sample installation ID for testing."""
27+
return 12345678
28+
29+
30+
@pytest.fixture
31+
def sample_installation_token():
32+
"""Sample installation token for testing."""
33+
return "ghs_1234567890abcdef1234567890abcdef12345678"
34+
35+
36+
@pytest.fixture
37+
def sample_access_token_response():
38+
"""Sample access token response from GitHub API."""
39+
return {
40+
"token": "ghs_1234567890abcdef1234567890abcdef12345678",
41+
"expires_at": "2023-12-31T23:59:59Z",
42+
"permissions": {
43+
"contents": "read",
44+
"metadata": "read",
45+
"pull_requests": "write",
46+
},
47+
"repository_selection": "selected",
48+
}
49+
50+
51+
@pytest.fixture
52+
def sample_expected_token():
53+
"""Expected token from the response."""
54+
return "ghs_1234567890abcdef1234567890abcdef12345678"
55+
56+
57+
@pytest.fixture
58+
def sample_installations():
59+
"""Sample installations list."""
60+
return [
61+
{
62+
"id": 12345678,
63+
"account": {"login": "testorg", "type": "Organization"},
64+
"target_type": "Organization",
65+
"created_at": "2023-01-01T00:00:00Z",
66+
},
67+
{
68+
"id": 87654321,
69+
"account": {"login": "testuser", "type": "User"},
70+
"target_type": "User",
71+
"created_at": "2023-02-01T00:00:00Z",
72+
},
73+
]
74+
75+
76+
@pytest.fixture
77+
def sample_repositories():
78+
"""Sample repositories response."""
79+
return {
80+
"total_count": 3,
81+
"repositories": [
82+
{
83+
"id": 123,
84+
"full_name": "testorg/repo1",
85+
"name": "repo1",
86+
"private": False,
87+
},
88+
{
89+
"id": 124,
90+
"full_name": "testorg/repo2",
91+
"name": "repo2",
92+
"private": True,
93+
},
94+
{
95+
"id": 125,
96+
"full_name": "testorg/repo3",
97+
"name": "repo3",
98+
"private": False,
99+
},
100+
],
101+
}
102+
103+
104+
@pytest.fixture
105+
def sample_app_info():
106+
"""Sample GitHub App information."""
107+
return {
108+
"id": 123456,
109+
"name": "Test GitHub App",
110+
"slug": "test-github-app",
111+
"description": "A test GitHub App for unit testing",
112+
"owner": {"login": "testorg", "type": "Organization"},
113+
"html_url": "https://github.com/apps/test-github-app",
114+
"created_at": "2023-01-01T00:00:00Z",
115+
"permissions": {
116+
"contents": "read",
117+
"metadata": "read",
118+
"pull_requests": "write",
119+
},
120+
"events": ["push", "pull_request"],
121+
}

0 commit comments

Comments
 (0)