oncall-engine/engine/common/tests/test_urlvalidator_without_tld.py
Hamed Karbasi 9b70b79c78
use CustomURLValidator in custom_button (#1398)
# What this PR does
This PR, overrides Django URLValidator with a CustomURLValidator. It
just removes tld_re part from the regex, and the other behaviour remains
the same.
The CustomURLValidator is defined in common.api_helpers.utils.py file
and is utilized in custom_button.py.
Please inform me if it needs to be defined somewhere else or be
implemented with some other methods.

## Which issue(s) this PR fixes
Currently, URLValidator raises exception for URLs that don't have TLD.
This leads to not being able to use containers URL for outgoing webhooks
as they usually don't have TLD.

## Checklist

- [x] Tests updated
- [ ] Documentation added
- [x] `CHANGELOG.md` updated

---------

Co-authored-by: Joey Orlando <joey.orlando@grafana.com>
Co-authored-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>
Co-authored-by: Joey Orlando <joseph.t.orlando@gmail.com>
2023-03-23 12:21:17 +00:00

20 lines
636 B
Python

import pytest
from django.core.validators import ValidationError
from common.api_helpers.utils import URLValidatorWithoutTLD
valid_urls = ["https://www.google.com", "https://www.google", "http://conatainer1"]
invalid_urls = ["https:/www.google.com", "htt://www.google.com/"]
@pytest.mark.parametrize("url", valid_urls)
def test_urlvalidator_without_tld_valid_urls(url):
# Test valid URLs
URLValidatorWithoutTLD()(url)
@pytest.mark.parametrize("url", invalid_urls)
def test_urlvalidator_without_tld_invalid_urls(url):
# Test an invalid URL
with pytest.raises(ValidationError):
URLValidatorWithoutTLD()(url)