summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--online_test/celery.py6
-rw-r--r--online_test/settings.py2
-rw-r--r--requirements/requirements-common.txt5
-rw-r--r--yaksh/test_views.py17
4 files changed, 28 insertions, 2 deletions
diff --git a/online_test/celery.py b/online_test/celery.py
index 582f8a1..ac6e395 100644
--- a/online_test/celery.py
+++ b/online_test/celery.py
@@ -17,3 +17,9 @@ app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
+
+@app.task(name='celery.ping')
+def ping():
+ # type: () -> str
+ """Simple task that just returns 'pong'."""
+ return 'pong' \ No newline at end of file
diff --git a/online_test/settings.py b/online_test/settings.py
index aa373c4..ad52804 100644
--- a/online_test/settings.py
+++ b/online_test/settings.py
@@ -46,6 +46,7 @@ INSTALLED_APPS = (
'social_django',
'grades',
'django_celery_beat',
+ 'django_celery_results',
'notifications_plugin',
)
@@ -220,3 +221,4 @@ CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TIMEZONE = 'Asia/Kolkata'
CELERY_BROKER_URL = 'redis://localhost'
+CELERY_RESULT_BACKEND = 'django-db'
diff --git a/requirements/requirements-common.txt b/requirements/requirements-common.txt
index d1fed93..de9fe96 100644
--- a/requirements/requirements-common.txt
+++ b/requirements/requirements-common.txt
@@ -10,3 +10,8 @@ coverage
ruamel.yaml==0.15.23
markdown==2.6.9
pygments==2.2.0
+celery==4.4.2
+redis==3.4.1
+notifications-plugin==0.1.1
+django-celery-beat==2.0.0
+django-celery-results==1.2.1
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index b137435..131aeb9 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -2,6 +2,7 @@ from datetime import datetime
import pytz
import os
import json
+import time
try:
from StringIO import StringIO as string_io
except ImportError:
@@ -21,6 +22,8 @@ from django.conf import settings
from django.core.files.uploadedfile import SimpleUploadedFile
from django.core.files import File
from django.contrib.messages import get_messages
+from celery.contrib.testing.worker import start_worker
+from django.test import SimpleTestCase
from yaksh.models import (
@@ -31,6 +34,7 @@ from yaksh.models import (
)
from yaksh.views import add_as_moderator
from yaksh.decorators import user_has_profile
+from online_test.celery import app
from notifications_plugin.models import Notification
@@ -3593,11 +3597,13 @@ class TestSelfEnroll(TestCase):
self.assertRedirects(response, '/exam/manage/')
-class TestGrader(TestCase):
+class TestGrader(SimpleTestCase):
+ allow_database_queries = True
+
def setUp(self):
self.client = Client()
- self.mod_group = Group.objects.create(name='moderator')
+ self.mod_group, created = Group.objects.get_or_create(name='moderator')
# Create Moderator with profile
self.user1_plaintext_pass = 'demo1'
@@ -3677,6 +3683,9 @@ class TestGrader(TestCase):
end_time=timezone.now()+timezone.timedelta(minutes=20),
)
+ self.celery_worker = start_worker(app)
+ self.celery_worker.__enter__()
+
def tearDown(self):
User.objects.all().delete()
Course.objects.all().delete()
@@ -3685,6 +3694,7 @@ class TestGrader(TestCase):
QuestionPaper.objects.all().delete()
AnswerPaper.objects.all().delete()
self.mod_group.delete()
+ self.celery_worker.__exit__(None, None, None)
def test_regrade_denies_anonymous(self):
# Given
@@ -3774,6 +3784,9 @@ class TestGrader(TestCase):
messages = [m.message for m in get_messages(response.wsgi_request)]
self.assertEqual(response.status_code, 200)
self.assertIn("demo quiz is submitted for re-evaluation", messages[0])
+ self.assertEqual(Notification.objects.get_receiver_notifications(
+ self.user1.id
+ ).count(), 3)
def test_regrade_denies_moderator_not_in_course(self):
# Given