'Review tags can be managed on document revisions'

@pytest.mark.review_tags
@mock.patch.object(Site.objects, 'get_current')
def test_review_tags(self, get_current):

    get_current.return_value.domain = 'su.mo.com'
    self.client.login(username='admin', password='testpass')
    data = new_document_data()
    data.update({'review_tags': ['technical']})
    response = self.client.post(reverse('wiki.create'), data)
    doc = Document.objects.get(slug='a-test-article')
    rev = doc.revisions.order_by('-id').all()[0]
    review_tags = [x.name for x in rev.review_tags.all()]
    eq_(['technical'], review_tags)
    data.update({'form-type': 'rev', 'review_tags': ['editorial', 'technical']})
    response = self.client.post(reverse('wiki.edit', args=[doc.slug]), data)
    doc = Document.objects.get(locale=settings.WIKI_DEFAULT_LANGUAGE, slug='a-test-article')
    rev = doc.revisions.order_by('-id').all()[0]
    review_tags = [x.name for x in rev.review_tags.all()]
    review_tags.sort()
    eq_(['editorial', 'technical'], review_tags)
    response = self.client.get(reverse('wiki.document', args=[doc.slug]), data)
    page = pq(response.content)
    eq_(1, page.find('.page-meta.reviews').length)
    eq_(1, page.find('#id_request_technical').length)
    eq_(1, page.find('#id_request_editorial').length)
    response = self.client.get(reverse('wiki.list_review'))
    eq_(1, pq(response.content).find(("ul.document-list    li    a:contains('%s')" % doc.title)).length)
    response = self.client.get(reverse('wiki.list_review_tag', args=('technical',)))
    eq_(1, pq(response.content).find(("ul.document-list    li    a:contains('%s')" % doc.title)).length)
    response = self.client.get(reverse('wiki.list_review_tag', args=('editorial',)))
    eq_(1, pq(response.content).find(("ul.document-list    li    a:contains('%s')" % doc.title)).length)
    response = self.client.get(reverse('wiki.feeds.list_review', args=('atom',)))
    ok_((('<entry><title>%s</title>' % doc.title) in response.content))
    response = self.client.get(reverse('wiki.feeds.list_review_tag', args=('atom', 'technical')))
    ok_((('<entry><title>%s</title>' % doc.title) in response.content))
    response = self.client.get(reverse('wiki.feeds.list_review_tag', args=('atom', 'editorial')))
    ok_((('<entry><title>%s</title>' % doc.title) in response.content))
    data.update({'form-type': 'rev', 'review_tags': ['editorial']})
    response = self.client.post(reverse('wiki.edit', args=[doc.slug]), data)
    response = self.client.get(reverse('wiki.document', args=[doc.slug]), data)
    page = pq(response.content)
    eq_(1, page.find('.page-meta.reviews').length)
    eq_(0, page.find('#id_request_technical').length)
    eq_(1, page.find('#id_request_editorial').length)
    response = self.client.get(reverse('wiki.list_review'))
    eq_(1, pq(response.content).find(("ul.document-list    li    a:contains('%s')" % doc.title)).length)
    response = self.client.get(reverse('wiki.list_review_tag', args=('technical',)))
    eq_(0, pq(response.content).find(("ul.document-list    li    a:contains('%s')" % doc.title)).length)
    response = self.client.get(reverse('wiki.list_review_tag', args=('editorial',)))
    eq_(1, pq(response.content).find(("ul.document-list    li    a:contains('%s')" % doc.title)).length)
    response = self.client.get(reverse('wiki.feeds.list_review', args=('atom',)))
    ok_((('<entry><title>%s</title>' % doc.title) in response.content))
    response = self.client.get(reverse('wiki.feeds.list_review_tag', args=('atom', 'technical')))
    ok_((('<entry><title>%s</title>' % doc.title) not in response.content))
    response = self.client.get(reverse('wiki.feeds.list_review_tag', args=('atom', 'editorial')))
    ok_((('<entry><title>%s</title>' % doc.title) in response.content))
