'Verify revision approval with proper notifications.'

@mock.patch.object(send_reviewed_notification, 'delay')
@mock.patch.object(Site.objects, 'get_current')
@mock.patch.object(settings._wrapped, 'TIDINGS_CONFIRM_ANONYMOUS_WATCHES', False)
def test_approve_revision(self, get_current, reviewed_delay):

    get_current.return_value.domain = 'testserver'
    watch = ApproveRevisionInLocaleEvent.notify('joe@example.com', locale='en-US')
    watch.activate().save()
    ApproveRevisionInLocaleEvent.notify(self.user, locale='en-US').activate().save()
    significance = SIGNIFICANCES[0][0]
    response = post(self.client, 'wiki.review_revision', {'approve': 'Approve    Revision', 'significance': significance, 'comment': 'something', 'needs_change': True, 'needs_change_comment': 'comment'}, args=[self.document.slug, self.revision.id])
    eq_(200, response.status_code)
    r = Revision.objects.get(pk=self.revision.id)
    eq_(significance, r.significance)
    assert r.reviewed
    assert r.is_approved
    assert r.document.needs_change
    assert (not r.is_ready_for_localization)
    eq_('comment', r.document.needs_change_comment)
    assert (r.creator in self.document.contributors.all())
    reviewed_delay.assert_called_with(r, r.document, 'something')
    if (r.based_on is not None):
        old_rev = r.document.current_Revision
    else:
        old_rev = r.document.revisions.filter(is_approved=True).order_by('-created')[1]
    diff = get_diff_for(r.document, old_rev, r)
    expected_body = (APPROVED_EMAIL_CONTENT % {'reviewer': r.reviewer.profile.name, 'document_title': self.document.title, 'document_slug': self.document.slug, 'watcher': watch.pk, 'secret': watch.secret, 'summary': old_rev.summary, 'diff': diff, 'content': r.content})
    eq_(1, len(mail.outbox))
    attrs_eq(mail.outbox[0], subject=u'{0}    ({1})    has    a    new    approved    revision    ({2})'.format(self.document.title, self.document.locale, self.user.username), body=expected_body, to=['joe@example.com'])
