-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create opensearch_external_url_formatter_test.py
Add a test file for opensearch_external_url_formatter
- Loading branch information
1 parent
42762f9
commit 8e07132
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import Any | ||
import os | ||
import pytest | ||
|
||
import requests | ||
from requests.auth import AuthBase, HTTPBasicAuth | ||
|
||
from elastalert.opensearch_external_url_formatter import AbsoluteOpensearchExternalUrlFormatter | ||
from elastalert.opensearch_external_url_formatter import OpensearchExternalUrlFormatter | ||
from elastalert.opensearch_external_url_formatter import create_opensearch_external_url_formatter | ||
|
||
from elastalert.auth import RefeshableAWSRequestsAuth | ||
from elastalert.util import EAException | ||
|
||
from unittest import mock | ||
|
||
|
||
class AbsoluteFormatTestCase: | ||
def __init__( | ||
self, | ||
base_url: str, | ||
relative_url: str, | ||
expected_url: str, | ||
) -> None: | ||
self.base_url = base_url | ||
self.relative_url = relative_url | ||
self.expected_url = expected_url | ||
|
||
|
||
@pytest.mark.parametrize("test_case", [ | ||
# Relative to OpenSearch Dashboards | ||
AbsoluteFormatTestCase( | ||
base_url='http://opensearch.test.org/_dashboards/', | ||
relative_url='app/dev_tools#/console', | ||
expected_url='http://opensearch.test.org/_dashboards/app/dev_tools#/console' | ||
), | ||
]) | ||
|
||
|
||
def test_absolute_opensearch_external_url_formatter( | ||
test_case: AbsoluteFormatTestCase | ||
): | ||
formatter = AbsoluteOpensearchExternalUrlFormatter( | ||
base_url=test_case.base_url | ||
) | ||
actualUrl = formatter.format(test_case.relative_url) | ||
print(actualUrl) | ||
assert actualUrl == test_case.expected_url |