<commit_before>from django.test import TestCase, Client, RequestFactory
from django.urls import reverse_lazy

from texts.models import Text
from texts.views import TextView, decode_request_body, ProcessHookView

import datetime

class TextTestCase(TestCase):
    """The Text app test runner."""

    def setUp(self):
        """Text test setup."""
        self.client = Client()
        self.request = RequestFactory()

    def test_add_text_model(self):
        """Test that adding a text model works."""
        text1 = Text(body="Jabba no watta.", sender="them")
        text1.save()
        self.assertTrue(Text.objects.count() == 1)

    def test_add_two_text_models(self):
        """Test that adding two text models works."""
        text1 = Text(body="Jabba no watta.", sender="them")
        text1.save()
        text2 = Text(body="Too Nakma Noya Solo!", sender="you")
        text2.save()
        self.assertTrue(Text.objects.count() == 2)

    def test_image_body(self):
        """Test that text instance has correct body."""
        text1 = Text(body="Jabba no watta.", sender="them")
        text1.save()
        self.assertTrue(Text.objects.first().body == "Jabba no watta.")

    def test_image_time_format(self):
        """Test that text instance has correct time format."""
        text1 = Text(body="Jabba no watta.", sender="them")
        text1.save()
        # import pdb; pdb.set_trace()
        self.assertTrue(isinstance(Text.objects.first().time, datetime.datetime))

    def test_text_repr_is_body(self):
        """Test that texts are properly represented."""
        text1 = Text(body="No bata tu tu, muni, muni.", sender="them")
        text1.save()
        self.assertTrue(text1.__str__() == text1.body[:20])
    
    # def test_text_view_returns_text(self):
    #     """Test that text view returns a text."""
    #     text1 = Text(body="Jabba no watta.", sender="them")
    #     text1.save()
    #     text2 = Text(body="Too Nakma Noya Solo!", sender="you")
    #     text2.save()
    #     view = TextView.as_view()
    #     req = self.request.get(reverse_lazy('texts'))
    #     response = view(req)
    #     self.assertTrue(response.context_data['texts'].count() == 2)

    # def test_text_view_returns_two_texts(self):
    #     """Test that text view returns two texts."""
    #     text1 = Text(body="Jabba no watta.", sender="them")
    #     text1.save()
    #     view = TextView.as_view()
    #     req = self.request.get(reverse_lazy('texts'))
    #     response = view(req)
    #     self.assertTrue(response.context_data['texts'].count() == 1)

    # def test_text_view_status_200(self):
    #     """Test that text view returns ok status."""
    #     text1 = Text(body="Jabba no watta.", sender="them")
    #     text1.save()<commit_msg>slightly modified test for text_view<commit_after>from django.test import TestCase, Client, RequestFactory
from django.urls import reverse_lazy

from texts.models import Text
from texts.views import TextView, decode_request_body, ProcessHookView

import datetime

class TextTestCase(TestCase):
    """The Text app test runner."""

    def setUp(self):
        """Text test setup."""
        self.client = Client()
        self.request = RequestFactory()

    def test_add_text_model(self):
        """Test that adding a text model works."""
        text1 = Text(body="Jabba no watta.", sender="them")
        text1.save()
        self.assertTrue(Text.objects.count() == 1)

    def test_add_two_text_models(self):
        """Test that adding two text models works."""
        text1 = Text(body="Jabba no watta.", sender="them")
        text1.save()
        text2 = Text(body="Too Nakma Noya Solo!", sender="you")
        text2.save()
        self.assertTrue(Text.objects.count() == 2)

    def test_image_body(self):
        """Test that text instance has correct body."""
        text1 = Text(body="Jabba no watta.", sender="them")
        text1.save()
        self.assertTrue(Text.objects.first().body == "Jabba no watta.")

    def test_image_time_format(self):
        """Test that text instance has correct time format."""
        text1 = Text(body="Jabba no watta.", sender="them")
        text1.save()
        # import pdb; pdb.set_trace()
        self.assertTrue(isinstance(Text.objects.first().time, datetime.datetime))

    def test_text_repr_is_body(self):
        """Test that texts are properly represented."""
        text1 = Text(body="No bata tu tu, muni, muni.", sender="them")
        text1.save()
        self.assertTrue(text1.__str__() == text1.body[:20])

    # def test_text_view_returns_text(self):
    #     """Test that text view returns a text."""
    #     text1 = Text(body="Jabba no watta.", sender="them")
    #     text1.save()
    #     text2 = Text(body="Too Nakma Noya Solo!", sender="you")
    #     text2.save()
    #     view = TextView.as_view()
    #     req = self.request.get(reverse_lazy('texts', kwargs={"pk": "1"}))
    #     import pdb; pdb.set_trace()
    #     response = view(req)
    #     self.assertTrue(response.context_data['texts'].count() == 2)

    # def test_text_view_returns_two_texts(self):
    #     """Test that text view returns two texts."""
    #     text1 = Text(body="Jabba no watta.", sender="them")
    #     text1.save()
    #     view = TextView.as_view()
    #     req = self.request.get(reverse_lazy('texts'))
    #     response = view(req)
    #     self.assertTrue(response.context_data['texts'].count() == 1)

    # def test_text_view_status_200(self):
    #     """Test that text view returns ok status."""
    #     text1 = Text(body="Jabba no watta.", sender="them")
    #     text1.save()
{'fraction_non_alphanumeric': 0.14419508747128468, 'fraction_numerical': 0.011132708959180067, 'mean_word_length': 2.8140161725067387, 'pattern_counts': {'":': 1, '<': 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': '620954', 'n_tokens_mistral': 1790, 'n_tokens_neox': 1754, 'n_words': 420}