Exemplo n.º 1
0
    def test_added_to_village(self, params, recip):
        """Test subject/body for added-to-village notifications."""
        name_map = {}
        context = {}
        for teacher_name, student_name in params['scenario']:
            if teacher_name not in name_map:
                name_map[teacher_name] = factories.ProfileFactory.create(
                    name=teacher_name, school_staff=True)
            if student_name not in name_map:
                name_map[student_name] = factories.ProfileFactory.create(
                    name=student_name, school_staff=True)
                context[student_name + 'Url'] = reverse(
                    'village',
                    kwargs={'student_id': name_map[student_name].id})
                factories.RelationshipFactory.create(
                    from_profile=recip, to_profile=name_map[student_name])
            teacher = name_map[teacher_name]
            student = name_map[student_name]
            factories.RelationshipFactory.create(from_profile=teacher,
                                                 to_profile=student)
            record.added_to_village(recip, teacher, student)

        assert base.send(recip.id)
        self.assert_multi_email(params['subject'], params['html'],
                                params['text'], context)
Exemplo n.º 2
0
def test_added_to_village(mock_record, requested):
    mock_profile = mock.Mock(id=2, notify_added_to_village=requested)
    mock_teacher = mock.Mock(id=3)
    mock_student = mock.Mock(id=4)
    record.added_to_village(mock_profile, mock_teacher, mock_student)

    mock_record.assert_called_with(
        mock_profile,
        'added to village',
        triggering=requested,
        data={'added-by-id': 3, 'student-id': 4},
        )
Exemplo n.º 3
0
    def test_generic_subject_single_student(self, recip):
        """Generic subject if multiple notification types, single student."""
        rel = factories.RelationshipFactory.create(
            from_profile=recip, to_profile__name='A Student')
        other_rel = factories.RelationshipFactory.create(
            to_profile=rel.student)

        record.added_to_village(recip, other_rel.elder, rel.student)
        record.new_teacher(recip, other_rel.elder, rel.student)

        assert base.send(recip.id)
        assert len(mail.outbox) == 1
        assert mail.outbox[0].subject == "New activity in A Student's village."
Exemplo n.º 4
0
    def test_generic_subject_multiple_students(self, recip):
        """Generic subject if multiple notification types, multiple students."""
        rel = factories.RelationshipFactory.create(from_profile=recip)
        other_rel = factories.RelationshipFactory.create()
        factories.RelationshipFactory.create(
            from_profile=recip, to_profile=other_rel.student)

        record.added_to_village(recip, other_rel.elder, other_rel.student)
        record.new_teacher(recip, other_rel.elder, rel.student)

        assert base.send(recip.id)
        assert len(mail.outbox) == 1
        assert mail.outbox[0].subject == "New activity in two of your villages."
Exemplo n.º 5
0
def test_added_to_village(mock_record, requested):
    mock_profile = mock.Mock(id=2, notify_added_to_village=requested)
    mock_teacher = mock.Mock(id=3)
    mock_student = mock.Mock(id=4)
    record.added_to_village(mock_profile, mock_teacher, mock_student)

    mock_record.assert_called_with(
        mock_profile,
        'added to village',
        triggering=requested,
        data={
            'added-by-id': 3,
            'student-id': 4
        },
    )
Exemplo n.º 6
0
    def test_added_to_village(self, params, recip):
        """Test subject/body for added-to-village notifications."""
        name_map = {}
        context = {}
        for teacher_name, student_name in params['scenario']:
            if teacher_name not in name_map:
                name_map[teacher_name] = factories.ProfileFactory.create(
                    name=teacher_name, school_staff=True)
            if student_name not in name_map:
                name_map[student_name] = factories.ProfileFactory.create(
                    name=student_name, school_staff=True)
                context[student_name + 'Url'] = reverse(
                    'village', kwargs={'student_id': name_map[student_name].id})
                factories.RelationshipFactory.create(
                    from_profile=recip, to_profile=name_map[student_name])
            teacher = name_map[teacher_name]
            student = name_map[student_name]
            factories.RelationshipFactory.create(
                from_profile=teacher, to_profile=student)
            record.added_to_village(recip, teacher, student)

        assert base.send(recip.id)
        self.assert_multi_email(
            params['subject'], params['html'], params['text'], context)