Skip to content

Commit

Permalink
Fix GH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroLQueiroz committed Apr 7, 2024
1 parent 30cf195 commit 766ce53
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 23 deletions.
17 changes: 13 additions & 4 deletions .github/workflows/test.yml
Expand Up @@ -11,7 +11,7 @@ on:
jobs:
code-check:
name: Code checking
runs-on: macos-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
Expand All @@ -20,13 +20,22 @@ jobs:
python-version: "3.11"
- name: Install poetry
run: pipx install poetry
- name: Set python version for poetry
run: poetry env use python3.11
- name: Install dependencies
run: poetry install
# - name: Run Isort
# run: poetry run -v -- isort -c notifications/ sample_website/
# - name: Run Black
# run: poetry run -v -- black --check notifications/ sample_website/
- name: versions
run: python --version & whereis python & poetry --version & poetry run pylint --version & poetry env info
- name: Run Pylint
run: poetry run -v -- pylint --rcfile=pyproject.toml notifications/ sample_website/
run: poetry run -v -- pylint --rcfile=pyproject.toml --recursive=y -v notifications/ sample_website/
- name: Run Bandit
run: poetry run -v -- bandit -c pyproject.toml -r notifications/ sample_website/

- name: Run Mypy
run: poetry run -v -- mypy

test:
name: Testing
Expand All @@ -47,7 +56,7 @@ jobs:
- name: Install dependencies
run: poetry install
- name: Run tests
run: poetry run pytest
run: poetry run -- pytest
env:
COVERAGE_FILE: ".coverage.${{ matrix.python_version }}"
- name: Store coverage file
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Expand Up @@ -21,7 +21,7 @@ repos:
hooks:
- id: pylint
name: pylint
entry: poetry run pylint
entry: poetry run -- pylint
language: system
args: ["--rcfile=pyproject.toml"]

Expand Down
2 changes: 1 addition & 1 deletion dockerfile
Expand Up @@ -20,4 +20,4 @@ RUN pyenv local system 3.8 3.9 3.10
RUN apt-get --purge autoremove -y gnupg; \
rm -rf /var/cache/apt/lists;

ENTRYPOINT poetry install && poetry run pre-commit install && /bin/bash
ENTRYPOINT poetry install && poetry run -- pre-commit install && /bin/bash
4 changes: 2 additions & 2 deletions notifications/admin.py
Expand Up @@ -28,9 +28,9 @@ def get_queryset(self, request: HttpRequest):
return qs.prefetch_related("actor")

@admin.action(description=gettext_lazy("Mark selected notifications as unread"))
def mark_unread(self, request: HttpRequest, queryset: NotificationQuerySet): # pylint: disable=unused-argument
def mark_unread(self, request: HttpRequest, queryset: NotificationQuerySet):
queryset.update(unread=True)

@admin.action(description=gettext_lazy("Mark selected notifications as read"))
def mark_read(self, request: HttpRequest, queryset: NotificationQuerySet): # pylint: disable=unused-argument
def mark_read(self, request: HttpRequest, queryset: NotificationQuerySet):
queryset.update(unread=False)
16 changes: 10 additions & 6 deletions notifications/settings.py
Expand Up @@ -40,14 +40,16 @@ class NotificationSettings:
"""

def __init__(self, defaults: None | NotificationDefaultsType = None):
self._user_settings = None
self.defaults = defaults or NotificationDefaultsType(**NOTIFICATION_DEFAULTS)
self._user_settings: NotificationDefaultsType | None = None
self.defaults = defaults or NotificationDefaultsType(**NOTIFICATION_DEFAULTS) # type: ignore[typeddict-item]
self._cached_attrs: set[str] = set()

@property
def user_settings(self) -> NotificationDefaultsType:
if not self._user_settings:
self._user_settings = NotificationDefaultsType(**getattr(settings, "DJANGO_NOTIFICATIONS_CONFIG") or {})
self._user_settings = NotificationDefaultsType(
**getattr(settings, "DJANGO_NOTIFICATIONS_CONFIG") or {}
) # type: ignore[typeddict-item]
return self._user_settings

def __getattr__(self, attr: str) -> NotificationDefaultsType:
Expand All @@ -56,10 +58,10 @@ def __getattr__(self, attr: str) -> NotificationDefaultsType:

try:
# Check if present in user settings
val = self.user_settings[attr]
val = self.user_settings[attr] # type: ignore[literal-required]
except KeyError:
# Fall back to defaults
val = self.defaults[attr]
val = self.defaults[attr] # type: ignore[literal-required]

# Cache the result
self._cached_attrs.add(attr)
Expand All @@ -73,7 +75,9 @@ def reload(self):
self._user_settings = None


notification_settings = NotificationSettings(NOTIFICATION_DEFAULTS)
notification_settings = NotificationSettings(
NotificationDefaultsType(**NOTIFICATION_DEFAULTS)
) # type: ignore[typeddict-item]


def reload_notification_settings(*args: Any, **kwargs: Any): # pylint: disable=unused-argument
Expand Down
11 changes: 5 additions & 6 deletions notifications/tests/tests.py
Expand Up @@ -4,7 +4,6 @@
Replace this with more appropriate tests for your application.
"""
# -*- coding: utf-8 -*-
# pylint: disable=too-many-lines,missing-docstring
import json
from datetime import datetime, timezone

