def test_format_pod_env_fingerprint(self): """Test env fingerprints.""" env = _mock_env(fingerprint="ABC123") pod = _mock_pod(env=env) path_format = grow_path_format.PathFormat(pod) self.assertEquals('/ABC123/test', path_format.format_pod('/{env.fingerprint}/test'))
def test_format_static_root(self): """Test doc paths.""" pod = _mock_pod(podspec={ 'root': 'root_path', }) path_format = grow_path_format.PathFormat(pod) self.assertEquals('/root_path/test', path_format.format_static('/{root}/test'))
def test_format_pod_extra_slash(self): """Test extra slashes are removed.""" pod = _mock_pod(podspec={ 'root': '/root_path', }) path_format = grow_path_format.PathFormat(pod) self.assertEquals('/root_path/test', path_format.format_pod('/{root}/test'))
def test_format_doc_base(self): """Test doc paths with the base filename.""" pod = _mock_pod(podspec={ 'root': 'root_path', }) path_format = grow_path_format.PathFormat(pod) doc = _mock_doc(pod, base='doc1') self.assertEqual('/doc1/', path_format.format_doc(doc, '/{base}/'))
def test_format_static_locale(self): """Test doc paths with locale.""" pod = _mock_pod(podspec={ 'root': 'root_path', }) path_format = grow_path_format.PathFormat(pod) doc = _mock_static(pod, '/{root}/test/{locale}', locale='es') self.assertEquals('/root_path/test/es', path_format.format_static(doc))
def test_format_doc_root(self): """Test doc paths.""" pod = _mock_pod(podspec={ 'root': 'root_path', }) path_format = grow_path_format.PathFormat(pod) doc = _mock_doc(pod) self.assertEqual('/root_path/test/', path_format.format_doc(doc, '/{root}/test'))
def test_format_static_locale_params(self): """Test doc paths with locale and keeping params.""" pod = _mock_pod(podspec={ 'root': 'root_path', }) path_format = grow_path_format.PathFormat(pod) doc = _mock_static(pod, '/{root}/test/{locale}', locale='es') self.assertEquals('/root_path/test/:locale', path_format.format_static(doc, parameterize=True))
def test_format_pod_params(self): """Test params are converted.""" pod = _mock_pod(podspec={ 'root': '/root_path', }) path_format = grow_path_format.PathFormat(pod) self.assertEquals( '/root_path/test/:locale/something', path_format.format_pod('/{root}/test/{locale}/something', parameterize=True))
def test_format_static_fingerprint(self): """Test doc paths with fingerprint.""" pod = _mock_pod(podspec={ 'root': 'root_path', }) path_format = grow_path_format.PathFormat(pod) self.assertEqual( '/root_path/test/asdf', path_format.format_static('/{root}/test/{fingerprint}', fingerprint='asdf'))
def test_format_doc_collection(self): """Test doc paths.""" pod = _mock_pod(podspec={ 'root': 'root_path', }) path_format = grow_path_format.PathFormat(pod) collection = _mock_collection(basename='/pages/') doc = _mock_doc(pod, collection=collection, collection_base_path='/sub/') self.assertEquals( '/root_path/sub/test/', path_format.format_doc(doc, '/{root}/{collection.base_path}/test'))
def test_format_doc_base_index(self): """Test doc paths with the index as a base filename.""" pod = _mock_pod(podspec={ 'root': 'root_path', }) path_format = grow_path_format.PathFormat(pod) doc = _mock_doc(pod, base='index') self.assertEqual('/', path_format.format_doc(doc, '/{base}/')) self.assertEqual('/', path_format.format_doc(doc, '/{base}')) # Does not replace index when it is not the end of the path. self.assertEqual('/index.html', path_format.format_doc(doc, '/{base}.html'))
def path_format(self): """Format utility for url paths.""" return grow_path_format.PathFormat(self)