<commit_before>#!/usr/bin/env python

# Akvo RSR is covered by the GNU Affero General Public License.
# See more details in the license.txt file located at the root folder of the Akvo RSR module.
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.

from unittest import TestCase

from helpers.akvopaths import *
from helpers.akvourls import *
from helpers.testexecution import *


class AkvoURLsTest(TestCase):

    def test_akvo_urls(self):
        """helpers.unittests.AkvoURLsTest  akvourls module has a URL function for each Akvo page path"""

        expected_url_function_names = self.expected_akvo_url_function_names()
        actual_url_function_names = self.actual_akvo_url_function_names()

        self.assertEqual(len(expected_url_function_names), len(actual_url_function_names),
                         "\nExpected number of URL function names: %i\n  Actual number of URL function names: %i" %
                                (len(expected_url_function_names), len(actual_url_function_names)))

        for expected_function_name in expected_url_function_names:
            self.assertTrue(expected_function_name in actual_url_function_names,
                         "\nExpected URL function name '%s' in:\n%s" %
                                (expected_function_name, actual_url_function_names))

    def test_can_get_akvo_url_from_given_page_function_name(self):
        """helpers.unittests.AkvoURLsTest  Can get Akvo URL from given page function name"""

        self.verify_url(self.full_url(home_page()), home_url())
        self.verify_url(self.full_url(projects_page()), projects_url()) # verifies an RSR URL
        self.verify_url(self.full_url(about_page()), about_url()) # verifies a CMS URL
        self.verify_url(self.full_url(blog_page()), blog_url()) # verifies a blog URL

    def expected_akvo_url_function_names(self):
        import helpers.akvopaths
        expected_page_paths = filter(lambda name: name.endswith('_page'), dir(helpers.akvopaths))
        return map(lambda page_path: page_path.replace('_page', '_url'), expected_page_paths)

    def actual_akvo_url_function_names(self):<commit_msg>[#5762847] Updated unit test name and docstring for ensuring the helpers.akvourls module has URL functions for each Akvo page path.<commit_after>#!/usr/bin/env python

# Akvo RSR is covered by the GNU Affero General Public License.
# See more details in the license.txt file located at the root folder of the Akvo RSR module.
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.

from unittest import TestCase

from helpers.akvopaths import *
from helpers.akvourls import *
from helpers.testexecution import *


class AkvoURLsTest(TestCase):

    def test_ensure_akvourls_module_has_url_function_for_each_akvo_page_path(self):
        """helpers.unittests.AkvoURLsTest  Ensure helpers.akvourls module has a URL function for each Akvo page path"""

        expected_url_function_names = self.expected_akvo_url_function_names()
        actual_url_function_names = self.actual_akvo_url_function_names()

        self.assertEqual(len(expected_url_function_names), len(actual_url_function_names),
                         "\nExpected number of URL function names: %i\n  Actual number of URL function names: %i" %
                                (len(expected_url_function_names), len(actual_url_function_names)))

        for expected_function_name in expected_url_function_names:
            self.assertTrue(expected_function_name in actual_url_function_names,
                         "\nExpected URL function name '%s' in:\n%s" %
                                (expected_function_name, actual_url_function_names))

    def test_can_get_akvo_url_from_given_page_function_name(self):
        """helpers.unittests.AkvoURLsTest  Can get Akvo URL from given page function name"""

        self.verify_url(self.full_url(home_page()), home_url())
        self.verify_url(self.full_url(projects_page()), projects_url()) # verifies an RSR URL
        self.verify_url(self.full_url(about_page()), about_url()) # verifies a CMS URL
        self.verify_url(self.full_url(blog_page()), blog_url()) # verifies a blog URL

    def expected_akvo_url_function_names(self):
        import helpers.akvopaths
        expected_page_paths = filter(lambda name: name.endswith('_page'), dir(helpers.akvopaths))
        return map(lambda page_path: page_path.replace('_page', '_url'), expected_page_paths)

    def actual_akvo_url_function_names(self):
{'fraction_non_alphanumeric': 0.08298572996706916, 'fraction_numerical': 0.0015367727771679472, 'mean_word_length': 3.6969072164948455, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3519005', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1339, 'n_words': 329}