<commit_before>from grow.pods import pods
from grow.pods import storage
from grow.testing import testing
import unittest
import webob.exc


class RoutesTest(unittest.TestCase):

    def setUp(self):
        self.maxDiff = None
        self.dir_path = testing.create_test_pod_dir()
        self.pod = pods.Pod(self.dir_path, storage=storage.FileStorage)

    def test_match(self):
        controller, params = self.pod.match('/')
        controller.render(params)
        controller, params = self.pod.match('/fr/about/')
        controller.render(params)
        controller, params = self.pod.match('/de_alias/about/')
        controller.render(params)
        controller, params = self.pod.match('/app/static/file with spaces.txt')
        controller.render(params)
        with self.assertRaises(webob.exc.HTTPNotFound):
            self.pod.match('/dummy/')

    def test_remove(self):
        controller, params = self.pod.match('/about/')
        controller.render(params)
        doc = self.pod.get_doc('/content/pages/about.yaml')
        self.pod.routes.remove_document(doc)
        with self.assertRaises(webob.exc.HTTPNotFound):
            self.pod.match('/about/')

    def test_list_concrete_paths(self):
        expected = [
            '/',
            '/about/',
            '/app/root/static/somepath/de_alias/test-9b3051eb0c19358847e7c879275f810a.txt',
            '/app/static/file with spaces-d41d8cd98f00b204e9800998ecf8427e.txt',
            '/app/static/sym/test_sym-15918ecf75b208ad2decc78ec3caa95d.txt',
            '/app/static/test-db3f6eaa28bac5ae1180257da33115d8.txt',
            '/de_alias/about/',
            '/de_alias/contact-us/',
            '/de_alias/home/',
            '/de_alias/html/',
            '/de_alias/intro/',
            '/de_alias/yaml_test/',
            '/fi_ALL/about/',
            '/fi_ALL/home/',
            '/fi_ALL/html/',
            '/fi_ALL/intro/',
            '/fi_ALL/yaml_test/',
            '/fil_ALL/about/',
            '/fil_ALL/home/',
            '/fil_ALL/html/',
            '/fil_ALL/intro/',
            '/fil_ALL/yaml_test/',
            '/fr/about/',
            '/fr/contact-us/',
            '/fr/home/',
            '/fr/html/',
            '/fr/intro/',<commit_msg>Adding tests for the new document functions for the routes.<commit_after>from grow.pods import pods
from grow.pods import storage
from grow.testing import testing
import unittest
import webob.exc


class RoutesTest(unittest.TestCase):

    def setUp(self):
        self.maxDiff = None
        self.dir_path = testing.create_test_pod_dir()
        self.pod = pods.Pod(self.dir_path, storage=storage.FileStorage)

    def test_match(self):
        controller, params = self.pod.match('/')
        controller.render(params)
        controller, params = self.pod.match('/fr/about/')
        controller.render(params)
        controller, params = self.pod.match('/de_alias/about/')
        controller.render(params)
        controller, params = self.pod.match('/app/static/file with spaces.txt')
        controller.render(params)
        with self.assertRaises(webob.exc.HTTPNotFound):
            self.pod.match('/dummy/')

    def test_add_remove_document(self):
        controller, params = self.pod.match('/about/')
        controller.render(params)
        doc = self.pod.get_doc('/content/pages/about.yaml')
        self.pod.routes.remove_document(doc)
        with self.assertRaises(webob.exc.HTTPNotFound):
            self.pod.match('/about/')
        self.pod.routes.add_document(doc)
        controller, params = self.pod.match('/about/')
        controller.render(params)

    def test_add_remove_documents(self):
        controller, params = self.pod.match('/')
        controller.render(params)
        controller, params = self.pod.match('/about/')
        controller.render(params)
        doc_home = self.pod.get_doc('/content/pages/home.yaml')
        doc_about = self.pod.get_doc('/content/pages/about.yaml')
        docs = [doc_home, doc_about]
        self.pod.routes.remove_documents(docs)
        with self.assertRaises(webob.exc.HTTPNotFound):
            self.pod.match('/')
        with self.assertRaises(webob.exc.HTTPNotFound):
            self.pod.match('/about/')
        self.pod.routes.add_documents(docs)
        controller, params = self.pod.match('/')
        controller.render(params)
        controller, params = self.pod.match('/about/')
        controller.render(params)

    def test_reconcile_documents(self):
        controller, params = self.pod.match('/about/')
        controller.render(params)
        self.pod.write_yaml('/content/pages/foobar.yaml', {
            '$title': 'Foobar'
        })
        with self.assertRaises(webob.exc.HTTPNotFound):
            self.pod.match('/foobar/')
        doc_about = self.pod.get_doc('/content/pages/about.yaml')
        doc_foobar = self.pod.get_doc('/content/pages/foobar.yaml')
        print doc_foobar.get_serving_path()
        self.pod.routes.reconcile_documents(
            remove_docs=[doc_about],
            add_docs=[doc_foobar])
        with self.assertRaises(webob.exc.HTTPNotFound):
            self.pod.match('/about/')
        controller, params = self.pod.match('/foobar/')
        controller.render(params)

    def test_list_concrete_paths(self):
        expected = [
            '/',
            '/about/',
            '/app/root/static/somepath/de_alias/test-9b3051eb0c19358847e7c879275f810a.txt',
            '/app/static/file with spaces-d41d8cd98f00b204e9800998ecf8427e.txt',
            '/app/static/sym/test_sym-15918ecf75b208ad2decc78ec3caa95d.txt',
            '/app/static/test-db3f6eaa28bac5ae1180257da33115d8.txt',
            '/de_alias/about/',
            '/de_alias/contact-us/',
            '/de_alias/home/',
            '/de_alias/html/',
            '/de_alias/intro/',
            '/de_alias/yaml_test/',
            '/fi_ALL/about/',
            '/fi_ALL/home/',
            '/fi_ALL/html/',
            '/fi_ALL/intro/',
            '/fi_ALL/yaml_test/',
            '/fil_ALL/about/',
            '/fil_ALL/home/',
            '/fil_ALL/html/',
            '/fil_ALL/intro/',
            '/fil_ALL/yaml_test/',
            '/fr/about/',
            '/fr/contact-us/',
            '/fr/home/',
            '/fr/html/',
            '/fr/intro/',
{'fraction_non_alphanumeric': 0.14236001265422335, 'fraction_numerical': 0.0249920911104081, 'mean_word_length': 2.0486981677917067, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4086703', 'n_tokens_mistral': 2094, 'n_tokens_neox': 1978, 'n_words': 260}