def test_gather_older_revision(root_doc, client): """Older revisions can be imported without some tags.""" doc_path = root_doc.get_absolute_url() old_rev = root_doc.revisions.order_by('id')[0] assert old_rev != root_doc.current_revision rev_path = doc_path + '$revision/%d' % old_rev.id html = client.get(rev_path).content source = RevisionSource(rev_path) source.state = source.STATE_PREREQ requester = mock_requester(requester_spec=[]) storage = mock_storage(spec=[ 'get_document', 'get_revision', 'get_document_metadata', 'get_revision_html', 'get_user', 'save_revision']) storage.get_document.return_value = root_doc storage.get_document_metadata.return_value = {'is_meta': True} storage.get_revision_html.return_value = html storage.get_user.return_value = {'username': '******'} resources = source.gather(requester, storage) assert resources == [] assert source.state == source.STATE_DONE assert source.freshness == source.FRESH_YES # Missing review and localization tags if it is not the current revision expected_data = { 'id': old_rev.id, 'comment': '', 'content': '<p>Getting started...</p>', 'created': datetime(2016, 1, 1), 'creator': {u'username': u'creator'}, 'document': root_doc, 'is_current': False, 'slug': 'Root', 'tags': [], 'title': 'Root Document', } storage.save_revision.assert_called_once_with(expected_data)
def test_gather_with_prereqs(tagged_doc, client): """On the first call, multiple items are requested from storage.""" doc_path = tagged_doc.get_absolute_url() rev_path = doc_path + '$revision/%d' % tagged_doc.current_revision_id html = client.get(rev_path).content source = RevisionSource(rev_path) source.state = source.STATE_PREREQ requester = mock_requester(requester_spec=[]) storage = mock_storage(spec=[ 'get_document', 'get_revision', 'get_document_metadata', 'get_revision_html', 'get_user', 'save_revision']) storage.get_document.return_value = tagged_doc storage.get_document_metadata.return_value = {'is_meta': True} storage.get_revision_html.return_value = html storage.get_user.return_value = {'username': '******'} resources = source.gather(requester, storage) assert resources == [] assert source.state == source.STATE_DONE assert source.freshness == source.FRESH_YES expected_data = { 'id': tagged_doc.current_revision_id, 'comment': 'Frist Post!', 'content': '<p>The HTML element <code><input></code>...', 'created': datetime(2016, 12, 15, 17, 23), 'creator': {u'username': u'creator'}, 'document': tagged_doc, 'is_current': True, 'localization_tags': [], 'review_tags': [], 'slug': 'Test', 'tags': ['One', 'Three', 'Two'], 'title': 'Test Document', } storage.save_revision.assert_called_once_with(expected_data)
def test_gather_document_slug_wins(tagged_doc, client): """ If the document slug is different from the revision, doc wins. This appears to be common around page moves. """ orig_doc_path = tagged_doc.get_absolute_url() orig_rev_path = orig_doc_path + ('$revision/%d' % tagged_doc.current_revision_id) html = client.get(orig_rev_path).content tagged_doc.slug = 'Other' doc_path = tagged_doc.get_absolute_url() rev_path = doc_path + '$revision/%d' % tagged_doc.current_revision_id source = RevisionSource(rev_path) source.state = source.STATE_PREREQ requester = mock_requester(requester_spec=[]) storage = mock_storage(spec=[ 'get_document', 'get_revision', 'get_document_metadata', 'get_revision_html', 'get_user', 'save_revision' ]) storage.get_document.return_value = tagged_doc storage.get_document_metadata.return_value = {'is_meta': True} storage.get_revision_html.return_value = html storage.get_user.return_value = {'username': '******'} resources = source.gather(requester, storage) assert resources == [] assert source.state == source.STATE_DONE assert source.freshness == source.FRESH_YES expected_data = { 'id': tagged_doc.current_revision_id, 'comment': 'Frist Post!', 'content': '<p>The HTML element <code><input></code>...', 'created': datetime(2016, 12, 15, 17, 23), 'creator': { u'username': u'creator' }, 'document': tagged_doc, 'is_current': True, 'localization_tags': [], 'review_tags': [], 'slug': 'Other', 'tags': ['One', 'Three', 'Two'], 'title': 'Test Document', } storage.save_revision.assert_called_once_with(expected_data)
def test_gather_document_slug_wins(tagged_doc, client): """ If the document slug is different from the revision, doc wins. This appears to be common around page moves. """ orig_doc_path = tagged_doc.get_absolute_url() orig_rev_path = orig_doc_path + ('$revision/%d' % tagged_doc.current_revision_id) html = client.get(orig_rev_path).content tagged_doc.slug = 'Other' doc_path = tagged_doc.get_absolute_url() rev_path = doc_path + '$revision/%d' % tagged_doc.current_revision_id source = RevisionSource(rev_path) source.state = source.STATE_PREREQ requester = mock_requester(requester_spec=[]) storage = mock_storage(spec=[ 'get_document', 'get_revision', 'get_document_metadata', 'get_revision_html', 'get_user', 'save_revision']) storage.get_document.return_value = tagged_doc storage.get_document_metadata.return_value = {'is_meta': True} storage.get_revision_html.return_value = html storage.get_user.return_value = {'username': '******'} resources = source.gather(requester, storage) assert resources == [] assert source.state == source.STATE_DONE assert source.freshness == source.FRESH_YES expected_data = { 'id': tagged_doc.current_revision_id, 'comment': 'Frist Post!', 'content': '<p>The HTML element <code><input></code>...', 'created': datetime(2016, 12, 15, 17, 23), 'creator': {u'username': u'creator'}, 'document': tagged_doc, 'is_current': True, 'localization_tags': [], 'review_tags': [], 'slug': 'Other', 'tags': ['One', 'Three', 'Two'], 'title': 'Test Document', } storage.save_revision.assert_called_once_with(expected_data)