<commit_before>import os
import sys
from retirement_api.models import AgeChoice, Question, Step, Page, Tooltip
import mock

from django.test import TestCase

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
sys.path.append(BASE_DIR)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

class ViewModels(TestCase):

    testcase = AgeChoice.objects.get(age=61)
    testquestion = Question.objects.all()[0]
    teststep = Step.objects.all()[0]
    testpage = Page.objects.all()[0]
    testtip = Tooltip.objects.all()[0]

    def test_get_subhed(self):
        tc = AgeChoice.objects.get(age=61)
        self.assertTrue("You've chosen age 61" in tc.get_subhed())

    def test_question_slug(self):
        question_slugger = Question(title='test q')
        question_slugger.save()
        self.assertTrue(question_slugger.slug == "test_q")
        question_slugger.delete()

    def test_question_translist(self):
        tlist = self.testquestion.translist()
        self.assertTrue(type(tlist) == list)
        for term in ['question', 'answer_yes_a', 'answer_no_b', 'answer_unsure_a_subhed']:
            self.assertTrue(term in tlist)

    def test_quesiton_dump(self):
        dumplist = self.testquestion.dump_translation_text()
        self.assertTrue(type(dumplist) == list)
        outfile = "/tmp/%s.po" % self.testquestion.slug
        self.testquestion.dump_translation_text(output=True)
        self.assertTrue(os.path.isfile(outfile))

    def test_agechoice_translist(self):
        tlist = self.testcase.translist()
        self.assertTrue(type(tlist) == list)

    def test_step_translist(self):
        tlist = self.teststep.translist()
        self.assertTrue(type(tlist) == list)

    def test_page_translist(self):
        tlist = self.testpage.translist()
        self.assertTrue(type(tlist) == list)

    def test_tooltip_translist(self):
        tlist = self.testtip.translist()
        self.assertTrue(type(tlist) == list)
<commit_msg>use mock in testing output function<commit_after>import os
import sys
from retirement_api.models import AgeChoice, Question, Step, Page, Tooltip
import mock

from django.test import TestCase

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
sys.path.append(BASE_DIR)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

class ViewModels(TestCase):

    testcase = AgeChoice.objects.get(age=61)
    testquestion = Question.objects.all()[0]
    teststep = Step.objects.all()[0]
    testpage = Page.objects.all()[0]
    testtip = Tooltip.objects.all()[0]

    def test_get_subhed(self):
        tc = AgeChoice.objects.get(age=61)
        self.assertTrue("You've chosen age 61" in tc.get_subhed())

    def test_question_slug(self):
        question_slugger = Question(title='test q')
        question_slugger.save()
        self.assertTrue(question_slugger.slug == "test_q")
        question_slugger.delete()

    def test_question_translist(self):
        tlist = self.testquestion.translist()
        self.assertTrue(type(tlist) == list)
        for term in ['question', 'answer_yes_a', 'answer_no_b', 'answer_unsure_a_subhed']:
            self.assertTrue(term in tlist)

    def test_quesiton_dump(self):
        dumplist = self.testquestion.dump_translation_text()
        self.assertTrue(type(dumplist) == list)
        # outfile = "/tmp/%s.po" % self.testquestion.slug
        # self.testquestion.dump_translation_text(output=True)
        # self.assertTrue(os.path.isfile(outfile))

    def test_question_dump_mock_output(self):
        open_name = '%s.open' % __name__
        with mock.patch(open_name, create=True) as mock_open:
            mock_open.return_value = mock.MagicMock(spec=file)
            self.testquestion.dump_translation_text(output=True)
            file_handle = mock_open.return_value.__enter__.return_value
            file_handle.write.assert_call_count==5

    def test_agechoice_translist(self):
        tlist = self.testcase.translist()
        self.assertTrue(type(tlist) == list)

    def test_step_translist(self):
        tlist = self.teststep.translist()
        self.assertTrue(type(tlist) == list)

    def test_page_translist(self):
        tlist = self.testpage.translist()
        self.assertTrue(type(tlist) == list)

    def test_tooltip_translist(self):
        tlist = self.testtip.translist()
        self.assertTrue(type(tlist) == list)

{'fraction_non_alphanumeric': 0.11827468785471056, 'fraction_numerical': 0.004767309875141884, 'mean_word_length': 3.46403242147923, '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': '4314600', 'n_tokens_mistral': 1417, 'n_tokens_neox': 1418, 'n_words': 231}