diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5ae22dd..c22982a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -14,16 +14,16 @@ jobs: # 並列して実行する各ジョブのPythonバージョン strategy: matrix: - python-version: ['3.6', '3.9'] - django-version: ['2.2', '3.2'] + python-version: ['3.9', '3.10', '3.11', '3.12'] + django-version: ['3.2', '4.2'] steps: # ソースコードをチェックアウト - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 # ジョブのPython環境を設定 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} diff --git a/.hgignore b/.hgignore deleted file mode 100644 index a808144..0000000 --- a/.hgignore +++ /dev/null @@ -1,19 +0,0 @@ -syntax: glob -*.orig -*.rej -*~ -*.bak -*.marks -*.o -*.pyc -*.swp -*.egg-info -*.egg -.tox -build -dist -pip-log.txt -docs/*/build - -syntax: regexp -.*\#.*\#$ diff --git a/CHANGES.rst b/CHANGES.rst index 3a19a67..e0e1606 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,18 @@ ChangeLog ========= +0.49 (2024-02-XX) +=================== + +Features: + +* Add Support Python3.10~3.12, Django4.2 + +Incompatible Changes: + +* Drop Python3.6 & Django2.2 +* Migrate from django-jsonfield to models.JSONField + 0.48 (2022-04-11) =================== diff --git a/MANIFEST.in b/MANIFEST.in index 4a467e1..3c683ad 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,3 @@ -recursive-include beproud/django/notify/tests/templates * recursive-include beproud/django/notify/templates * recursive-include beproud/django/notify/fixtures * include README.rst diff --git a/README.rst b/README.rst index 5a8adc5..8e43d6f 100644 --- a/README.rst +++ b/README.rst @@ -7,11 +7,10 @@ Requirements ============ -* Python (3.6, 3.9) -* Celery (4.2, 5.1, 5.2) -* Django (2.2, 3.2) +* Python (3.9, 3.10, 3.11, 3.12) +* Celery (5.2, 5.3) +* Django (3.2, 4.2) * six -* django-jsonfield (1.0.1) Links ================= diff --git a/beproud/django/notify/models.py b/beproud/django/notify/models.py index 9e3b6ab..313c147 100644 --- a/beproud/django/notify/models.py +++ b/beproud/django/notify/models.py @@ -3,11 +3,9 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.fields import GenericForeignKey -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ from django.db import models -import jsonfield - from beproud.django.notify.api import _get_media_map __all__ = ( @@ -42,7 +40,7 @@ class Notification(models.Model): notify_type = models.CharField(_('notify type'), max_length=100, db_index=True) media = models.CharField(_('media'), max_length=100, choices=MediaChoices(), db_index=True) - extra_data = jsonfield.JSONField(_('extra data'), null=True, blank=True) + extra_data = models.JSONField(_('extra data'), null=True, blank=True) ctime = models.DateTimeField(_('created'), auto_now_add=True, db_index=True) diff --git a/beproud/django/notify/tests/__init__.py b/beproud/django/notify/tests/__init__.py deleted file mode 100644 index 49ba9c0..0000000 --- a/beproud/django/notify/tests/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from beproud.django.notify.tests.test_basic import * #NOQA -from beproud.django.notify.tests.test_mail import * #NOQA -from beproud.django.notify.tests.test_storage import * #NOQA -from beproud.django.notify.tests.test_tasks import * #NOQA diff --git a/setup.py b/setup.py index 7bfab3c..02a4dc4 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ def read_file(filename): long_description=read_file('README.rst'), long_description_content_type="text/x-rst", url='https://github.com/beproud/bpnotify/', - python_requires='>=3.6', + python_requires='>=3.9', classifiers=[ 'Development Status :: 3 - Alpha', 'Environment :: Plugins', @@ -30,11 +30,13 @@ def read_file(filename): 'License :: OSI Approved :: BSD License', 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', 'Framework :: Django', - 'Framework :: Django :: 2.2', 'Framework :: Django :: 3.2', + 'Framework :: Django :: 4.2', 'Topic :: Software Development :: Libraries :: Python Modules', ], include_package_data=True, @@ -42,9 +44,8 @@ def read_file(filename): namespace_packages=['beproud', 'beproud.django'], test_suite='tests.main', install_requires=[ - 'Django>=2.2', - 'django-jsonfield>=1.0.1', - 'Celery>=4.2', + 'Django~=3.2', + 'Celery~=5.2', 'six', ], zip_safe=False, diff --git a/tests.py b/tests.py deleted file mode 100644 index 8945737..0000000 --- a/tests.py +++ /dev/null @@ -1,46 +0,0 @@ -import os -import sys -import django -import celery - -import test_settings - -BASE_PATH = os.path.dirname(__file__) - - -def main(): - """ - Standalone django model test with a 'memory-only-django-installation'. - You can play with a django model without a complete django app installation. - http://www.djangosnippets.org/snippets/1044/ - """ - - # Django標準のdjango.conf.global_settingsを設定してしまうと、 - # Django3では、global_settingsの全ての定数を上書きする挙動になってしまい、 - # Django3の仕様で、多重上書き禁止エラーが検知され、例外が発生する。 - # (例) https://github.com/django/django/blob/70035fb0444ae7c01613374212ca5e3c27c9782c/django/conf/__init__.py#L188 - # そのため、自前のテスト用settingsモジュール(test_settings.py)を設定する。 - os.environ["DJANGO_SETTINGS_MODULE"] = "test_settings" - - app = celery.Celery() - app.config_from_object('django.conf:settings', namespace='CELERY') - app.autodiscover_tasks(lambda: test_settings.INSTALLED_APPS) - - django.setup() - - from django.test.utils import get_runner - - # test用のsettings情報を用いて、Djangoのtest runnerクラスを取得 - TestRunner = get_runner(test_settings) - - # test runnerオブジェクトを生成 - test_runner = TestRunner() - - # test runnerにbpnotifyの単体テストのPathを渡して、bpnotifyの単体テストを実行する - failures = test_runner.run_tests(['beproud.django.notify.tests']) - - sys.exit(failures) - - -if __name__ == '__main__': - main() diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/beproud/django/notify/tests/base.py b/tests/base.py similarity index 100% rename from beproud/django/notify/tests/base.py rename to tests/base.py diff --git a/test_settings.py b/tests/settings.py similarity index 100% rename from test_settings.py rename to tests/settings.py diff --git a/beproud/django/notify/tests/templates/notify/private_msg/private_messages/mail_body.html b/tests/templates/notify/private_msg/private_messages/mail_body.html similarity index 100% rename from beproud/django/notify/tests/templates/notify/private_msg/private_messages/mail_body.html rename to tests/templates/notify/private_msg/private_messages/mail_body.html diff --git a/beproud/django/notify/tests/templates/notify/private_msg/private_messages/mail_body.txt b/tests/templates/notify/private_msg/private_messages/mail_body.txt similarity index 100% rename from beproud/django/notify/tests/templates/notify/private_msg/private_messages/mail_body.txt rename to tests/templates/notify/private_msg/private_messages/mail_body.txt diff --git a/beproud/django/notify/tests/templates/notify/private_msg/private_messages/mail_subject.txt b/tests/templates/notify/private_msg/private_messages/mail_subject.txt similarity index 100% rename from beproud/django/notify/tests/templates/notify/private_msg/private_messages/mail_subject.txt rename to tests/templates/notify/private_msg/private_messages/mail_subject.txt diff --git a/beproud/django/notify/tests/test_basic.py b/tests/test_basic.py similarity index 59% rename from beproud/django/notify/tests/test_basic.py rename to tests/test_basic.py index 28ec02e..2ff0501 100644 --- a/beproud/django/notify/tests/test_basic.py +++ b/tests/test_basic.py @@ -7,7 +7,7 @@ from django.contrib.auth.models import User from django.test import TestCase -from beproud.django.notify.tests.base import TestBase +from tests.base import TestBase from beproud.django.notify.models import Notification, NotifySetting from beproud.django.notify.api import ( notify_now, @@ -29,32 +29,32 @@ def test_sending_model(self): user = User.objects.get(pk=2) items_sent = notify_now(user, 'follow', extra_data={"followed": "eggs"}) # 1 news model - self.assertEquals(items_sent, 1) + self.assertEqual(items_sent, 1) news = Notification.objects.filter(media='news') - self.assertEquals(len(news), 1) - self.assertEquals(news[0].media, 'news') - self.assertEquals(news[0].notify_type, 'follow') - self.assertEquals(news[0].target, user) - self.assertEquals(news[0].extra_data.get('followed'), 'eggs') + self.assertEqual(len(news), 1) + self.assertEqual(news[0].media, 'news') + self.assertEqual(news[0].notify_type, 'follow') + self.assertEqual(news[0].target, user) + self.assertEqual(news[0].extra_data.get('followed'), 'eggs') private_messages = Notification.objects.exclude(media='news') - self.assertEquals(len(private_messages), 0) + self.assertEqual(len(private_messages), 0) def test_sending_model_null(self): items_sent = notify_now(None, 'follow', extra_data={"followed": "eggs"}) # 1 news model - self.assertEquals(items_sent, 1) + self.assertEqual(items_sent, 1) news = Notification.objects.filter(media='news') - self.assertEquals(len(news), 1) - self.assertEquals(news[0].media, 'news') - self.assertEquals(news[0].notify_type, 'follow') - self.assertEquals(news[0].target, None) - self.assertEquals(news[0].extra_data.get('followed'), 'eggs') + self.assertEqual(len(news), 1) + self.assertEqual(news[0].media, 'news') + self.assertEqual(news[0].notify_type, 'follow') + self.assertEqual(news[0].target, None) + self.assertEqual(news[0].extra_data.get('followed'), 'eggs') private_messages = Notification.objects.exclude(media='news') - self.assertEquals(len(private_messages), 0) + self.assertEqual(len(private_messages), 0) def test_sending_model_types(self): user = User.objects.get(pk=2) @@ -62,42 +62,42 @@ def test_sending_model_types(self): # 1 private_messages model # 1 private_messages mail # 1 news model - self.assertEquals(items_sent, 3) + self.assertEqual(items_sent, 3) private_messages = Notification.objects.filter(media='private_messages') - self.assertEquals(len(private_messages), 1) - self.assertEquals(private_messages[0].media, 'private_messages') - self.assertEquals(private_messages[0].notify_type, 'private_msg') - self.assertEquals(private_messages[0].target, user) - self.assertEquals(private_messages[0].extra_data.get('spam'), 'eggs') + self.assertEqual(len(private_messages), 1) + self.assertEqual(private_messages[0].media, 'private_messages') + self.assertEqual(private_messages[0].notify_type, 'private_msg') + self.assertEqual(private_messages[0].target, user) + self.assertEqual(private_messages[0].extra_data.get('spam'), 'eggs') news = Notification.objects.filter(media='news') - self.assertEquals(len(news), 1) - self.assertEquals(news[0].media, 'news') - self.assertEquals(news[0].notify_type, 'private_msg') - self.assertEquals(news[0].target, user) - self.assertEquals(news[0].extra_data.get('spam'), 'eggs') + self.assertEqual(len(news), 1) + self.assertEqual(news[0].media, 'news') + self.assertEqual(news[0].notify_type, 'private_msg') + self.assertEqual(news[0].target, user) + self.assertEqual(news[0].extra_data.get('spam'), 'eggs') def test_sending_model_types_null(self): items_sent = notify_now(None, 'private_msg', extra_data={"spam": "eggs"}) # 1 private_messages model # 0 private_messages mail (No mail to null target) # 1 news model - self.assertEquals(items_sent, 2) + self.assertEqual(items_sent, 2) private_messages = Notification.objects.filter(media='private_messages') - self.assertEquals(len(private_messages), 1) - self.assertEquals(private_messages[0].media, 'private_messages') - self.assertEquals(private_messages[0].notify_type, 'private_msg') - self.assertEquals(private_messages[0].target, None) - self.assertEquals(private_messages[0].extra_data.get('spam'), 'eggs') + self.assertEqual(len(private_messages), 1) + self.assertEqual(private_messages[0].media, 'private_messages') + self.assertEqual(private_messages[0].notify_type, 'private_msg') + self.assertEqual(private_messages[0].target, None) + self.assertEqual(private_messages[0].extra_data.get('spam'), 'eggs') news = Notification.objects.filter(media='news') - self.assertEquals(len(news), 1) - self.assertEquals(news[0].media, 'news') - self.assertEquals(news[0].notify_type, 'private_msg') - self.assertEquals(news[0].target, None) - self.assertEquals(news[0].extra_data.get('spam'), 'eggs') + self.assertEqual(len(news), 1) + self.assertEqual(news[0].media, 'news') + self.assertEqual(news[0].notify_type, 'private_msg') + self.assertEqual(news[0].target, None) + self.assertEqual(news[0].extra_data.get('spam'), 'eggs') def test_sending_model_multi(self): @@ -107,7 +107,7 @@ def test_sending_model_multi(self): # 3 private_messages model # 2 private_messages mail (No mail to null target) # 3 news model - self.assertEquals(items_sent, 8) + self.assertEqual(items_sent, 8) # User1 private_messages = Notification.objects.filter( @@ -115,22 +115,22 @@ def test_sending_model_multi(self): target_content_type=ContentType.objects.get_for_model(user[0]), target_object_id=user[0].id, ) - self.assertEquals(len(private_messages), 1) - self.assertEquals(private_messages[0].media, 'private_messages') - self.assertEquals(private_messages[0].notify_type, 'private_msg') - self.assertEquals(private_messages[0].target, user[0]) - self.assertEquals(private_messages[0].extra_data.get('spam'), 'eggs') + self.assertEqual(len(private_messages), 1) + self.assertEqual(private_messages[0].media, 'private_messages') + self.assertEqual(private_messages[0].notify_type, 'private_msg') + self.assertEqual(private_messages[0].target, user[0]) + self.assertEqual(private_messages[0].extra_data.get('spam'), 'eggs') news = Notification.objects.filter( media='news', target_content_type=ContentType.objects.get_for_model(user[0]), target_object_id=user[0].id, ) - self.assertEquals(len(news), 1) - self.assertEquals(news[0].media, 'news') - self.assertEquals(news[0].notify_type, 'private_msg') - self.assertEquals(news[0].target, user[0]) - self.assertEquals(news[0].extra_data.get('spam'), 'eggs') + self.assertEqual(len(news), 1) + self.assertEqual(news[0].media, 'news') + self.assertEqual(news[0].notify_type, 'private_msg') + self.assertEqual(news[0].target, user[0]) + self.assertEqual(news[0].extra_data.get('spam'), 'eggs') # User2 private_messages = Notification.objects.filter( @@ -138,22 +138,22 @@ def test_sending_model_multi(self): target_content_type=ContentType.objects.get_for_model(user[1]), target_object_id=user[1].id, ) - self.assertEquals(len(private_messages), 1) - self.assertEquals(private_messages[0].media, 'private_messages') - self.assertEquals(private_messages[0].notify_type, 'private_msg') - self.assertEquals(private_messages[0].target, user[1]) - self.assertEquals(private_messages[0].extra_data.get('spam'), 'eggs') + self.assertEqual(len(private_messages), 1) + self.assertEqual(private_messages[0].media, 'private_messages') + self.assertEqual(private_messages[0].notify_type, 'private_msg') + self.assertEqual(private_messages[0].target, user[1]) + self.assertEqual(private_messages[0].extra_data.get('spam'), 'eggs') news = Notification.objects.filter( media='news', target_content_type=ContentType.objects.get_for_model(user[1]), target_object_id=user[1].id, ) - self.assertEquals(len(news), 1) - self.assertEquals(news[0].media, 'news') - self.assertEquals(news[0].notify_type, 'private_msg') - self.assertEquals(news[0].target, user[1]) - self.assertEquals(news[0].extra_data.get('spam'), 'eggs') + self.assertEqual(len(news), 1) + self.assertEqual(news[0].media, 'news') + self.assertEqual(news[0].notify_type, 'private_msg') + self.assertEqual(news[0].target, user[1]) + self.assertEqual(news[0].extra_data.get('spam'), 'eggs') # Null Target private_messages = Notification.objects.filter( @@ -161,34 +161,34 @@ def test_sending_model_multi(self): target_content_type__isnull=True, target_object_id__isnull=True, ) - self.assertEquals(len(private_messages), 1) - self.assertEquals(private_messages[0].media, 'private_messages') - self.assertEquals(private_messages[0].notify_type, 'private_msg') - self.assertEquals(private_messages[0].target, None) - self.assertEquals(private_messages[0].extra_data.get('spam'), 'eggs') + self.assertEqual(len(private_messages), 1) + self.assertEqual(private_messages[0].media, 'private_messages') + self.assertEqual(private_messages[0].notify_type, 'private_msg') + self.assertEqual(private_messages[0].target, None) + self.assertEqual(private_messages[0].extra_data.get('spam'), 'eggs') news = Notification.objects.filter( media='news', target_content_type__isnull=True, target_object_id__isnull=True, ) - self.assertEquals(len(news), 1) - self.assertEquals(news[0].media, 'news') - self.assertEquals(news[0].notify_type, 'private_msg') - self.assertEquals(news[0].target, None) - self.assertEquals(news[0].extra_data.get('spam'), 'eggs') + self.assertEqual(len(news), 1) + self.assertEqual(news[0].media, 'news') + self.assertEqual(news[0].notify_type, 'private_msg') + self.assertEqual(news[0].target, None) + self.assertEqual(news[0].extra_data.get('spam'), 'eggs') def test_sending_with_settings(self): user = [User.objects.get(pk=1), User.objects.get(pk=2)] items_sent = notify_now(user, 'followed', extra_data={"spam": "eggs"}) - self.assertEquals(items_sent, 0) + self.assertEqual(items_sent, 0) self.assertTrue(set_notify_setting(user[0], 'followed', 'news', True)) items_sent = notify_now(user, 'followed', extra_data={"spam": "eggs"}) # 1 news model - self.assertEquals(items_sent, 1) + self.assertEqual(items_sent, 1) def test_settings_null(self): self.assertFalse(set_notify_setting(None, 'followed', 'news', True)) @@ -206,30 +206,30 @@ def test_get_notifications(self): # 2 private_messages model # 2 private_messages mail # 2 news model - self.assertEquals(items_sent, 6) + self.assertEqual(items_sent, 6) for index in [0, 1]: news = get_notifications(user[index], 'news') self.assertTrue(hasattr(news, '__iter__'), 'news notifications is not an iterable!') - self.assertEquals(len(news), 1) + self.assertEqual(len(news), 1) self.assertTrue(isinstance(news[0], dict), 'news notification is not a dict!') self.assertTrue(news[0].get('id', False), 'news notification has no id') - self.assertEquals(news[0].get('target'), user[index]) - self.assertEquals(news[0].get('notify_type'), 'private_msg') - self.assertEquals(news[0].get('media'), 'news') - self.assertEquals(news[0].get('extra_data'), {'spam': 'eggs'}) + self.assertEqual(news[0].get('target'), user[index]) + self.assertEqual(news[0].get('notify_type'), 'private_msg') + self.assertEqual(news[0].get('media'), 'news') + self.assertEqual(news[0].get('extra_data'), {'spam': 'eggs'}) self.assertTrue(isinstance(news[0].get('ctime'), datetime), 'news ctime is not a datetime!') private_messages = get_notifications(user[index], 'private_messages') self.assertTrue(hasattr(private_messages, '__iter__'), 'private_messages notifications is not an iterable!') - self.assertEquals(len(private_messages), 1) + self.assertEqual(len(private_messages), 1) self.assertTrue(isinstance(private_messages[0], dict), 'private_messages notification is not a dict!') self.assertTrue(private_messages[0].get('id', False), 'private_messages notification has no id') - self.assertEquals(private_messages[0].get('target'), user[index]) - self.assertEquals(private_messages[0].get('notify_type'), 'private_msg') - self.assertEquals(private_messages[0].get('media'), 'private_messages') - self.assertEquals(private_messages[0].get('extra_data'), {'spam': 'eggs'}) + self.assertEqual(private_messages[0].get('target'), user[index]) + self.assertEqual(private_messages[0].get('notify_type'), 'private_msg') + self.assertEqual(private_messages[0].get('media'), 'private_messages') + self.assertEqual(private_messages[0].get('extra_data'), {'spam': 'eggs'}) self.assertTrue(isinstance(news[0].get('ctime'), datetime), 'news ctime is not a datetime!') def test_object_list(self): @@ -274,9 +274,9 @@ def test_notify_type_length(self): user = User.objects.get(pk=2) items_sent = notify_now(user, 'notify_type_with_length_over_thirty') # 1 news model - self.assertEquals(items_sent, 1) + self.assertEqual(items_sent, 1) - self.assertEquals( + self.assertEqual( Notification.objects.filter(notify_type='notify_type_with_length_over_thirty').count(), 1, ) @@ -284,22 +284,22 @@ def test_notify_type_length(self): class ModelUnicodeTest(TestCase): def test_notification_unicode(self): notice = Notification() - self.assertEquals(str(notice), "None (, )") + self.assertEqual(str(notice), "None (, )") notice.notify_type = u"テスト" notice.media = "yyy" if six.PY2: - self.assertEquals(str(notice), u"None (テスト, yyy)".encode("utf-8")) + self.assertEqual(str(notice), u"None (テスト, yyy)".encode("utf-8")) else: - self.assertEquals(str(notice), "None (テスト, yyy)") + self.assertEqual(str(notice), "None (テスト, yyy)") def test_notification_setting_unicode(self): setting = NotifySetting() - self.assertEquals(str(setting), "None (, , no send)") + self.assertEqual(str(setting), "None (, , no send)") setting.notify_type = u"テスト" setting.media = "yyy" setting.send = True if six.PY2: - self.assertEquals(str(setting), u"None (テスト, yyy, send)".encode("utf-8")) + self.assertEqual(str(setting), u"None (テスト, yyy, send)".encode("utf-8")) else: - self.assertEquals(str(setting), "None (テスト, yyy, send)") + self.assertEqual(str(setting), "None (テスト, yyy, send)") diff --git a/beproud/django/notify/tests/test_mail.py b/tests/test_mail.py similarity index 59% rename from beproud/django/notify/tests/test_mail.py rename to tests/test_mail.py index b215d30..d58887f 100644 --- a/beproud/django/notify/tests/test_mail.py +++ b/tests/test_mail.py @@ -4,7 +4,7 @@ from django.core import mail from django.test import TestCase -from beproud.django.notify.tests.base import TestBase +from tests.base import TestBase from beproud.django.notify.api import notify_now @@ -20,20 +20,20 @@ def test_sending_mail(self): # 1 private_messages model # 1 news model # 1 private_messages mail - self.assertEquals(items_sent, 3) + self.assertEqual(items_sent, 3) - self.assertEquals(len(mail.outbox), 1) - self.assertEquals(mail.outbox[0].subject, u'テストメール private_msg private_messages eggs') - self.assertEquals(mail.outbox[0].body, u'Text メールボディ private_msg private_messages eggs\n') + self.assertEqual(len(mail.outbox), 1) + self.assertEqual(mail.outbox[0].subject, u'テストメール private_msg private_messages eggs') + self.assertEqual(mail.outbox[0].body, u'Text メールボディ private_msg private_messages eggs\n') def test_from_email(self): user = User.objects.get(pk=2) notify_now(user, 'private_msg', extra_data={"spam": "eggs", "from_email": "spameggs@example.com"}) - self.assertEquals(len(mail.outbox), 1) - self.assertEquals(mail.outbox[0].from_email, "spameggs@example.com") + self.assertEqual(len(mail.outbox), 1) + self.assertEqual(mail.outbox[0].from_email, "spameggs@example.com") def test_from_mail(self): user = User.objects.get(pk=2) notify_now(user, 'private_msg', extra_data={"spam": "eggs", "from_mail": "spameggs@example.com"}) - self.assertEquals(len(mail.outbox), 1) - self.assertEquals(mail.outbox[0].from_email, "spameggs@example.com") + self.assertEqual(len(mail.outbox), 1) + self.assertEqual(mail.outbox[0].from_email, "spameggs@example.com") diff --git a/beproud/django/notify/tests/test_storage.py b/tests/test_storage.py similarity index 98% rename from beproud/django/notify/tests/test_storage.py rename to tests/test_storage.py index 868765b..ee09be5 100644 --- a/beproud/django/notify/tests/test_storage.py +++ b/tests/test_storage.py @@ -4,7 +4,7 @@ from django.contrib.auth.models import User from django.test import TestCase -from beproud.django.notify.tests.base import TestBase +from tests.base import TestBase from beproud.django.notify.storage import get_storage from beproud.django.notify.models import NotifySetting diff --git a/beproud/django/notify/tests/test_tasks.py b/tests/test_tasks.py similarity index 88% rename from beproud/django/notify/tests/test_tasks.py rename to tests/test_tasks.py index a02834b..ad4d44e 100644 --- a/beproud/django/notify/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -5,7 +5,7 @@ from django.test import TestCase from django.contrib.auth.models import User -from beproud.django.notify.tests.utils import override_settings +from tests.utils import override_settings from beproud.django.notify.models import Notification from beproud.django.notify import tasks as notify_tasks from beproud.django.notify import api as notify_api @@ -46,9 +46,9 @@ def test_notify_task(self): ) private_messages = Notification.objects.filter(media="news") - self.assertEquals(len(private_messages), 1) - self.assertEquals(private_messages[0].notify_type, 'private_msg') - self.assertEquals(private_messages[0].target, user) + self.assertEqual(len(private_messages), 1) + self.assertEqual(private_messages[0].notify_type, 'private_msg') + self.assertEqual(private_messages[0].target, user) @mock.patch.object(notify_tasks, 'notify_now') def test_notify_task_retry(self, notify_now): @@ -73,7 +73,7 @@ def _notify_now(*args, **kwargs): ) # First call + 2 retries = 3 calls - self.assertEquals(notify_now.call_count, 3) + self.assertEqual(notify_now.call_count, 3) @mock.patch.object(notify_tasks, 'notify_now') def test_notify_task_retry_fail(self, notify_now): @@ -98,4 +98,4 @@ def _notify_now(*args, **kwargs): ) # First call + 3 retries = 4 calls - self.assertEquals(notify_now.call_count, 4) + self.assertEqual(notify_now.call_count, 4) diff --git a/beproud/django/notify/tests/utils.py b/tests/utils.py similarity index 100% rename from beproud/django/notify/tests/utils.py rename to tests/utils.py diff --git a/tox.ini b/tox.ini index 4512907..09c6c79 100644 --- a/tox.ini +++ b/tox.ini @@ -1,30 +1,39 @@ # content of: tox.ini , put in same dir as setup.py [tox] -# celery5.2はPython3.7以降に対応しているため、Python3.6のテストではcelery 5.1までを使用する -envlist = py36-django{22,32}-celery{42,51},py39-django{22,32}-celery{51,52} +envlist = py{39,310,311}-dj{32,42}-celery{52,53},py312-dj-celery53 +skipsdist = True + +[pytest] +python_files = tests test_*.py *_tests.py +django_find_project = false +DJANGO_SETTINGS_MODULE = tests.settings [testenv] basepython = - py36: python3.6 py39: python3.9 - + py310: python3.10 + py311: python3.11 + py312: python3.12 deps = + pytest + pytest-django + pytest-pythonpath six - django22: Django~=2.2.12 - django32: Django~=3.2.1 - celery42: celery>=4.2,<4.3 - celery51: celery>=5.0,<5.2 + dj32: Django>=3.2,<4.0 + dj42: Django>=4.2,<5.0 celery52: celery>=5.2,<5.3 - -commands=python setup.py test + celery53: celery>=5.3,<5.4 +commands=pytest -Wa {posargs} # tox-gh-actionsパッケージの設定 [gh-actions] python = - 3.6: py36 3.9: py39 + 3.10: py310 + 3.11: py311 + 3.12: py312 [gh-actions:env] DJANGO = - 2.2: django22 3.2: django32 + 4.2: django42