<commit_before>import unittest

from bs4 import BeautifulSoup
from sqlalchemy import and_

from knowledge_repo import KnowledgeRepository
from knowledge_repo.app.proxies import db_session
from knowledge_repo.app.models import Post


class PostTest(unittest.TestCase):

    def setUp(self):
        self.repo = KnowledgeRepository.for_uri('tests/test_repo', auto_create=True)
        self.app = self.repo.get_app(config='tests/config_server.py')
        self.client = self.app.test_client()

        with self.app.app_context():
            # for this test, pick one post
            post = (db_session.query(Post)
                              .filter(Post.is_published)
                              .first())
            self.post_id = post.id
            self.post_rendered_url = '/post/{}'.format(post.path)

    def test01_check_render_route(self):
        """
        Check post path will render in /post/<path>
        """
        rv = self.client.get(self.post_rendered_url)
        assert rv.status == "200 OK"

    def test02_check_post_stats(self):
        """
        Make sure pageview, distinct viewers correct for post
        """
        rv = self.client.get(self.post_rendered_url)

        data = rv.data.decode('utf-8')
        soup = BeautifulSoup(data, 'html.parser')

        # we'll check the post_stats of the post by computing them
        # and ensuring that the upper-right-hand text is correct
        icon = soup.findAll("div", {"id": "pageview_stats"})
        print(icon)
        pageviews_str = icon[0].text.strip()

        with self.app.app_context():
            post = Post.query.get(self.post_id)
            distinct_viewers = post.view_user_count
            pageviews = post.view_count

        db_pageviews_str = "Viewed {pageviews} times by {distinct_viewers} different users".format(**locals())
<commit_msg>remove<commit_after>import unittest

from bs4 import BeautifulSoup
from sqlalchemy import and_

from knowledge_repo import KnowledgeRepository
from knowledge_repo.app.proxies import db_session
from knowledge_repo.app.models import Post


class PostTest(unittest.TestCase):

    def setUp(self):
        self.repo = KnowledgeRepository.for_uri('tests/test_repo', auto_create=True)
        self.app = self.repo.get_app(config='tests/config_server.py')
        self.client = self.app.test_client()

        with self.app.app_context():
            # for this test, pick one post
            post = (db_session.query(Post)
                              .filter(Post.is_published)
                              .first())
            self.post_id = post.id
            self.post_rendered_url = '/post/{}'.format(post.path)

    def test01_check_render_route(self):
        """
        Check post path will render in /post/<path>
        """
        rv = self.client.get(self.post_rendered_url)
        assert rv.status == "200 OK"

    def test02_check_post_stats(self):
        """
        Make sure pageview, distinct viewers correct for post
        """
        rv = self.client.get(self.post_rendered_url)

        data = rv.data.decode('utf-8')
        soup = BeautifulSoup(data, 'html.parser')

        # we'll check the post_stats of the post by computing them
        # and ensuring that the upper-right-hand text is correct
        icon = soup.findAll("div", {"id": "pageview_stats"})
        pageviews_str = icon[0].text.strip()

        with self.app.app_context():
            post = Post.query.get(self.post_id)
            distinct_viewers = post.view_user_count
            pageviews = post.view_count

        db_pageviews_str = "Viewed {pageviews} times by {distinct_viewers} different users".format(**locals())

{'fraction_non_alphanumeric': 0.10182412197114075, 'fraction_numerical': 0.005445140212360468, 'mean_word_length': 2.3955637707948245, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, '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': '5073654', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1054, 'n_words': 243}