diff --git a/.github/workflows/plugin.yml b/.github/workflows/plugin.yml index 8e0b29e..d702cf6 100644 --- a/.github/workflows/plugin.yml +++ b/.github/workflows/plugin.yml @@ -36,6 +36,15 @@ jobs: ports: - 3306/tcp options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + redis: + image: redis + ports: + - 6379/tcp + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 strategy: matrix: @@ -62,6 +71,11 @@ jobs: python setup.py develop cd ../modoboa-amavis python setup.py develop + echo "Testing redis connection" + redis-cli -h $REDIS_HOST -p $REDIS_PORT ping + env: + REDIS_HOST: localhost + REDIS_PORT: ${{ job.services.redis.ports[6379] }} - name: Install postgres requirements if: ${{ matrix.database == 'postgres' }} run: | @@ -85,7 +99,8 @@ jobs: MYSQL_HOST: 127.0.0.1 MYSQL_PORT: ${{ job.services.mysql.ports[3306] }} # get randomly assigned published port MYSQL_USER: root - + REDIS_HOST: localhost + REDIS_PORT: ${{ job.services.redis.ports[6379] }} - name: Test with pytest and coverage if: ${{ matrix.python-version == '3.10' && matrix.database == 'postgres' }} run: | @@ -100,6 +115,8 @@ jobs: MYSQL_HOST: 127.0.0.1 MYSQL_PORT: ${{ job.services.mysql.ports[3306] }} # get randomly assigned published port MYSQL_USER: root + REDIS_HOST: localhost + REDIS_PORT: ${{ job.services.redis.ports[6379] }} - name: Upload coverage result if: ${{ matrix.python-version == '3.10' && matrix.database == 'postgres' }} uses: actions/upload-artifact@v3 diff --git a/modoboa_amavis/tests/test_views.py b/modoboa_amavis/tests/test_views.py index 3350fa1..a73e616 100644 --- a/modoboa_amavis/tests/test_views.py +++ b/modoboa_amavis/tests/test_views.py @@ -5,11 +5,15 @@ import os from unittest import mock +from rq import SimpleWorker + from django.core import mail from django.core.management import call_command from django.test import override_settings from django.urls import reverse +import django_rq + from modoboa.admin import factories as admin_factories from modoboa.core import models as core_models from modoboa.lib.tests import ModoTestCase @@ -226,7 +230,10 @@ def _test_mark_message(self, action, status): data = {"rcpt": smart_str(self.msgrcpt.rid.email)} response = self.ajax_post(url, data) self.assertEqual( - response["message"], "1 message processed successfully") + response["message"], "Your request is being processed...") + queue = django_rq.get_queue("default") + worker = SimpleWorker([queue], connection=queue.connection) + worker.work(burst=True) self.msgrcpt.refresh_from_db() self.assertEqual(self.msgrcpt.rs, status) @@ -235,7 +242,8 @@ def _test_mark_message(self, action, status): self.set_global_parameter("sa_is_local", False) response = self.ajax_post(url, data) self.assertEqual( - response["message"], "1 message processed successfully") + response["message"], "Your request is being processed...") + worker.work(burst=True) self.msgrcpt.refresh_from_db() self.assertEqual(self.msgrcpt.rs, status) @@ -289,7 +297,7 @@ def test_manual_learning_as_user(self): self._test_mark_message("ham", "H") @mock.patch("socket.socket") - def test_process(self, mock_socket): + def test_process_release(self, mock_socket): """Test process mode (bulk).""" # Initiate session url = reverse("modoboa_amavis:_mail_list") @@ -305,8 +313,9 @@ def test_process(self, mock_socket): smart_str(msgrcpt.rid.email), smart_str(msgrcpt.mail.mail_id)), ] - mock_socket.return_value.recv.side_effect = ( - b"250 1234 Ok\r\n", b"250 1234 Ok\r\n") + mock_socket.return_value.recv.side_effect = [ + b"250 1234 Ok\r\n", b"250 1234 Ok\r\n" + ] data = { "action": "release", "rcpt": smart_str(self.msgrcpt.rid.email), @@ -317,15 +326,36 @@ def test_process(self, mock_socket): self.assertEqual( response["message"], "2 messages released successfully") + def test_process_all(self): + """Test process mode (bulk).""" + # Initiate session + url = reverse("modoboa_amavis:_mail_list") + response = self.ajax_get(url) + + msgrcpt = factories.create_spam("user@test.com") + url = reverse("modoboa_amavis:mail_process") + selection = [ + "{} {}".format( + smart_str(self.msgrcpt.rid.email), + smart_str(self.msgrcpt.mail.mail_id)), + "{} {}".format( + smart_str(msgrcpt.rid.email), + smart_str(msgrcpt.mail.mail_id)), + ] + data = { + "rcpt": smart_str(self.msgrcpt.rid.email), + "selection": ",".join(selection) + } + data["action"] = "mark_as_spam" response = self.ajax_post(url, data) self.assertEqual( - response["message"], "2 messages processed successfully") + response["message"], "Your request is being processed...") data["action"] = "mark_as_ham" response = self.ajax_post(url, data) self.assertEqual( - response["message"], "2 messages processed successfully") + response["message"], "Your request is being processed...") data = { "action": "delete",