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_new_parents(self, params, recip):
        context = {}
        for student_name, parent_name, role, group_name in params['scenario']:
            ts = factories.TextSignupFactory.create(teacher=recip,
                                                    family__name=parent_name,
                                                    family__role=role)

            ts.student = factories.RelationshipFactory.create(
                from_profile=ts.family, to_profile__name=student_name).student

            if group_name is not None:
                ts.group = factories.GroupFactory.create(name=group_name)
                context['%sUrl' % group_name] = reverse(
                    'group', kwargs={'group_id': ts.group_id})

            ts.save()

            context['%sUrl' % student_name] = reverse(
                'village', kwargs={'student_id': ts.student_id})

            record.new_parent(recip, ts)

        assert base.send(recip.id)
        self.assert_multi_email(params['subject'], params['html'],
                                params['text'], context)
Exemplo n.º 3
0
    def test_no_requested(self, params, recip):
        """If no (non-post) requested notifications, container not shown."""
        rel = factories.RelationshipFactory.create(
            from_profile=recip, to_profile__name='A Student')
        signup = factories.TextSignupFactory.create(student=rel.student)

        record.new_parent(recip, signup)

        assert base.send(recip.id)
        assert len(mail.outbox) == 1
        html_body = mail.outbox[0].alternatives[0][0]
        assert 'class="requested"' not in html_body
        assert 'class="nonrequested"' in html_body
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_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.º 6
0
    def test_no_requested(self, params, recip):
        """If no (non-post) requested notifications, container not shown."""
        rel = factories.RelationshipFactory.create(
            from_profile=recip, to_profile__name='A Student')
        signup = factories.TextSignupFactory.create(
            student=rel.student)

        record.new_parent(recip, signup)

        assert base.send(recip.id)
        assert len(mail.outbox) == 1
        html_body = mail.outbox[0].alternatives[0][0]
        assert 'class="requested"' not in html_body
        assert 'class="nonrequested"' in html_body
Exemplo n.º 7
0
    def test_bulk_posts(self, params, recip):
        context = {}
        name_map = {}
        now = datetime(2012, 1, 15, tzinfo=timezone.utc)
        for teacher_name, my_sts, other_sts, msg, ago in params['scenario']:
            if teacher_name not in name_map:
                name_map[teacher_name] = factories.ProfileFactory.create(
                    school_staff=True, name=teacher_name, role="Teacher")
            teacher = name_map[teacher_name]
            all_students = []
            for st_name in my_sts:
                if st_name not in name_map:
                    name_map[st_name] = factories.RelationshipFactory.create(
                        to_profile__name=st_name, from_profile=recip).student
                all_students.append(name_map[st_name])
            for st_name in other_sts:
                if st_name not in name_map:
                    name_map[st_name] = factories.ProfileFactory.create(
                        name=st_name)
                all_students.append(name_map[st_name])
            group = factories.GroupFactory.create(owner=teacher)
            group.students.add(*all_students)
            html_text = "html: %s" % msg
            timestamp = now - ago
            bulk_post = factories.BulkPostFactory.create(
                author=teacher,
                group=group,
                original_text=msg,
                html_text=html_text,
                timestamp=timestamp,
            )
            for student in all_students:
                context['%sUrl' % student.name] = reverse(
                    'village', kwargs={'student_id': student.id})
                factories.PostFactory.create(
                    author=teacher,
                    student=student,
                    from_bulk=bulk_post,
                    original_text=msg,
                    html_text=html_text,
                    timestamp=timestamp,
                )
            record.bulk_post(recip, bulk_post)

        assert base.send(recip.id)
        self.assert_multi_email(params['subject'], params['html'],
                                params['text'], context)