Expand Down Expand Up @@ -107,7 +106,7 @@ def test_notify_send_return_val(self):
# only check types for now
self.assertEqual(type(result[1][0]), Notification)

def test_notify_send_return_val_group(self): # pylint: disable=invalid-name
def test_notify_send_return_val_group(self):
results = notify.send(self.from_user, recipient=self.to_group, verb="commented", action_object=self.from_user)
for result in results:
if result[0] is notify_handler:
Expand Down Expand Up @@ -137,7 +136,7 @@ def test_mark_all_as_read_manager(self):
Notification.objects.filter(recipient=self.to_user).mark_all_as_read()
self.assertEqual(self.to_user.notifications.unread().count(), 0)

@override_settings(DJANGO_NOTIFICATIONS_CONFIG={"SOFT_DELETE": True}) # pylint: disable=invalid-name
@override_settings(DJANGO_NOTIFICATIONS_CONFIG={"SOFT_DELETE": True})
def test_mark_all_as_read_manager_with_soft_delete(self):
# even soft-deleted notifications should be marked as read
# refer: https://github.com/django-notifications/django-notifications/issues/126
Expand All @@ -155,7 +154,7 @@ def test_mark_all_as_unread_manager(self):
Notification.objects.filter(recipient=self.to_user).mark_all_as_unread()
self.assertEqual(Notification.objects.unread().count(), self.message_count)

def test_mark_all_deleted_manager_without_soft_delete(self): # pylint: disable=invalid-name
def test_mark_all_deleted_manager_without_soft_delete(self):
self.assertRaises(ImproperlyConfigured, Notification.objects.active)
self.assertRaises(ImproperlyConfigured, Notification.objects.active)
self.assertRaises(ImproperlyConfigured, Notification.objects.mark_all_as_deleted)
Expand Down Expand Up @@ -295,7 +294,7 @@ def test_delete_messages_pages(self):
self.assertEqual(len(response.context["notifications"]), len(self.to_user.notifications.unread()))
self.assertEqual(len(response.context["notifications"]), self.message_count - 1)

@override_settings(DJANGO_NOTIFICATIONS_CONFIG={"SOFT_DELETE": True}) # pylint: disable=invalid-name
@override_settings(DJANGO_NOTIFICATIONS_CONFIG={"SOFT_DELETE": True})
def test_soft_delete_messages_manager(self):
self.login("to", "pwd")

Expand Down Expand Up @@ -439,7 +438,7 @@ def test_all_list_api(self):
self.assertEqual(data["all_list"][0]["verb"], "commented")
self.assertEqual(data["all_list"][0]["slug"], data["all_list"][0]["id"])

def test_unread_list_api_mark_as_read(self): # pylint: disable=invalid-name
def test_unread_list_api_mark_as_read(self):
self.login("to", "pwd")
num_requested = 3
response = self.client.get(
Expand Down
2 changes: 1 addition & 1 deletion notifications/types.py
Expand Up @@ -2,4 +2,4 @@

from django.contrib.auth.base_user import AbstractBaseUser

AbstractUser = NewType("AbstractUser", AbstractBaseUser)
AbstractUser = NewType("AbstractUser", AbstractBaseUser) # type: ignore[valid-newtype]
13 changes: 11 additions & 2 deletions pyproject.toml
Expand Up @@ -53,7 +53,7 @@ classifiers = [
"Framework :: Django",
"Framework :: Django :: 3.2",
"Framework :: Django :: 4.0",
"Framework :: Django :: 4.1",
"Framework :: Django :: 5.0",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
Expand Down Expand Up @@ -141,9 +141,9 @@ disable = [
[tool.pylint.FORMAT]
max-line-length = 120


[tool.black]
line-length = 120
extend-exclude = "migrations/"

[tool.isort]
profile = "black"
Expand Down Expand Up @@ -180,8 +180,17 @@ testpaths = [
]
DJANGO_SETTINGS_MODULE = "notifications.tests.settings_for_tests"
django_debug_mode = "keep"
show_locals=true

[tool.coverage.run]
relative_files = true
parallel = true
branch = true

[tool.coverage.html]
directory = "coverage_html_report"

[tool.mypy]
files = "**/*.py"
exclude = "migration/*"
ignore_missing_imports=true

0 comments on commit 766ce53

Please sign in to comment.