Exemple #1
0
    def test_notify(self, sendMock):
        sendMock.return_value = 'taco'
        self.obj = FeedbackFromMetareviewMessenger(self.unit, self.studentRepo,
                                                   self.contentRepo,
                                                   self.statusRepo)

        # Call
        result = self.obj.notify([self.review_assign], send=True)

        # Check
        # Intermediate things were called
        self.assertTrue(self.contentRepo.get_formatted_work_by.called,
                        "Content repo method called")
        self.assertTrue(self.studentRepo.get_student.called,
                        "Student repo method called")
        # Returned expected stuff
        self.assertTrue(len(result) == 1, "Something was returned")

        # Check that the sender was given the expected content
        sendMock.assert_called()
        kwargs = sendMock.call_args[1]
        self.assertEqual(kwargs['student_id'], self.reviewer.id,
                         "Sent to reviewer")
        self.assertEqual(
            kwargs['subject'],
            FeedbackFromMetareviewMessenger.subject.format(
                self.unit.unit_number),
            "Sent with expected subject line (This is different from the tests of its siblings"
        )
        d = {
            'intro': FeedbackFromMetareviewMessenger.intro,
            # the person who did the review is getting feedback from the author
            'name': get_first_name(self.reviewer),

            # Formatted work for sending
            'responses': self.work,

            # Add any materials from me
            'other': "",
        }
        # d = self.obj._make_template_input( self.work, None, self.reviewer )
        b = METAREVIEW_CONTENT_TEMPLATE.format(**d)
        self.assertEqual(kwargs['body'], b, "Sent with expected body")

        # Super important: makes sure going to right person
        # This is for the metareview, so the receipient should be the REVIEWER
        self.studentRepo.get_student.assert_called_with(self.reviewer.id)

        # Check that status repo called
        self.statusRepo.record.assert_called()
        self.statusRepo.record.assert_called_with(self.reviewer.id)
Exemple #2
0
def metareview_send_message_to_reviewers(review_assignments,
                                         studentRepo,
                                         contentRepo,
                                         activity,
                                         send=False):
    # # Load list of ReviewAssociation objects representing who reviews whom
    # review_assigns = associationRepo.get_associations(activity_inviting_to_complete)
    # print("loaded {} student reviewer assignments".format(len(review_assigns)))
    log_file = "{}/{}-metareview-message-log.txt".format(
        env.LOG_FOLDER, getDateForMakingFileName())
    with open(log_file, 'a') as f:
        for rev in review_assignments:
            try:
                assessee = studentRepo.get_student_record(rev.assessee_id)

                content = contentRepo.get_formatted_work_by(rev.assessor_id)

                d = {
                    'intro': activity.email_intro,
                    'name': get_first_name(assessee),

                    # Formatted work for sending
                    'responses': content,

                    # Add any materials from me
                    'other': '',

                    # Add code and link to do reviewing unit
                    'review_assignment_name': activity.name,
                    'access_code': activity.access_code,
                    'review_url': activity.html_url,
                    'due_date': activity.string_due_date
                }

                message = make_notice(d)

                f.write("\n=========\n {}".format(message))

                if send:
                    subject = activity.email_subject
                    m = send_message_to_student(student_id=rev.assessee_id,
                                                subject=subject,
                                                body=message)
                    print(m)
                else:
                    print(message)
            except Exception as e:
                # todo Replace with raise LookupError and hook handler
                f.write("\n=========\n {}".format(e))
                print(e)