Exemplo n.º 8
0
    def test_bulk_posts(self, params, recip):
        context = {}
        name_map = {}
        now = datetime(2012, 1, 15, tzinfo=timezone.utc)
        for teacher_name, my_sts, other_sts, msg, ago in params['scenario']:
            if teacher_name not in name_map:
                name_map[teacher_name] = factories.ProfileFactory.create(
                    school_staff=True, name=teacher_name, role="Teacher")
            teacher = name_map[teacher_name]
            all_students = []
            for st_name in my_sts:
                if st_name not in name_map:
                    name_map[st_name] = factories.RelationshipFactory.create(
                        to_profile__name=st_name, from_profile=recip).student
                all_students.append(name_map[st_name])
            for st_name in other_sts:
                if st_name not in name_map:
                    name_map[st_name] = factories.ProfileFactory.create(
                        name=st_name)
                all_students.append(name_map[st_name])
            group = factories.GroupFactory.create(owner=teacher)
            group.students.add(*all_students)
            html_text = "html: %s" % msg
            timestamp = now - ago
            bulk_post = factories.BulkPostFactory.create(
                author=teacher,
                group=group,
                original_text=msg,
                html_text=html_text,
                timestamp=timestamp,
                )
            for student in all_students:
                context['%sUrl' % student.name] = reverse(
                    'village', kwargs={'student_id': student.id})
                factories.PostFactory.create(
                    author=teacher,
                    student=student,
                    from_bulk=bulk_post,
                    original_text=msg,
                    html_text=html_text,
                    timestamp=timestamp,
                    )
            record.bulk_post(recip, bulk_post)

        assert base.send(recip.id)
        self.assert_multi_email(
            params['subject'], params['html'], params['text'], context)
Exemplo n.º 9
0
    def test_new_teachers(self, params, recip):
        """Test subject/body for new-teacher notifications."""
        student_names, teacher_names = params['scenario']
        teacher_profiles = []
        context = {}
        for teacher_name in teacher_names:
            teacher_profiles.append(
                factories.ProfileFactory.create(name=teacher_name))
        for student_name in student_names:
            rel = factories.RelationshipFactory.create(
                from_profile=recip, to_profile__name=student_name)
            context[student_name + 'Url'] = reverse(
                'village', kwargs={'student_id': rel.to_profile_id})
            for teacher in teacher_profiles:
                factories.RelationshipFactory.create(
                    from_profile=teacher, to_profile=rel.student)
                record.new_teacher(recip, teacher, rel.student)

        assert base.send(recip.id)
        self.assert_multi_email(
            params['subject'], params['html'], params['text'], context)
Exemplo n.º 10
0
    def test_new_teachers(self, params, recip):
        """Test subject/body for new-teacher notifications."""
        student_names, teacher_names = params['scenario']
        teacher_profiles = []
        context = {}
        for teacher_name in teacher_names:
            teacher_profiles.append(
                factories.ProfileFactory.create(name=teacher_name))
        for student_name in student_names:
            rel = factories.RelationshipFactory.create(
                from_profile=recip, to_profile__name=student_name)
            context[student_name + 'Url'] = reverse(
                'village', kwargs={'student_id': rel.to_profile_id})
            for teacher in teacher_profiles:
                factories.RelationshipFactory.create(from_profile=teacher,
                                                     to_profile=rel.student)
                record.new_teacher(recip, teacher, rel.student)

        assert base.send(recip.id)
        self.assert_multi_email(params['subject'], params['html'],
                                params['text'], context)
Exemplo n.º 11
0
    def test_footer(self, recip):
        """Footer links to profile."""
        rel = factories.RelationshipFactory.create(
            from_profile=recip, to_profile__name='A Student')
        other_rel = factories.RelationshipFactory.create(
            to_profile=rel.student)

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

        assert base.send(recip.id)
        self.assert_multi_email(
            html_snippets=[
                '<p>Don\'t want email notifications from Portfoliyo? '
                '<a href="%(url)s">Edit your profile</a>.</p>'
                ],
            text_snippets=[
                "----\n"
                "Don't want email notifications from Portfoliyo? "
                "Edit your profile: %(base)s%(url)s"
                ],
            snippet_context={'url': reverse('edit_profile')},
            )
Exemplo n.º 12
0
    def test_footer(self, recip):
        """Footer links to profile."""
        rel = factories.RelationshipFactory.create(
            from_profile=recip, to_profile__name='A Student')
        other_rel = factories.RelationshipFactory.create(
            to_profile=rel.student)

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

        assert base.send(recip.id)
        self.assert_multi_email(
            html_snippets=[
                '<p>Don\'t want email notifications from Portfoliyo? '
                '<a href="%(url)s">Edit your profile</a>.</p>'
            ],
            text_snippets=[
                "----\n"
                "Don't want email notifications from Portfoliyo? "
                "Edit your profile: %(base)s%(url)s"
            ],
            snippet_context={'url': reverse('edit_profile')},
        )
