<commit_before>import json
import hashlib

from django.test import TestCase
from django.test import Client
from django.test.utils import override_settings
from django.urls import reverse
from django.contrib.auth import get_user_model

from rest_framework import status
from rest_framework.test import APIClient

from journal import models, serializers


User = get_user_model()


class BaseTestCase(TestCase):
    def setUp(self):
        self.user1 = User.objects.create(username='user1')
        self.user2 = User.objects.create(username='user2')
        self.client = APIClient()
        self.raw_client = Client()
        self.random_hash_seed = 1

    def get_random_hash(self):
        """Not really random, generates a sha256 hash that is consistent across runs"""
        ret = hashlib.sha256(bytes(self.random_hash_seed)).hexdigest()
        self.random_hash_seed = self.random_hash_seed + 1
        return ret


class ApiJournalTestCase(BaseTestCase):
    def setUp(self):
        super().setUp()
        self.serializer = serializers.JournalSerializer

    def test_only_owner(self):
        """Check all the endpoints correctly require authentication"""
        journal = models.Journal(owner=self.user1, uid=self.get_random_hash(), content=b'test')
        journal.save()

        # List
        self.client.force_authenticate(user=self.user1)
        response = self.client.get(reverse('journal-list'))
        self.assertEqual(response.status_code, status.HTTP_200_OK)<commit_msg>Tests: Add email to user init.<commit_after>import json
import hashlib

from django.test import TestCase
from django.test import Client
from django.test.utils import override_settings
from django.urls import reverse
from django.contrib.auth import get_user_model

from rest_framework import status
from rest_framework.test import APIClient

from journal import models, serializers


User = get_user_model()


class BaseTestCase(TestCase):
    def setUp(self):
        self.user1 = User.objects.create(username='user1', email='user<EMAIL>')
        self.user2 = User.objects.create(username='user2', email='<EMAIL>')
        self.client = APIClient()
        self.raw_client = Client()
        self.random_hash_seed = 1

    def get_random_hash(self):
        """Not really random, generates a sha256 hash that is consistent across runs"""
        ret = hashlib.sha256(bytes(self.random_hash_seed)).hexdigest()
        self.random_hash_seed = self.random_hash_seed + 1
        return ret


class ApiJournalTestCase(BaseTestCase):
    def setUp(self):
        super().setUp()
        self.serializer = serializers.JournalSerializer

    def test_only_owner(self):
        """Check all the endpoints correctly require authentication"""
        journal = models.Journal(owner=self.user1, uid=self.get_random_hash(), content=b'test')
        journal.save()

        # List
        self.client.force_authenticate(user=self.user1)
        response = self.client.get(reverse('journal-list'))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
{'fraction_non_alphanumeric': 0.09458128078817735, 'fraction_numerical': 0.01116584564860427, 'mean_word_length': 3.650381679389313, 'pattern_counts': {'":': 0, '<': 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': '3165933', 'n_tokens_mistral': 874, 'n_tokens_neox': 850, 'n_words': 208}