예제 #1
0
    def test_listOfTempLanguageNames(self):
        lang_names_file = os.path.join(self.resources_dir, "templanguages.json")
        lang_names = file_utils.load_json_object(lang_names_file)
        vc = PageMetrics()
        success = True
        msg = ""
        for lang_name in lang_names:

            # given
            code = lang_name["lc"]
            language_name = lang_name["ln"]
            expected_language_code = code.lower()
            self.lang_url = "https://live.door43.org/pt-BR/"

            # when
            lang_code = vc.validate_language_code(code)

            # then
            if lang_code != expected_language_code:
                msg = "FAILURE: For language '{0}', expected code '{2}' but got '{1}'".format(language_name, lang_code,
                                                                                              expected_language_code)
                App.logger.debug(msg)
                success = False

        if not success:
            self.assertTrue(success, msg)
예제 #2
0
    def test_validLangTextIncrement(self):
        # given
        vc = PageMetrics()
        expected_view_count = 1
        self.lang_url = "https://live.door43.org/zzz/"

        # when
        results = vc.get_language_view_count(self.lang_url, increment=1)

        # then
        self.validateResults(expected_view_count, results)
예제 #3
0
    def test_validIncrement(self):
        # given
        vc = PageMetrics()
        expected_view_count = ViewCountTest.INITIAL_VIEW_COUNT + 1
        self.repo_url = "https://live.door43.org/u/dummy/repo/96db55378e/"

        # when
        results = vc.get_view_count(self.repo_url, increment=1)

        # then
        self.validateResults(expected_view_count, results)
예제 #4
0
    def test_validIncrement(self):
        # given
        vc = PageMetrics()
        expected_view_count = ViewCountTest.INITIAL_VIEW_COUNT + 1
        self.lang_url = "https://live.door43.org/en/"

        # when
        results = vc.get_language_view_count(self.lang_url, increment=1)

        # then
        self.validateResults(expected_view_count, results)
예제 #5
0
    def test_localizedLanguage2(self):
        # given
        vc = PageMetrics()
        expected_view_count = 0
        self.lang_url = "https://live.door43.org/es-419/"

        # when
        results = vc.get_language_view_count(self.lang_url, increment=0)

        # then
        self.validateResults(expected_view_count, results)
    def test_validRepoNotInManifestTableIncrement(self):
        # given
        vc = PageMetrics()
        expected_view_count = 0
        self.repo_url = "https://live.door43.org/u/dummy/repo2/96db55378e/"

        # when
        results = vc.get_view_count(self.repo_url, increment=1)

        # then
        self.validateResults(expected_view_count, results)
    def test_unsupportedPath(self):
        # given
        vc = PageMetrics()
        expected_view_count = 0
        self.repo_url = "https://other_url.com/dummy/stuff2/stuff3/"

        # when
        results = vc.get_view_count(self.repo_url, increment=1)

        # then
        self.validateResults(expected_view_count, results, error_type=PageMetrics.INVALID_URL_ERROR)
예제 #8
0
    def test_unsupportedPath(self):
        # given
        vc = PageMetrics()
        expected_view_count = -1
        self.repo_url = "https://api.door43.org?"

        # when
        results = vc.increment_search_params(self.repo_url)

        # then
        self.assertEquals(expected_view_count, results)
예제 #9
0
    def test_unsupportedPathShouldFail(self):
        # given
        vc = PageMetrics()
        expected_view_count = 0
        self.lang_url = "https://other_url.com/dummy/stuff2/stuff3/"

        # when
        results = vc.get_language_view_count(self.lang_url, increment=1)

        # then
        self.validateResults(expected_view_count, results, error_type=PageMetrics.INVALID_LANG_URL_ERROR)
예제 #10
0
    def test_valid(self):
        # given
        vc = PageMetrics()
        expected_view_count = self.INITIAL_VIEW_COUNT + 1
        self.repo_url = "https://api.door43.org?lc=en"

        # when
        results = vc.increment_search_params(self.repo_url)

        # then
        self.assertEquals(expected_view_count, results)
예제 #11
0
    def test_validRepoNotInManifestTable(self):
        # given
        vc = PageMetrics()
        expected_view_count = 1
        self.repo_url = "https://api.door43.org?lc=en1"

        # when
        results = vc.increment_search_params(self.repo_url)

        # then
        self.assertEquals(expected_view_count, results)
예제 #12
0
    def test_validRepoNotInManifestTableIncrement(self):
        # given
        vc = PageMetrics()
        expected_view_count = 0
        self.repo_url = "https://live.door43.org/u/dummy/repo2/96db55378e/"

        # when
        results = vc.get_view_count(self.repo_url, increment=1)

        # then
        self.validateResults(expected_view_count, results)
    def test_valid(self):
        # given
        vc = PageMetrics()
        expected_view_count = self.INITIAL_VIEW_COUNT + 1
        self.repo_url = "https://api.door43.org?lc=en"

        # when
        results = vc.increment_search_params(self.repo_url)

        # then
        self.assertEquals(expected_view_count, results)
    def test_validRepoNotInManifestTable(self):
        # given
        vc = PageMetrics()
        expected_view_count = 1
        self.repo_url = "https://api.door43.org?lc=en1"

        # when
        results = vc.increment_search_params(self.repo_url)

        # then
        self.assertEquals(expected_view_count, results)
