Skip to content

Commit

Permalink
Merge pull request #48 from MEHRSHAD-MIRSHEKARY/refactor/tests
Browse files Browse the repository at this point in the history
Refactor/tests
  • Loading branch information
ARYAN-NIKNEZHAD authored Aug 28, 2024
2 parents 1f7fa38 + 0011af7 commit 98daeee
Show file tree
Hide file tree
Showing 17 changed files with 107 additions and 20 deletions.
File renamed without changes.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ repos:
- id: commitizen
exclude: (tests/|docs/).*

- repo: https://github.com/PyCQA/bandit
rev: 1.7.4
hooks:
- id: bandit
args: [ "-c pyproject.toml" ]
additional_dependencies: [ "toml" ]
# - repo: https://github.com/PyCQA/bandit
# rev: 1.7.4
# hooks:
# - id: bandit
# args: [ "-c pyproject.toml" ]
# additional_dependencies: [ "toml" ]
9 changes: 8 additions & 1 deletion tests/commands/test_send_logs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import shutil
import sys
import tempfile
from unittest.mock import ANY, Mock, patch

Expand All @@ -8,7 +9,13 @@
from django.core.management import call_command
from django.test import TestCase

pytestmark = [pytest.mark.commands, pytest.mark.commands_send_logs]
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [
pytest.mark.commands,
pytest.mark.commands_send_logs,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class SendLogsCommandTests(TestCase):
Expand Down
2 changes: 2 additions & 0 deletions tests/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PYTHON_VERSION = (3, 8)
PYTHON_VERSION_REASON = "Requires Python 3.8 or higher"
8 changes: 7 additions & 1 deletion tests/filters/test_log_level_filter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import logging
import sys

import pytest

from django_logging.filters import LoggingLevelFilter
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [pytest.mark.filters, pytest.mark.filters_level_filter]
pytestmark = [
pytest.mark.filters,
pytest.mark.filters_level_filter,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class TestLoggingLevelFilter:
Expand Down
8 changes: 7 additions & 1 deletion tests/formatters/test_colored_formatter.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import logging
import sys
from unittest.mock import MagicMock, patch

import pytest

from django_logging.formatters import ColoredFormatter
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [pytest.mark.formatters, pytest.mark.colored_formatter]
pytestmark = [
pytest.mark.formatters,
pytest.mark.colored_formatter,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class TestColoredFormatter:
Expand Down
8 changes: 7 additions & 1 deletion tests/handlers/test_email_handler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import logging
import sys
from unittest.mock import ANY, MagicMock, patch

import pytest
from django.conf import settings

from django_logging.handlers.email_handler import EmailHandler
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [pytest.mark.handlers, pytest.mark.email_handler]
pytestmark = [
pytest.mark.handlers,
pytest.mark.email_handler,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class TestEmailHandler:
Expand Down
8 changes: 7 additions & 1 deletion tests/middleware/test_request_middleware.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import sys
from unittest.mock import Mock

import pytest
Expand All @@ -7,8 +8,13 @@
from django.test import RequestFactory

from django_logging.middleware import RequestLogMiddleware
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [pytest.mark.middleware, pytest.mark.request_middleware]
pytestmark = [
pytest.mark.middleware,
pytest.mark.request_middleware,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class TestRequestMiddleware:
Expand Down
8 changes: 7 additions & 1 deletion tests/settings/test_checks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from typing import Generator, List
from unittest.mock import patch

Expand All @@ -6,8 +7,13 @@
from django.core.checks import Error

from django_logging.settings.checks import check_logging_settings
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [pytest.mark.settings, pytest.mark.settings_checks]
pytestmark = [
pytest.mark.settings,
pytest.mark.settings_checks,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class TestChecks:
Expand Down
8 changes: 7 additions & 1 deletion tests/settings/test_conf.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import os
import sys
from shutil import rmtree
from unittest import mock

import pytest

from django_logging.constants import FORMAT_OPTIONS
from django_logging.settings.conf import LogConfig, LogManager
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [pytest.mark.settings, pytest.mark.settings_conf]
pytestmark = [
pytest.mark.settings,
pytest.mark.settings_conf,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class TestConf:
Expand Down
8 changes: 7 additions & 1 deletion tests/utils/test_context_manager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import logging
import sys
from unittest import mock

import pytest

from django_logging.utils.context_manager import _restore_logging_config, config_setup
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [pytest.mark.utils, pytest.mark.utils_context_manager]
pytestmark = [
pytest.mark.utils,
pytest.mark.utils_context_manager,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class TestContextManager:
Expand Down
8 changes: 7 additions & 1 deletion tests/utils/test_email_notifier.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import sys
import threading
from smtplib import SMTPException
from unittest.mock import ANY, MagicMock

import pytest

from django_logging.utils.log_email_notifier.notifier import send_email_async
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [pytest.mark.utils, pytest.mark.utils_email_notifier]
pytestmark = [
pytest.mark.utils,
pytest.mark.utils_email_notifier,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class TestEmailNotifier:
Expand Down
8 changes: 7 additions & 1 deletion tests/utils/test_get_conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from typing import Dict
from unittest.mock import patch

Expand All @@ -10,8 +11,13 @@
is_initialization_message_enabled,
use_email_notifier_template,
)
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [pytest.mark.utils, pytest.mark.utils_get_conf]
pytestmark = [
pytest.mark.utils,
pytest.mark.utils_get_conf,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class TestGetConf:
Expand Down
8 changes: 7 additions & 1 deletion tests/utils/test_log_and_notify.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import logging
import sys
from typing import Dict
from unittest.mock import MagicMock, patch

import pytest
from django.conf import settings

from django_logging.utils.log_email_notifier.log_and_notify import log_and_notify_admin
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [pytest.mark.utils, pytest.mark.utils_log_and_notify]
pytestmark = [
pytest.mark.utils,
pytest.mark.utils_log_and_notify,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class TestLogAndNotify:
Expand Down
8 changes: 7 additions & 1 deletion tests/utils/test_set_conf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import os
import sys
from unittest.mock import MagicMock, patch

import pytest

from django_logging.constants.ansi_colors import AnsiColors
from django_logging.utils.set_conf import set_config
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [pytest.mark.utils, pytest.mark.utils_set_conf]
pytestmark = [
pytest.mark.utils,
pytest.mark.utils_set_conf,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class TestSetConf:
Expand Down
8 changes: 7 additions & 1 deletion tests/validators/test_config_validators.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
from unittest.mock import patch

import pytest
Expand All @@ -12,8 +13,13 @@
validate_format_string,
validate_log_levels,
)
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [pytest.mark.validators, pytest.mark.config_validator]
pytestmark = [
pytest.mark.validators,
pytest.mark.config_validator,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class TestConfigValidator:
Expand Down
8 changes: 7 additions & 1 deletion tests/validators/test_email_settings_validator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import sys
from typing import Dict
from unittest.mock import patch

import pytest
from django.conf import settings

from django_logging.validators.email_settings_validator import check_email_settings
from tests.constants import PYTHON_VERSION, PYTHON_VERSION_REASON

pytestmark = [pytest.mark.validators, pytest.mark.email_settings_validator]
pytestmark = [
pytest.mark.validators,
pytest.mark.email_settings_validator,
pytest.mark.skipif(sys.version_info < PYTHON_VERSION, reason=PYTHON_VERSION_REASON),
]


class TestEmailSettingsValidator:
Expand Down

0 comments on commit 98daeee

Please sign in to comment.