# What this PR does - Adds [`mypy` static type checking](https://mypy-lang.org/) to our CI pipeline. Currently there is still a **ton** of errors being returned by the tool, as we'll need to fix pre-existing errors. I think we can slowly chip away at these errors in small PRs, doing them all in one large PR is likely very risky. - Also, this PR starts chipping away at one of the main type errors that we have which is accessing the `datetime` class (from the `datetime` library) or `timedelta` function on the `django.utils.timezone` module. Basically we should be instead accessing these two objects from the native `datetime` module. This makes sense because the [`__all__` attribute](https://github.com/django/django/blob/main/django/utils/timezone.py#L14-L30) in `django.utils.timezone` does not re-export `datetime` or `timedelta`. - splits `engine` dependencies out into `requirements.txt` and `requirements-dev.txt` ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated (N/A) - [ ] Documentation added (or `pr:no public docs` PR label added if not required) (N/A) - [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) (N/A)
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
import pytest
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_escaping_payload_with_double_quotes(
|
|
make_organization,
|
|
make_custom_action,
|
|
make_alert_receive_channel,
|
|
make_alert_group,
|
|
make_alert,
|
|
):
|
|
organization = make_organization()
|
|
alert_receive_channel = make_alert_receive_channel(organization)
|
|
alert_group = make_alert_group(alert_receive_channel)
|
|
alert_payload = {
|
|
"text": '"Hello world"',
|
|
}
|
|
|
|
alert = make_alert(alert_group=alert_group, raw_request_data=alert_payload)
|
|
|
|
custom_button = make_custom_action(
|
|
name="github_button",
|
|
webhook="https://github.com/",
|
|
user="Chris Vanstras",
|
|
password="qwerty",
|
|
data='{\n "text" : "{{ alert_payload.text }}"\n}',
|
|
authorization_header="auth_token",
|
|
organization=organization,
|
|
)
|
|
|
|
custom_button.build_post_kwargs(alert)
|
|
|
|
|
|
@pytest.mark.django_db
|
|
def test_escaping_payload_with_single_quote_in_string(
|
|
make_organization,
|
|
make_custom_action,
|
|
make_alert_receive_channel,
|
|
make_alert_group,
|
|
make_alert,
|
|
):
|
|
organization = make_organization()
|
|
alert_receive_channel = make_alert_receive_channel(organization)
|
|
alert_group = make_alert_group(alert_receive_channel)
|
|
alert_payload = {
|
|
"text": "Hi, it's alert",
|
|
}
|
|
|
|
alert = make_alert(alert_group=alert_group, raw_request_data=alert_payload)
|
|
|
|
custom_button = make_custom_action(
|
|
name="github_button",
|
|
webhook="https://github.com/",
|
|
user="Chris Vanstras",
|
|
password="qwerty",
|
|
data='{"data" : "{{ alert_payload }}"}',
|
|
authorization_header="auth_token",
|
|
organization=organization,
|
|
)
|
|
|
|
custom_button.build_post_kwargs(alert)
|