Merge pull request #21194 from edx/feanil/remove_parsepy
DEPR-41 Remove parsepy
This commit is contained in:
@@ -7,7 +7,6 @@ from __future__ import absolute_import
|
||||
from config_models.admin import ConfigurationModelAdmin
|
||||
from django.contrib import admin
|
||||
|
||||
from contentstore.models import PushNotificationConfig, VideoUploadConfig
|
||||
from contentstore.models import VideoUploadConfig
|
||||
|
||||
admin.site.register(VideoUploadConfig, ConfigurationModelAdmin)
|
||||
admin.site.register(PushNotificationConfig, ConfigurationModelAdmin)
|
||||
|
||||
@@ -20,7 +20,6 @@ import re
|
||||
from django.http import HttpResponseBadRequest
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from cms.djangoapps.contentstore.push_notification import enqueue_push_course_update
|
||||
from openedx.core.lib.xblock_utils import get_course_update_items
|
||||
from xmodule.html_module import CourseInfoModule
|
||||
from xmodule.modulestore.django import modulestore
|
||||
@@ -49,7 +48,6 @@ def update_course_updates(location, update, passed_id=None, user=None):
|
||||
Either add or update the given course update.
|
||||
Add:
|
||||
If the passed_id is absent or None, the course update is added.
|
||||
If push_notification_selected is set in the update, a celery task for the push notification is created.
|
||||
Update:
|
||||
It will update it if it has a passed_id which has a valid value.
|
||||
Until updates have distinct values, the passed_id is the location url + an index into the html structure.
|
||||
@@ -79,7 +77,6 @@ def update_course_updates(location, update, passed_id=None, user=None):
|
||||
"status": CourseInfoModule.STATUS_VISIBLE
|
||||
}
|
||||
course_update_items.append(course_update_dict)
|
||||
enqueue_push_course_update(update, location.course_key)
|
||||
|
||||
# update db record
|
||||
save_course_update_items(location, course_updates, course_update_items, user)
|
||||
|
||||
@@ -23,11 +23,3 @@ class VideoUploadConfig(ConfigurationModel):
|
||||
def get_profile_whitelist(cls):
|
||||
"""Get the list of profiles to include in the encoding download"""
|
||||
return [profile for profile in cls.current().profile_whitelist.split(",") if profile]
|
||||
|
||||
|
||||
class PushNotificationConfig(ConfigurationModel):
|
||||
"""
|
||||
Configuration for mobile push notifications.
|
||||
|
||||
.. no_pii:
|
||||
"""
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
"""
|
||||
Helper methods for push notifications from Studio.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from logging import exception as log_exception
|
||||
from uuid import uuid4
|
||||
|
||||
import six
|
||||
from django.conf import settings
|
||||
from parse_rest.connection import register
|
||||
from parse_rest.core import ParseError
|
||||
from parse_rest.installation import Push
|
||||
from six import text_type
|
||||
|
||||
from contentstore.models import PushNotificationConfig
|
||||
from contentstore.tasks import push_course_update_task
|
||||
from xmodule.modulestore.django import modulestore
|
||||
|
||||
|
||||
def push_notification_enabled():
|
||||
"""
|
||||
Returns whether the push notification feature is enabled.
|
||||
"""
|
||||
return PushNotificationConfig.is_enabled()
|
||||
|
||||
|
||||
def enqueue_push_course_update(update, course_key):
|
||||
"""
|
||||
Enqueues a task for push notification for the given update for the given course if
|
||||
(1) the feature is enabled and
|
||||
(2) push_notification is selected for the update
|
||||
"""
|
||||
if push_notification_enabled() and update.get("push_notification_selected"):
|
||||
course = modulestore().get_course(course_key)
|
||||
if course:
|
||||
push_course_update_task.delay(
|
||||
six.text_type(course_key),
|
||||
course.clean_id(padding_char='_'),
|
||||
course.display_name
|
||||
)
|
||||
|
||||
|
||||
def send_push_course_update(course_key_string, course_subscription_id, course_display_name):
|
||||
"""
|
||||
Sends a push notification for a course update, given the course's subscription_id and display_name.
|
||||
"""
|
||||
if settings.PARSE_KEYS:
|
||||
try:
|
||||
register(
|
||||
settings.PARSE_KEYS["APPLICATION_ID"],
|
||||
settings.PARSE_KEYS["REST_API_KEY"],
|
||||
)
|
||||
push_payload = {
|
||||
"action": "course.announcement",
|
||||
"notification-id": six.text_type(uuid4()),
|
||||
|
||||
"course-id": course_key_string,
|
||||
"course-name": course_display_name,
|
||||
}
|
||||
push_channels = [course_subscription_id]
|
||||
|
||||
# Push to all Android devices
|
||||
Push.alert(
|
||||
data=push_payload,
|
||||
channels={"$in": push_channels},
|
||||
where={"deviceType": "android"},
|
||||
)
|
||||
|
||||
# Push to all iOS devices
|
||||
# With additional payload so that
|
||||
# 1. The push is displayed automatically
|
||||
# 2. The app gets it even in the background.
|
||||
# See http://stackoverflow.com/questions/19239737/silent-push-notification-in-ios-7-does-not-work
|
||||
push_payload.update({
|
||||
"alert": "",
|
||||
"content-available": 1
|
||||
})
|
||||
Push.alert(
|
||||
data=push_payload,
|
||||
channels={"$in": push_channels},
|
||||
where={"deviceType": "ios"},
|
||||
)
|
||||
|
||||
except ParseError as error:
|
||||
log_exception(text_type(error))
|
||||
@@ -555,9 +555,8 @@ def push_course_update_task(course_key_string, course_subscription_id, course_di
|
||||
"""
|
||||
Sends a push notification for a course update.
|
||||
"""
|
||||
# TODO Use edx-notifications library instead (MA-638).
|
||||
from .push_notification import send_push_course_update
|
||||
send_push_course_update(course_key_string, course_subscription_id, course_display_name)
|
||||
# TODO Delete once we've done a deploy where nothing is using this. DEPR-41
|
||||
pass
|
||||
|
||||
|
||||
class CourseExportTask(UserTask): # pylint: disable=abstract-method
|
||||
|
||||
@@ -8,7 +8,6 @@ import time
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
from contentstore.models import PushNotificationConfig
|
||||
from contentstore.tests.test_course_settings import CourseTestCase
|
||||
from contentstore.tests.utils import AjaxEnabledTestClient, parse_json, registration, user
|
||||
from ddt import data, ddt, unpack
|
||||
@@ -417,16 +416,3 @@ class CourseKeyVerificationTestCase(CourseTestCase):
|
||||
)
|
||||
resp = self.client.get_html(url)
|
||||
self.assertEqual(resp.status_code, status_code)
|
||||
|
||||
|
||||
class PushNotificationConfigTestCase(TestCase):
|
||||
"""
|
||||
Tests PushNotificationConfig.
|
||||
"""
|
||||
|
||||
def test_notifications_defaults(self):
|
||||
self.assertFalse(PushNotificationConfig.is_enabled())
|
||||
|
||||
def test_notifications_enabled(self):
|
||||
PushNotificationConfig(enabled=True).save()
|
||||
self.assertTrue(PushNotificationConfig.is_enabled())
|
||||
|
||||
@@ -39,7 +39,6 @@ from contentstore.course_group_config import (
|
||||
)
|
||||
from contentstore.course_info_model import delete_course_update, get_course_updates, update_course_updates
|
||||
from contentstore.courseware_index import CoursewareSearchIndexer, SearchIndexingError
|
||||
from contentstore.push_notification import push_notification_enabled
|
||||
from contentstore.tasks import rerun_course as rerun_course_task
|
||||
from contentstore.utils import (
|
||||
add_instructor,
|
||||
@@ -966,7 +965,6 @@ def course_info_handler(request, course_key_string):
|
||||
'updates_url': reverse_course_url('course_info_update_handler', course_key),
|
||||
'handouts_locator': course_key.make_usage_key('course_info', 'handouts'),
|
||||
'base_asset_url': StaticContent.get_base_url_path_for_course_assets(course_module.id),
|
||||
'push_notification_enabled': push_notification_enabled()
|
||||
}
|
||||
)
|
||||
else:
|
||||
|
||||
@@ -9,7 +9,6 @@ from django.test.utils import override_settings
|
||||
from mock import patch
|
||||
from opaque_keys.edx.keys import UsageKey
|
||||
|
||||
from contentstore.models import PushNotificationConfig
|
||||
from contentstore.tests.test_course_settings import CourseTestCase
|
||||
from contentstore.utils import reverse_course_url, reverse_usage_url
|
||||
from xmodule.modulestore.django import modulestore
|
||||
@@ -239,7 +238,7 @@ class CourseUpdateTest(CourseTestCase):
|
||||
payload = json.loads(resp.content)
|
||||
self.assertEqual(len(payload), 1)
|
||||
|
||||
def post_course_update(self, send_push_notification=False):
|
||||
def post_course_update(self):
|
||||
"""
|
||||
Posts an update to the course
|
||||
"""
|
||||
@@ -250,8 +249,6 @@ class CourseUpdateTest(CourseTestCase):
|
||||
|
||||
content = u"Sample update"
|
||||
payload = {'content': content, 'date': 'January 8, 2013'}
|
||||
if send_push_notification:
|
||||
payload['push_notification_selected'] = True
|
||||
resp = self.client.ajax_post(course_update_url, payload)
|
||||
|
||||
# check that response status is 200 not 400
|
||||
@@ -260,16 +257,12 @@ class CourseUpdateTest(CourseTestCase):
|
||||
payload = json.loads(resp.content)
|
||||
self.assertHTMLEqual(payload['content'], content)
|
||||
|
||||
@patch("contentstore.push_notification.send_push_course_update")
|
||||
def test_post_course_update(self, mock_push_update):
|
||||
def test_post_course_update(self):
|
||||
"""
|
||||
Test that a user can successfully post on course updates and handouts of a course
|
||||
"""
|
||||
self.post_course_update()
|
||||
|
||||
# check that push notifications are not sent
|
||||
self.assertFalse(mock_push_update.called)
|
||||
|
||||
updates_location = self.course.id.make_usage_key('course_info', 'updates')
|
||||
self.assertTrue(isinstance(updates_location, UsageKey))
|
||||
self.assertEqual(updates_location.block_id, u'updates')
|
||||
@@ -287,32 +280,3 @@ class CourseUpdateTest(CourseTestCase):
|
||||
|
||||
payload = json.loads(resp.content)
|
||||
self.assertHTMLEqual(payload['data'], content)
|
||||
|
||||
@patch("contentstore.push_notification.send_push_course_update")
|
||||
def test_notifications_enabled_but_not_requested(self, mock_push_update):
|
||||
PushNotificationConfig(enabled=True).save()
|
||||
self.post_course_update()
|
||||
self.assertFalse(mock_push_update.called)
|
||||
|
||||
@patch("contentstore.push_notification.send_push_course_update")
|
||||
def test_notifications_enabled_and_sent(self, mock_push_update):
|
||||
PushNotificationConfig(enabled=True).save()
|
||||
self.post_course_update(send_push_notification=True)
|
||||
self.assertTrue(mock_push_update.called)
|
||||
|
||||
@override_settings(PARSE_KEYS={"APPLICATION_ID": "TEST_APPLICATION_ID", "REST_API_KEY": "TEST_REST_API_KEY"})
|
||||
@patch("contentstore.push_notification.Push")
|
||||
def test_notifications_sent_to_parse(self, mock_parse_push):
|
||||
PushNotificationConfig(enabled=True).save()
|
||||
self.post_course_update(send_push_notification=True)
|
||||
self.assertEquals(mock_parse_push.alert.call_count, 2)
|
||||
|
||||
@override_settings(PARSE_KEYS={"APPLICATION_ID": "TEST_APPLICATION_ID", "REST_API_KEY": "TEST_REST_API_KEY"})
|
||||
@patch("contentstore.push_notification.log_exception")
|
||||
@patch("contentstore.push_notification.Push")
|
||||
def test_notifications_error_from_parse(self, mock_parse_push, mock_log_exception):
|
||||
PushNotificationConfig(enabled=True).save()
|
||||
from parse_rest.core import ParseError
|
||||
mock_parse_push.alert.side_effect = ParseError
|
||||
self.post_course_update(send_push_notification=True)
|
||||
self.assertTrue(mock_log_exception.called)
|
||||
|
||||
Reference in New Issue
Block a user