-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from MountainGod2/dev
fix: update influxdb logic and improve testing coverage
- Loading branch information
Showing
9 changed files
with
291 additions
and
49 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
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
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
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
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,39 @@ | ||
# ruff: noqa: S101, S603 | ||
"""Test the Docker integration.""" | ||
|
||
import shutil | ||
import subprocess | ||
|
||
|
||
def test_docker_image_build(mocker) -> None: # noqa: ANN001 | ||
"""Test building the Docker image.""" | ||
docker_executable = shutil.which("docker") # Find the full path of the Docker executable | ||
assert docker_executable is not None, "Docker is not installed or not found in PATH" | ||
|
||
mock_subprocess = mocker.patch("subprocess.run") | ||
mock_subprocess.return_value.returncode = 0 | ||
|
||
result = subprocess.run( | ||
[docker_executable, "build", "-t", "chaturbate_poller:latest", "."], check=True | ||
) | ||
|
||
assert result.returncode == 0 | ||
mock_subprocess.assert_called_once_with( | ||
[docker_executable, "build", "-t", "chaturbate_poller:latest", "."], check=True | ||
) | ||
|
||
|
||
def test_docker_image_run(mocker) -> None: # noqa: ANN001 | ||
"""Test running the Docker container.""" | ||
docker_executable = shutil.which("docker") # Find the full path of the Docker executable | ||
assert docker_executable is not None, "Docker is not installed or not found in PATH" | ||
|
||
mock_subprocess = mocker.patch("subprocess.run") | ||
mock_subprocess.return_value.returncode = 0 | ||
|
||
result = subprocess.run([docker_executable, "run", "chaturbate_poller:latest"], check=True) | ||
|
||
assert result.returncode == 0 | ||
mock_subprocess.assert_called_once_with( | ||
[docker_executable, "run", "chaturbate_poller:latest"], check=True | ||
) |
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,24 @@ | ||
# ruff: noqa: S101 | ||
"""Tests for the format_messages module.""" | ||
|
||
import pytest | ||
|
||
from chaturbate_poller.format_messages import format_message | ||
from chaturbate_poller.models import Event, EventData | ||
|
||
|
||
@pytest.mark.asyncio() | ||
async def test_format_message_unknown_method() -> None: | ||
"""Test formatting an event with an unknown method.""" | ||
event = Event(method="unknown_method", object=EventData(), id="UNIQUE_EVENT_ID") | ||
formatted_message = await format_message(event) | ||
assert formatted_message == "Unknown method: unknown_method" | ||
|
||
|
||
@pytest.mark.asyncio() | ||
async def test_format_message_no_user_or_media() -> None: | ||
"""Test formatting an event with no user or media in the EventData.""" | ||
event_data = EventData(broadcaster="example_broadcaster") | ||
event = Event(method="mediaPurchase", object=event_data, id="UNIQUE_EVENT_ID") | ||
formatted_message = await format_message(event) | ||
assert formatted_message == "Unknown media purchase event" |
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
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,47 @@ | ||
# ruff: noqa: S101 | ||
"""Tests for the logging configuration module.""" | ||
|
||
import logging | ||
|
||
from chaturbate_poller.logging_config import CustomFormatter, SanitizeURLFilter, sanitize_url | ||
|
||
|
||
def test_sanitize_url() -> None: | ||
"""Test that the sanitize_url function masks sensitive information.""" | ||
url = "https://eventsapi.chaturbate.com/events/username/token/" | ||
sanitized = sanitize_url(url) | ||
assert sanitized == "https://eventsapi.chaturbate.com/events/USERNAME/TOKEN/" | ||
|
||
|
||
def test_sanitize_url_filter() -> None: | ||
"""Test the SanitizeURLFilter to ensure it sanitizes log messages.""" | ||
_filter = SanitizeURLFilter() | ||
log_record = logging.LogRecord( | ||
name="test", | ||
level=logging.INFO, | ||
pathname="", | ||
lineno=0, | ||
msg="https://eventsapi.chaturbate.com/events/username/token/", | ||
args=(), | ||
exc_info=None, | ||
) | ||
|
||
assert _filter.filter(log_record) | ||
assert log_record.msg == "https://eventsapi.chaturbate.com/events/USERNAME/TOKEN/" | ||
|
||
|
||
def test_custom_formatter() -> None: | ||
"""Test the CustomFormatter to ensure it formats log records properly.""" | ||
formatter = CustomFormatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") | ||
log_record = logging.LogRecord( | ||
name="test", | ||
level=logging.INFO, | ||
pathname="", | ||
lineno=0, | ||
msg="Test message", | ||
args=None, | ||
exc_info=None, | ||
) | ||
formatted = formatter.format(log_record) | ||
|
||
assert "Test message" in formatted |
Oops, something went wrong.