Exemple #3
0
def review_send_message_to_reviewers(review_assignments,
                                     studentRepo,
                                     contentRepo,
                                     activity,
                                     send=False):
    # THIS IS UNUSABLE. MUST FIX ERROR

    # # Load list of ReviewAssociation objects representing who reviews whom
    # review_assigns = associationRepo.get_associations(activity_inviting_to_complete)
    # print("loaded {} student reviewer assignments".format(len(review_assigns)))

    for rev in review_assignments:
        try:
            assessor = studentRepo.get_student_record(rev.assessor_id)

            content = contentRepo.get_formatted_work(rev.assessee_id)

            d = {
                'intro': activity.email_intro,
                'name': get_first_name(assessor),

                # Formatted work for sending
                'responses': content,

                # Add any materials from me
                'other': '',

                # Add code and link to do reviewing unit
                'review_assignment_name': activity.name,
                'access_code': activity.access_code,
                'review_url': activity.html_url,
                'due_date': activity.string_due_date
            }

            message = make_notice(d)

            if send:
                subject = activity.email_subject
                # fix this you f*****g idiot
                m = send_message_to_student(student_id=rev.assessor_id,
                                            subject=subject,
                                            body=message)
                print(m)
            else:
                print(message)
        except Exception as e:
            # todo Replace with raise LookupError and hook handler
            print(e)
Exemple #4
0
    def test_prepare_message(self):
        obj = FeedbackFromMetareviewMessenger(self.unit, self.studentRepo,
                                              self.contentRepo,
                                              self.statusRepo)

        # call
        message_data = obj.prepare_message(self.review_assign)

        # check
        self.assertEqual(obj.message_template, METAREVIEW_CONTENT_TEMPLATE,
                         "Working off expected template")
        self.assertEqual(
            message_data['student_id'], self.reviewer.id,
            "Message is going to reviewer (it contains the feedback from the original author)"
        )
        self.assertEqual(
            message_data['subject'],
            FeedbackFromMetareviewMessenger.subject.format(
                self.unit.unit_number),
            "Sent with expected subject line (This is different from the tests of its siblings"
        )

        self.assertTrue(len(message_data['body']) > 0)

        d = {
            'intro': FeedbackFromMetareviewMessenger.intro,
            # the person who did the review is getting feedback from the author
            'name': get_first_name(self.reviewer),

            # Formatted work for sending
            'responses': self.work,

            # Add any materials from me
            'other': "",
        }
        expected_content = METAREVIEW_CONTENT_TEMPLATE.format(**d)

        self.assertEqual(expected_content, message_data['body'],
                         "Expected message body")

        # Super important: makes sure going to right person
        # This is for the metareview, so the receipient should be the REVIEWER
        self.studentRepo.get_student.assert_called_with(self.reviewer.id)
Exemple #5
0
    def prepare_message(self, review_assignment, other=None):
        """This looks up the appropriate data for a review
        unit and returns what will be the message body
        """
        try:
            # We are going to send the metareview feedback
            # created by the assessee (original author) to the student who did
            # the assessing in the peer review stage
            receiving_student = self.student_repository.get_student(
                review_assignment.assessor_id)

            # The assessee (original author) did the work that we want to send
            # to the assessor (peer reviewer)
            content = self.content_repository.get_formatted_work_by(
                review_assignment.assessee_id)

            d = {
                'intro': self.intro,
                'name': get_first_name(receiving_student),

                # Formatted work for sending
                'responses': content,

                # Add any materials from me
                'other': "",
            }

            body = self.message_template.format(**d)

            # can't use the usual self.make_message_data because won't have all the expected fields
            return {
                'student_id': receiving_student.id,
                'subject': self.email_subject,
                'body': body
            }

        except Exception as e:
            # todo exception handling
            print(e)
            raise MessageDataCreationError(review_assignment)
Exemple #6
0
    def _make_template_input(self, content, other, receiving_student):
        """Creates the dictionary that will be used to format the message template
        and create the message content
        This is abstracted out to make testing easier
        """

        d = {
            'intro': self.activity_inviting_to_complete.email_intro,
            'name': get_first_name(receiving_student),

            # Formatted work for sending
            'responses': content,

            # Add any materials from me
            'other': other if other is not None else "",

            # Add code and link to do reviewing unit
            'review_assignment_name': self.activity_inviting_to_complete.name,
            'access_code_message': self._make_access_code_message(),
            'review_url': self.activity_inviting_to_complete.html_url,
            'due_date': self.activity_inviting_to_complete.string_due_date
        }
        return d