'Document tags can be edited through revisions'

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

    data = new_document_data()
    locale = data['locale']
    slug = data['slug']
    path = slug
    ts1 = ('JavaScript', 'AJAX', 'DOM')
    ts2 = ('XML', 'JSON')
    get_current.return_value.domain = 'su.mo.com'
    self.client.login(username='admin', password='testpass')
    def assert_tag_state(yes_tags, no_tags):
        doc = Document.objects.get(locale=locale, slug=slug)
        doc_tags = [x.name for x in doc.tags.all()]
        for t in yes_tags:
            ok_((t in doc_tags))
        for t in no_tags:
            ok_((t not in doc_tags))
        response = self.client.get(reverse('wiki.document', args=[doc.slug]), data)
        page = pq(response.content)
        for t in yes_tags:
            eq_(1, page.find(('.tags    li    a:contains("%s")' % t)).length, ('%s    should    NOT    appear    in    document    view    tags' % t))
        for t in no_tags:
            eq_(0, page.find(('.tags    li    a:contains("%s")' % t)).length, ('%s    should    appear    in    document    view    tags' % t))
        for t in yes_tags:
            response = self.client.get(reverse('wiki.tag', args=[t]))
            self.assertContains(response, doc.slug, msg_prefix=t)
            response = self.client.get(reverse('wiki.feeds.recent_documents', args=['atom', t]))
            self.assertContains(response, doc.title)
        for t in no_tags:
            response = self.client.get(reverse('wiki.tag', args=[t]))
            ok_((doc.slug not in response.content.decode('utf-8')))
            response = self.client.get(reverse('wiki.feeds.recent_documents', args=['atom', t]))
            self.assertNotContains(response, doc.title)
    data.update({'slug': slug, 'tags': ','.join(ts1)})
    self.client.post(reverse('wiki.create'), data)
    assert_tag_state(ts1, ts2)
    data.update({'form-type': 'rev', 'tags': ',    '.join(ts2)})
    self.client.post(reverse('wiki.edit', args=[path]), data)
    assert_tag_state(ts2, ts1)
