def send_message(students, message):
    """
    Loop over the list of student ids, and send a message to every student in the list.

    :param students: List of student ids.
    :type students: list(str)
    :param message: The message that needs to be send.
    :type message: str
    """
    students = set(students)
    moodle_api.send_bulk_messages(students, message)
Example #2
0
def send_update_notification(course, message):
    """
    Send a message to all admin users linked to the course.

    :param course: Course in which a module has changed.
    :type course: Course
    :param message: The message that has to be sent.
    :type message: str
    """
    user_list = []
    for user in course.user_set.all():
        user_list.append(user.moodle_id)
    if len(user_list) > 0:
        moodle_api.send_bulk_messages(user_list, message)
Example #3
0
    def test_send_bulk_message_correct(self, a):
        moodle_api.send_bulk_messages([2, 4, 5], 'TestMessage')

        a.assert_called_with(
            'DUMMY_MOODLE_URL/core_message_send_instant_messages',
            headers={
                'Content-Type': 'application/json',
                'Accept': 'application/json',
                'Authorization': 'DUMMY_MOODLE_TOKEN'
            },
            json={
                'messages': [{
                    'touserid': 2,
                    'text': 'TestMessage'
                }, {
                    'touserid': 4,
                    'text': 'TestMessage'
                }, {
                    'touserid': 5,
                    'text': 'TestMessage'
                }]
            })
Example #4
0
 def test_send_bulk_messages_incorrect(self, a):
     with self.assertRaises(Exception):
         moodle_api.send_bulk_messages(4, 'TestMessage')