<commit_before>from django.test import TestCase, Client
from suggestions.models import DummyModel, SecondDummyModel
from .models import ObjectView, ObjectViewDictionary
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User


class SuggestionsTestCase(TestCase):

    def setUp(self):
        self.client = Client()
        User.objects.create_user(username='johndoe', password='<PASSWORD>')
        self.client.login(username='johndoe', password='<PASSWORD>')
        DummyModel.objects.create(name="Test")
        DummyModel.objects.create(name="Test2")
        SecondDummyModel.objects.create(name="Test2")

    def test_ensure_object_view_updated(self):
        init_view_count = ObjectView.objects.all().count()
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 1}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(ObjectView.objects.all().count(), init_view_count + 1)

    def test_ensure_dictionary_created(self):
        init_view_count = ObjectView.objects.all().count()
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 1}))
        self.assertEqual(response.status_code, 200)
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 2}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(ObjectView.objects.all().count(), init_view_count + 2)
        self.assertEqual(ObjectViewDictionary.objects.all().count(), 1)

    def test_ensure_dictionary_updated(self):
        init_view_count = ObjectView.objects.all().count()
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 1}))
        self.assertEqual(response.status_code, 200)
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 2}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(ObjectView.objects.all().count(), init_view_count + 2)
        self.assertEqual(ObjectViewDictionary.objects.all().count(), 1)
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 2}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(ObjectViewDictionary.objects.all().count(), 1)
        view_count = ObjectViewDictionary.objects.get(
            current_object_id=2).visits
        self.assertEqual(view_count, 2)

    def test_ensure_dictionary_not_created(self):
        init_dictionary_count = ObjectViewDictionary.objects.all().count()
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 1}))
        response = self.client.get(
            reverse('dummy2-detail', kwargs={'pk': 1}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            ObjectViewDictionary.objects.all().count(),
            init_dictionary_count)<commit_msg>Updated the test for dictionary<commit_after>from django.test import TestCase, Client
from suggestions.models import DummyModel, SecondDummyModel
from .models import ObjectView, ObjectViewDictionary
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User


class SuggestionsTestCase(TestCase):

    def setUp(self):
        self.client = Client()
        User.objects.create_user(username='johndoe', password='<PASSWORD>')
        self.client.login(username='johndoe', password='<PASSWORD>')
        DummyModel.objects.create(name="Test")
        DummyModel.objects.create(name="Test2")
        SecondDummyModel.objects.create(name="Test2")

    def test_ensure_object_view_updated(self):
        init_view_count = ObjectView.objects.all().count()
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 1}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(ObjectView.objects.all().count(), init_view_count + 1)

    def test_ensure_dictionary_created(self):
        init_view_count = ObjectView.objects.all().count()
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 1}))
        self.assertEqual(response.status_code, 200)
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 2}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(ObjectView.objects.all().count(), init_view_count + 2)
        self.assertEqual(ObjectViewDictionary.objects.all().count(), 1)

    def test_ensure_dictionary_updated(self):
        init_view_count = ObjectView.objects.all().count()
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 1}))
        self.assertEqual(response.status_code, 200)
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 2}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(ObjectView.objects.all().count(), init_view_count + 2)
        self.assertEqual(ObjectViewDictionary.objects.all().count(), 2)
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 2}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(ObjectViewDictionary.objects.all().count(), 2)
        view_count = ObjectViewDictionary.objects.get(
            current_object_id=2).visits
        self.assertEqual(view_count, 2)

    def test_ensure_dictionary_not_created(self):
        init_dictionary_count = ObjectViewDictionary.objects.all().count()
        response = self.client.get(
            reverse('dummy-detail', kwargs={'pk': 1}))
        response = self.client.get(
            reverse('dummy2-detail', kwargs={'pk': 1}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            ObjectViewDictionary.objects.all().count(),
            init_dictionary_count)
{'fraction_non_alphanumeric': 0.129553264604811, 'fraction_numerical': 0.013745704467353952, 'mean_word_length': 3.2832965415746873, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2090246', 'n_tokens_mistral': 1669, 'n_tokens_neox': 1605, 'n_words': 261}