def test_docs_with_localization(self): pod = testing.create_pod() fields = { 'localization': { 'default_locale': 'en', 'locales': [ 'de', 'fr', 'it', ] } } pod.write_yaml('/podspec.yaml', fields) fields = { '$view': '/views/base.html', '$path': '/{base}/', 'localization': { 'path': '/{locale}/{base}/', } } pod.write_yaml('/content/pages/_blueprint.yaml', fields) pod.write_yaml('/content/pages/foo.yaml', {}) pod.write_yaml('/content/pages/bar.yaml', {}) pod.write_yaml('/content/pages/baz.yaml', {}) pod.write_yaml('/content/pages/[email protected]', {}) collection = pod.get_collection('pages') self.assertEqual(3, len(collection.docs(locale='en'))) self.assertEqual(3, len(collection.docs(locale='de')))
def test_docs(self): # List documents where locale = fr. collection = self.pod.get_collection('pages') documents = collection.docs(locale='fr') for doc in documents: self.assertEqual('fr', doc.locale) # Verify list behavior with multi-file localized documents. expected_docs = [ self.pod.get_doc(pod_path, locale='fr') for pod_path in [ '/content/pages/json_test.html', '/content/pages/yaml_test.html', '/content/pages/home.yaml', '/content/pages/[email protected]', '/content/pages/about.yaml', '/content/pages/contact.yaml', ] ] for doc in expected_docs: self.assertIn(doc, documents) # List unhidden documents. documents = collection.docs() for doc in documents: self.assertFalse(doc.hidden) # List all documents. documents = collection.docs(include_hidden=True) collection = self.pod.get_collection('posts') documents = collection.docs(order_by='$published', reverse=True) expected = ['newest', 'newer', 'older', 'oldest'] self.assertListEqual(expected, [doc.base for doc in documents])
def test_empty_front_matter(self): collection = self.pod.get_collection('empty-front-matter') docs = collection.docs() path = '/content/empty-front-matter/empty-front-matter.html' expected_doc = self.pod.get_doc(path) self.assertEqual(expected_doc, docs[0])