-
Notifications
You must be signed in to change notification settings - Fork 3
Add simple test for get_size
#570
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
Changes from all commits
e0e779f
598fb99
b2162e3
9a425bd
899e0d2
0117c7e
e3c2dbb
944bdcc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,16 @@ | ||
| [tox] | ||
| envlist = unused-code, pytest | ||
| skipsdist = True | ||
|
|
||
| [testenv] | ||
| [testenv:unused-code] | ||
| deps = | ||
| python-utility-scripts | ||
| commands = | ||
| pyutils-unusedcode --exclude-function-prefixes 'process_webhook' | ||
|
|
||
| [testenv:pytest] | ||
| deps = | ||
| poetry | ||
| commands = | ||
| poetry install | ||
| poetry run pytest webhook_server_container/tests |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,92 @@ | ||||||
| log-level: INFO # Set global log level, change take effect immediately without server restart | ||||||
| log-file: webhook-server.log # Set global log file, change take effect immediately without server restart | ||||||
|
|
||||||
| github-app-id: 123456 # GitHub app id | ||||||
| github-toekns: | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typo in 'github-tokens' key There's a typo in the key "github-toekns". Please correct it to "github-tokens": -github-toekns:
+github-tokens:📝 Committable suggestion
Suggested change
|
||||||
| - <GITHIB TOKEN1> | ||||||
| - <GITHIB TOKEN2> | ||||||
|
myakove marked this conversation as resolved.
|
||||||
|
|
||||||
| webhook_ip: <HTTP://IP OR URL:PORT> | ||||||
|
myakove marked this conversation as resolved.
|
||||||
|
|
||||||
| docker: # Used to pull images from docker.io | ||||||
| username: <username> | ||||||
| password: <password> | ||||||
|
myakove marked this conversation as resolved.
|
||||||
|
|
||||||
| default-status-checks: | ||||||
| - "WIP" | ||||||
| - "dpulls" | ||||||
| - "can-be-merged" | ||||||
|
|
||||||
| auto-verified-and-merged-users: | ||||||
| - "renovate[bot]" | ||||||
| - "pre-commit-ci[bot]" | ||||||
|
|
||||||
| jira: | ||||||
| server: <JIRA URL> | ||||||
| project: <PROJECT KEY> | ||||||
| token: <JIRA TOKEN> | ||||||
| user-mapping: | ||||||
| <GITHUB USER>: <JIRA USER> # if github user is not the same as jira | ||||||
|
|
||||||
| repositories: | ||||||
| test-repo: | ||||||
| name: my-org/test-repo | ||||||
| log-level: DEBUG # Override global log-level for repository | ||||||
| log-file: test-repo.log # Override global log-file for repository | ||||||
| slack_webhook_url: <Slack webhook url> # Send notification to slack on several operations | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security concern: Slack webhook URL exposed The Slack webhook URL is exposed in plain text. This could be a security risk if the configuration file is compromised. Consider using an environment variable for the Slack webhook URL: slack_webhook_url: ${SLACK_WEBHOOK_URL} |
||||||
| verified_job: true | ||||||
| pypi: | ||||||
| token: <PYPI TOKEN> | ||||||
|
Comment on lines
+38
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security concern: Multiple exposed sensitive tokens Several sensitive tokens and credentials are exposed in plain text throughout the repository-specific configuration. This includes PyPI token, container credentials, GitHub tokens, and Jira token. Replace all sensitive information with environment variables or use a secure secret management system. For example: pypi:
token: ${PYPI_TOKEN}
container:
username: ${CONTAINER_USERNAME}
password: ${CONTAINER_PASSWORD}
github-tokens:
- ${GITHUB_TOKEN1}
- ${GITHUB_TOKEN2}
jira:
token: ${JIRA_TOKEN}Also applies to: 62-64, 76-78, 87-89 |
||||||
|
|
||||||
| events: # To listen to all events do not send events | ||||||
| - push | ||||||
| - pull_request | ||||||
| - issue_comment | ||||||
| - check_run | ||||||
| - pull_request_review | ||||||
| tox: | ||||||
| main: all # Run all tests in tox.ini when pull request parent branch is main | ||||||
| dev: testenv1,testenv2 # Run testenv1 and testenv2 tests in tox.ini when pull request parent branch is dev | ||||||
|
|
||||||
| pre-commit: true # Run pre-commit check | ||||||
|
|
||||||
| protected-branches: | ||||||
| dev: [] | ||||||
| main: # set [] in order to set all defaults run included | ||||||
| include-runs: | ||||||
| - "pre-commit.ci - pr" | ||||||
| - "WIP" | ||||||
| exclude-runs: | ||||||
| - "SonarCloud Code Analysis" | ||||||
| container: | ||||||
| username: <registry username> | ||||||
| password: <registry_password> | ||||||
| repository: <registry_repository_full_path> | ||||||
| tag: <image_tag> | ||||||
| release: true # Push image to registry on new release with release as the tag | ||||||
| build-args: # build args to send to podman build command | ||||||
| - my-build-arg1=1 | ||||||
| - my-build-arg2=2 | ||||||
| args: # args to send to podman build command | ||||||
| - --format docker | ||||||
|
|
||||||
|
Comment on lines
+61
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security concern and clarity improvements for container configuration
container:
username: ${CONTAINER_REGISTRY_USERNAME}
password: ${CONTAINER_REGISTRY_PASSWORD}
container:
# ... (username and password as above)
repository: <registry_repository_full_path>
tag: <image_tag>
release: true # Push image to registry on new release, using the release as the tag
build-args: # Arguments passed to the container build process
- my-build-arg1=1
- my-build-arg2=2
args: # Additional arguments for the podman build command
- --format docker # Ensure the built image is compatible with DockerThese changes will improve security and make the configuration more self-explanatory. |
||||||
| auto-verified-and-merged-users: # override auto verified users per repository | ||||||
| - "my[bot]" | ||||||
|
|
||||||
| github-tokens: # override GitHub tokens per repository | ||||||
| - <GITHUB TOKEN1> | ||||||
| - <GITHUB TOKEN2> | ||||||
|
|
||||||
| can-be-merged-required-labels: # check for extra labels to set PR as can be merged | ||||||
| - my-label1 | ||||||
| - my-label2 | ||||||
|
|
||||||
| jira-tracking: true | ||||||
|
|
||||||
| jira: # override Jira global settings | ||||||
| server: <JIRA URL> | ||||||
| project: <PROJECT KEY> | ||||||
| token: <JIRA TOKEN> | ||||||
| epic: <EPIC KEY> # Optional | ||||||
| user-mapping: | ||||||
| <GITHUB USER>: <JIRA USER> # if github user is not the same as jira | ||||||
|
myakove marked this conversation as resolved.
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import pytest | ||
| from starlette.datastructures import Headers | ||
|
|
||
| from simple_logger.logger import logging | ||
| from stringcolor.ops import os | ||
| from webhook_server_container.libs.github_api import ProcessGithubWehook | ||
| from webhook_server_container.utils.constants import SIZE_LABEL_PREFIX | ||
|
|
||
|
|
||
| class Repository: | ||
| def __init__(self): | ||
| self.name = "test-repo" | ||
|
|
||
|
|
||
| class PullRequest: | ||
| def __init__(self, additions: int, deletions: int): | ||
| self.additions = additions | ||
| self.deletions = deletions | ||
|
|
||
|
|
||
| @pytest.fixture(scope="function") | ||
| def process_github_webhook(mocker): | ||
| base_import_path = "webhook_server_container.libs.github_api" | ||
| os.environ["WEBHOOK_SERVER_DATA_DIR"] = "webhook_server_container/tests/manifests" | ||
|
|
||
| mocker.patch(f"{base_import_path}.get_repository_github_app_api", return_value=True) | ||
| mocker.patch("github.AuthenticatedUser", return_value=True) | ||
| mocker.patch(f"{base_import_path}.get_api_with_highest_rate_limit", return_value=("API", "TOKEN")) | ||
| mocker.patch(f"{base_import_path}.get_github_repo_api", return_value=Repository()) | ||
|
|
||
| return ProcessGithubWehook( | ||
| {"repository": {"name": Repository().name}}, Headers({"X-GitHub-Event": "test-event"}), logging.getLogger() | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "additions, deletions, expected_label", | ||
| [ | ||
| (0, 0, "XS"), | ||
| (18, 1, "XS"), | ||
| (48, 1, "S"), | ||
| (98, 1, "M"), | ||
| (298, 1, "L"), | ||
| (498, 1, "XL"), | ||
| (1000, 1, "XXL"), | ||
| ], | ||
| ) | ||
| def test_get_size_thresholds(process_github_webhook, additions, deletions, expected_label): | ||
| process_github_webhook.pull_request = PullRequest(additions=additions, deletions=deletions) | ||
| result = process_github_webhook.get_size() | ||
|
|
||
| assert result == f"{SIZE_LABEL_PREFIX}{expected_label}" | ||
|
myakove marked this conversation as resolved.
|
||
Uh oh!
There was an error while loading. Please reload this page.