예제 #15
0
    def test_missingPathShouldFail(self):
        # given
        vc = PageMetrics()
        expected_view_count = 0
        self.lang_url = ""

        # when
        results = vc.get_language_view_count(self.lang_url, increment=1)

        # then
        self.validateResults(expected_view_count, results, error_type=PageMetrics.INVALID_LANG_URL_ERROR)
예제 #16
0
    def test_shortLanguageShouldFail(self):
        # given
        vc = PageMetrics(**{})
        expected_view_count = 0
        self.lang_url = "https://live.door43.org/e/"

        # when
        results = vc.get_language_view_count(self.lang_url, increment=1)

        # then
        self.validateResults(expected_view_count, results, error_type=PageMetrics.INVALID_LANG_URL_ERROR)
    def test_validIncrement(self):
        # given
        vc = PageMetrics()
        expected_view_count = ViewCountTest.INITIAL_VIEW_COUNT + 1
        self.repo_url = "https://live.door43.org/u/dummy/repo/96db55378e/"

        # when
        results = vc.get_view_count(self.repo_url, increment=1)

        # then
        self.validateResults(expected_view_count, results)
예제 #18
0
    def test_longLanguageShouldFail5(self):
        # given
        vc = PageMetrics()
        expected_view_count = ViewCountTest.INITIAL_VIEW_COUNT
        self.lang_url = "https://live.door43.org/eng-x-/"

        # when
        results = vc.get_language_view_count(self.lang_url, increment=0)

        # then
        self.validateResults(expected_view_count, results, error_type=PageMetrics.INVALID_LANG_URL_ERROR)
    def test_missingPath(self):
        # given
        vc = PageMetrics()
        expected_view_count = 0
        self.repo_url = ""

        # when
        results = vc.get_view_count(self.repo_url, increment=1)

        # then
        self.validateResults(expected_view_count, results, error_type=PageMetrics.INVALID_URL_ERROR)
    def test_unsupportedPath(self):
        # given
        vc = PageMetrics()
        expected_view_count = -1
        self.repo_url = "https://api.door43.org?"

        # when
        results = vc.increment_search_params(self.repo_url)

        # then
        self.assertEquals(expected_view_count, results)
예제 #21
0
    def test_invalidLanguageStatsTableShouldFail(self):
        # given
        vc = PageMetrics()
        expected_view_count = ViewCountTest.INITIAL_VIEW_COUNT + 1
        App._language_stats_db_handler = None
        App.language_stats_table_name = None
        self.lang_url = "https://live.door43.org/en/"

        # when
        results = vc.get_language_view_count(self.lang_url, increment=1)

        # then
        self.validateResults(expected_view_count, results, error_type=PageMetrics.DB_ACCESS_ERROR)
예제 #22
0
    def test_missingPath(self):
        # given
        vc = PageMetrics()
        expected_view_count = 0
        self.repo_url = ""

        # when
        results = vc.get_view_count(self.repo_url, increment=1)

        # then
        self.validateResults(expected_view_count,
                             results,
                             error_type=PageMetrics.INVALID_URL_ERROR)
예제 #23
0
    def lint(self):
        """
        Checks for issues with all Bibles, such as missing books or chapters

        Use self.log.warning("message") to log any issues.
        self.source_dir is the directory of .usfm files
        :return bool:
        """

        lang_code = self.rc.resource.language.identifier
        valid_lang_code = PageMetrics().validate_language_code(lang_code)
        if not valid_lang_code:
            self.log.warning("Invalid language code: " + lang_code)

        for root, dirs, files in os.walk(self.source_dir):
            for f in files:
                if os.path.splitext(
                        f)[1].lower() != '.usfm':  # only usfm files
                    continue

                if self.single_file and (f != self.single_file):
                    continue

                App.logger.debug("linting: " + f)
                file_path = os.path.join(root, f)
                sub_path = '.' + file_path[len(self.source_dir):]
                self.parse_file(file_path, sub_path, f)

        if not len(self.found_books):
            self.log.warning("No translations found")

        return True
예제 #24
0
    def _handle(self, event, context):
        """
        :param dict event:
        :param context:
        :return dict:
        """
        # Gather arguments
        increment = int(
            self.retrieve(self.data,
                          'increment',
                          'Payload',
                          required=False,
                          default=0))
        path = self.retrieve(self.data,
                             'path',
                             'Payload',
                             required=False,
                             default='')
        callback = self.retrieve(self.data,
                                 'callback',
                                 'Payload',
                                 required=False)

        # Execute
        data = PageMetrics().get_view_count(path, increment)
        if callback:
            return callback + '(' + json.dumps(data) + ')'
        else:
            return data
예제 #25
0
 def build_language_popularity_tables(self, body, max_count):
     vc = PageMetrics()
     self.language_views = vc.get_language_views_sorted_by_count(reverse_sort=True, max_count=max_count)
     self.generate_highest_views_lang_table(body, self.language_views, max_count)
     self.searches = vc.get_searches_sorted_by_count(reverse_sort=True, max_count=max_count)
     self.generate_highest_searches_table(body, self.searches, max_count)
 def get_search_items(self, count):
     self.initialze_searches_table(count)
     vc = PageMetrics()
     self.searches = vc.get_searches_sorted_by_count()
예제 #27
0
 def save_url_search(self):
     PageMetrics().increment_search_params(self.url_params)
 def get_language_view_items(self, count):
     self.initialze_lang_stats_table(count)
     vc = PageMetrics()
     self.language_views = vc.get_language_views_sorted_by_count()