Exemple #1
0
def test_report_email(db):
    with session_scope():
        user_author, api_token_author = generate_user()
        user_reported, api_token_reported = generate_user()

        complaint = Complaint(author_user=user_author,
                              reported_user=user_reported,
                              reason=random_hex(64),
                              description=random_hex(256))

        with patch("couchers.email.queue_email") as mock:
            send_report_email(complaint)

        assert mock.call_count == 1

        (sender_name, sender_email, recipient, subject, plain,
         html), _ = mock.call_args
        assert recipient == "*****@*****.**"
        assert complaint.author_user.username in plain
        assert complaint.author_user.username in html
        assert complaint.reported_user.username in plain
        assert complaint.reported_user.username in html
        assert complaint.reason in plain
        assert complaint.reason in html
        assert complaint.description in plain
        assert complaint.description in html
        assert "report" in subject.lower()
Exemple #2
0
    def Report(self, request, context):
        if context.user_id == request.reported_user_id:
            context.abort(grpc.StatusCode.INVALID_ARGUMENT, errors.CANT_REPORT_SELF)

        with session_scope() as session:
            reported_user = session.query(User).filter(User.id == request.reported_user_id).one_or_none()

            if not reported_user:
                context.abort(grpc.StatusCode.NOT_FOUND, errors.USER_NOT_FOUND)

            complaint = Complaint(
                author_user_id=context.user_id,
                reported_user_id=request.reported_user_id,
                reason=request.reason,
                description=request.description,
            )

            session.add(complaint)

            # commit here so that send_report_email can lazy-load stuff it needs
            session.commit()

            send_report_email(complaint)

            return empty_pb2.Empty()
Exemple #3
0
def test_report_email(db):
    with session_scope(db):
        user_author, api_token_author = generate_user(db)
        user_reported, api_token_reported = generate_user(db)

        complaint = Complaint(author_user=user_author,
                              reported_user=user_reported,
                              reason=random_hex(64),
                              description=random_hex(256))

        message_id = random_hex(64)

        @create_autospec
        def mock_send_email(sender_name, sender_email, recipient, subject,
                            plain, html):
            assert recipient == "*****@*****.**"
            assert complaint.author_user.username in plain
            assert complaint.author_user.username in html
            assert complaint.reported_user.username in plain
            assert complaint.reported_user.username in html
            assert complaint.reason in plain
            assert complaint.reason in html
            assert complaint.description in plain
            assert complaint.description in html
            assert "report" in subject.lower()
            return message_id

        with patch("couchers.email.send_email", mock_send_email) as mock:
            send_report_email(complaint)

        assert mock.call_count == 1