Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
bug 1462475: Drop normalized_path
Browse files Browse the repository at this point in the history
The normalized_path was used to distinguish between the zone URL
('vanity URL') and the standard doc path. With Zones gone, there is no
longer a difference.
  • Loading branch information
jwhitlock committed Aug 3, 2018
1 parent 5b527e7 commit 3dc15e7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 22 deletions.
1 change: 0 additions & 1 deletion kuma/scrape/sources/base.py
Expand Up @@ -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."""
Expand Down
25 changes: 8 additions & 17 deletions kuma/scrape/sources/document.py
Expand Up @@ -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:
Expand All @@ -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'):
Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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']
Expand Down Expand Up @@ -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."""
Expand All @@ -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."""
Expand Down Expand Up @@ -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})]
4 changes: 2 additions & 2 deletions kuma/scrape/tests/test_source_document.py
Expand Up @@ -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'])
Expand All @@ -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=[
Expand Down
2 changes: 0 additions & 2 deletions kuma/scrape/tests/test_source_document_base.py
Expand Up @@ -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

Expand All @@ -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'

Expand Down

0 comments on commit 3dc15e7

Please sign in to comment.