Exemplo n.º 13
0
    def test_posts(self, params, recip):
        context = {}
        name_map = {}
        rels = {}
        now = datetime(2012, 1, 15, tzinfo=timezone.utc)
        for st_name, author_name, role, text, ago, new in params['scenario']:
            if st_name not in name_map:
                name_map[st_name] = factories.RelationshipFactory.create(
                    from_profile=recip, to_profile__name=st_name).student
                context['%sUrl' % st_name] = reverse(
                    'village', kwargs={'student_id': name_map[st_name].id})
            if author_name not in name_map:
                name_map[author_name] = factories.ProfileFactory.create(
                    name=author_name, school_staff=False)
            student = name_map[st_name]
            author = name_map[author_name]
            if (student, author) not in rels:
                rel = factories.RelationshipFactory.create(from_profile=author,
                                                           to_profile=student,
                                                           description=role)
                rels[(student, author)] = rel
            else:
                rel = rels[(student, author)]
            post = factories.PostFactory.create(
                author=author,
                student=student,
                relationship=rel,
                original_text=text,
                html_text='html: %s' % text,
                timestamp=now - ago,
            )
            if new:
                record.post(recip, post)

        assert base.send(recip.id)
        self.assert_multi_email(params['subject'], params['html'],
                                params['text'], context)
Exemplo n.º 14
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.º 15
0
    def test_new_parents(self, params, recip):
        context = {}
        for student_name, parent_name, role, group_name in params['scenario']:
            ts = factories.TextSignupFactory.create(
                teacher=recip, family__name=parent_name, family__role=role)

            ts.student = factories.RelationshipFactory.create(
                from_profile=ts.family, to_profile__name=student_name).student

            if group_name is not None:
                ts.group = factories.GroupFactory.create(name=group_name)
                context['%sUrl' % group_name] = reverse(
                    'group', kwargs={'group_id': ts.group_id})

            ts.save()

            context['%sUrl' % student_name] = reverse(
                'village', kwargs={'student_id': ts.student_id})

            record.new_parent(recip, ts)

        assert base.send(recip.id)
        self.assert_multi_email(
            params['subject'], params['html'], params['text'], context)
Exemplo n.º 16
0
    def test_posts(self, params, recip):
        context = {}
        name_map = {}
        rels = {}
        now = datetime(2012, 1, 15, tzinfo=timezone.utc)
        for st_name, author_name, role, text, ago, new in params['scenario']:
            if st_name not in name_map:
                name_map[st_name] = factories.RelationshipFactory.create(
                    from_profile=recip, to_profile__name=st_name).student
                context['%sUrl' % st_name] = reverse(
                    'village', kwargs={'student_id': name_map[st_name].id})
            if author_name not in name_map:
                name_map[author_name] = factories.ProfileFactory.create(
                    name=author_name, school_staff=False)
            student = name_map[st_name]
            author = name_map[author_name]
            if (student, author) not in rels:
                rel = factories.RelationshipFactory.create(
                    from_profile=author, to_profile=student, description=role)
                rels[(student, author)] = rel
            else:
                rel = rels[(student, author)]
            post = factories.PostFactory.create(
                author=author,
                student=student,
                relationship=rel,
                original_text=text,
                html_text='html: %s' % text,
                timestamp=now - ago,
                )
            if new:
                record.post(recip, post)

        assert base.send(recip.id)
        self.assert_multi_email(
            params['subject'], params['html'], params['text'], context)
Exemplo n.º 17
0
 def test_send_only_if_notifications(self, db, redis):
     """If there are no notifications, don't try to send an email."""
     p = factories.ProfileFactory.create(user__email='*****@*****.**',
                                         user__is_active=True)
     assert not base.send(p.id)
Exemplo n.º 18
0
 def test_send_only_if_active(self, db):
     """If user is inactive, notifications not queried or sent."""
     p = factories.ProfileFactory.create(user__email='*****@*****.**',
                                         user__is_active=False)
     assert not base.send(p.id)
Exemplo n.º 19
0
 def test_send_only_if_email(self, db):
     """If user has no email, notifications not queried or sent."""
     p = factories.ProfileFactory.create(user__email=None)
     assert not base.send(p.id)
Exemplo n.º 20
0
 def test_send_only_if_email(self, db):
     """If user has no email, notifications not queried or sent."""
     p = factories.ProfileFactory.create(user__email=None)
     assert not base.send(p.id)
Exemplo n.º 21
0
 def test_send_only_if_notifications(self, db, redis):
     """If there are no notifications, don't try to send an email."""
     p = factories.ProfileFactory.create(
         user__email='*****@*****.**', user__is_active=True)
     assert not base.send(p.id)
Exemplo n.º 22
0
 def test_send_only_if_active(self, db):
     """If user is inactive, notifications not queried or sent."""
     p = factories.ProfileFactory.create(
         user__email='*****@*****.**', user__is_active=False)
     assert not base.send(p.id)