diff --git a/kuma/scrape/sources/base.py b/kuma/scrape/sources/base.py index 323cc6187fa..1f43cd634ec 100644 --- a/kuma/scrape/sources/base.py +++ b/kuma/scrape/sources/base.py @@ -224,7 +224,6 @@ def __init__(self, path, **options): if path != unquote(path): raise ValueError('URL-encoded path "%s"' % path) self.locale, self.slug = self.locale_and_slug(path) - self.normalized_path = path def locale_and_slug(self, path): """Extract a document locale and slug from a path.""" diff --git a/kuma/scrape/sources/document.py b/kuma/scrape/sources/document.py index 781d74453ac..61f7141942d 100644 --- a/kuma/scrape/sources/document.py +++ b/kuma/scrape/sources/document.py @@ -20,8 +20,7 @@ def load_and_validate_existing(self, storage): just_this_doc = (not self.translations and self.depth == 0 and - self.revisions == 1 and - self.normalized_path) + self.revisions == 1) if not self.force and just_this_doc: document = storage.get_document(self.locale, self.slug) if document: @@ -33,7 +32,6 @@ def load_prereqs(self, requester, storage): data = {'needs': []} # Load data, gathering further source needs - assert self.normalized_path self.load_prereq_parent_topic(storage, data) self.load_prereq_redirect_check(storage, data) if data.get('has_redirect_check'): @@ -48,7 +46,6 @@ def load_prereqs(self, requester, storage): def load_prereq_parent_topic(self, storage, data): """Load the parent topic, if a child page.""" - assert self.normalized_path if not self.parent_slug: return # No parent to load @@ -60,18 +57,15 @@ def load_prereq_parent_topic(self, storage, data): def load_prereq_redirect_check(self, storage, data): """Check the URL for redirects.""" - assert self.normalized_path redirect = storage.get_document_redirect(self.locale, self.slug) if redirect is None: - data['needs'].append( - ('document_redirect', self.normalized_path, {})) + data['needs'].append(('document_redirect', self.path, {})) else: data['has_redirect_check'] = True data['redirect_to'] = redirect.get('redirect_to') def load_prereq_redirect(self, storage, data): """Load the destination of a redirect.""" - assert self.normalized_path data['is_standard_page'] = data.get('has_redirect_check') redirect_to = data.get('redirect_to') if not redirect_to: @@ -86,14 +80,12 @@ def load_prereq_redirect(self, storage, data): def load_prereq_metadata(self, storage, data): """Load the document metadata.""" - assert self.normalized_path meta = storage.get_document_metadata(self.locale, self.slug) if meta is None: - data['needs'].append(('document_meta', self.normalized_path, + data['needs'].append(('document_meta', self.path, self.current_options())) elif 'error' in meta: - raise self.SourceError('Error getting metadata for %s', - self.normalized_path) + raise self.SourceError('Error getting metadata for %s', self.path) elif meta: data['id'] = meta['id'] data['locale'] = meta['locale'] @@ -138,11 +130,11 @@ def load_prereq_history(self, storage, data): """Load the revision history.""" history = storage.get_document_history(self.locale, self.slug) if history is None: - data['needs'].append(('document_history', self.normalized_path, + data['needs'].append(('document_history', self.path, {"revisions": self.revisions})) elif len(history) == 0: raise self.SourceError('Empty history for document "%s"', - self.normalized_path) + self.path) def load_prereq_children(self, storage, data): """Load the document children.""" @@ -151,8 +143,7 @@ def load_prereq_children(self, storage, data): children = storage.get_document_children(self.locale, self.slug) if children is None: options = self.current_options() - data['needs'].append(('document_children', self.normalized_path, - options)) + data['needs'].append(('document_children', self.path, options)) def save_data(self, storage, data): """Save the document as a redirect or full document.""" @@ -192,5 +183,5 @@ def save_data(self, storage, data): doc_data['locale'], self.path) doc_data['locale'] = self.locale storage.save_document(doc_data) - return [('document_current', self.normalized_path, + return [('document_current', self.path, {'revisions': self.revisions})] diff --git a/kuma/scrape/tests/test_source_document.py b/kuma/scrape/tests/test_source_document.py index bad08df01f1..bfdf9be900c 100644 --- a/kuma/scrape/tests/test_source_document.py +++ b/kuma/scrape/tests/test_source_document.py @@ -201,7 +201,7 @@ def test_gather_standard_doc_no_uuid(): storage.save_document.assert_called_once_with(expected) -def test_gather_normalized_path_moved_page_needed(): +def test_gather_redirect_moved_page_needed(): """If a document is a redirect, request the target page.""" source = DocumentSource('/en-US/docs/Origin', force=True) storage = mock_storage(spec=['get_document', 'get_document_redirect']) @@ -214,7 +214,7 @@ def test_gather_normalized_path_moved_page_needed(): assert source.state == source.STATE_PREREQ -def test_gather_normalized_path_moved_page_followed(): +def test_gather_redirect_moved_page_followed(): """If a document is a redirect to a normal page, create a redirect.""" source = DocumentSource('/en-US/docs/Origin', force=True) storage = mock_storage(spec=[ diff --git a/kuma/scrape/tests/test_source_document_base.py b/kuma/scrape/tests/test_source_document_base.py index 064c5f719b1..86e0c3dcdd6 100644 --- a/kuma/scrape/tests/test_source_document_base.py +++ b/kuma/scrape/tests/test_source_document_base.py @@ -10,7 +10,6 @@ def test_top_level_doc(): assert source.path == '/locale/docs/slug' assert source.locale == 'locale' assert source.slug == 'slug' - assert source.normalized_path == '/locale/docs/slug' assert source.parent_slug is None assert source.parent_path is None @@ -21,7 +20,6 @@ def test_child_doc(): assert source.path == '/locale/docs/parent/child' assert source.locale == 'locale' assert source.slug == 'parent/child' - assert source.normalized_path == '/locale/docs/parent/child' assert source.parent_slug == 'parent' assert source.parent_path == '/locale/docs/parent'