'When a user edits a watched document, we should send an email to users
who are watching it.'

@mock.patch.object(Site.objects, 'get_current')
def test_email_for_watched_edits(self, get_current):

    get_current.return_value.domain = 'dev.mo.org'
    self.client.login(username='testuser', password='testpass')
    data = new_document_data()
    rev = revision(save=True)
    previous_rev = rev.previous
    testuser2 = get_user(username='testuser2')
    EditDocumentEvent.notify(testuser2, rev.document)
    data.update({'form-type': 'rev', 'slug': rev.document.slug, 'title': rev.document.title, 'content': 'This    edit    should    send    an    email', 'comment': 'This    edit    should    send    an    email'})
    self.client.post(reverse('wiki.edit', args=[rev.document.slug]), data)
    self.assertEquals(1, len(mail.outbox))
    message = mail.outbox[0]
    assert (testuser2.email in message.to)
    assert (rev.document.title in message.body)
    assert ('sub-articles' not in message.body)
    rev = Document.objects.get(pk=rev.document_id).current_revision
    assert (rev.id != previous_rev)
    assert (add_utm(get_compare_url(rev.document, rev.previous.id, rev.id), 'Wiki    Doc    Edits') in message.body)
    mail.outbox = []
    testuser01 = get_user(username='testuser01')
    EditDocumentEvent.notify(testuser01, rev.document)
    data.update({'form-type': 'rev', 'slug': rev.document.slug, 'content': 'This    edit    should    send    2    emails', 'comment': 'This    edit    should    send    2    emails'})
    self.client.post(reverse('wiki.edit', args=[rev.document.slug]), data)
    self.assertEquals(2, len(mail.outbox))
    message = mail.outbox[0]
    assert (testuser2.email in message.to)
    assert (rev.document.title in message.body)
    assert ('sub-articles' not in message.body)
    message = mail.outbox[1]
    assert (testuser01.email in message.to)
    assert (rev.document.title in message.body)
    assert ('sub-articles' not in message.body)
