<commit_before>""" Test cases for the user profile data """

from tentd import db
from tentd.documents.entity import Entity
from tentd.documents.profiles import CoreProfile
from tentd.tests import TentdTestCase, EntityTentdTestCase

class EntityTest(EntityTentdTestCase):
    def test_create_entity(self):
        """Test creating and accessing an Entity"""
        assert self.entity == Entity.objects.get(name="testuser")

    def test_create_identical_entity(self):
        """Check that properly inserting a document does not overwrite an
        existing one"""
        with self.assertRaises(db.NotUniqueError):
            entity = Entity(name="testuser")
            entity.save()

def CoreProfileTest(TentdTestCase):
    def test_core_profile(self):
        self.entity = Entity(name="testuser")
        self.entity.save()
        
        with self.assertRaises(Exception):
            core = self.entity.core
<commit_msg>Added a test for cascading deletions<commit_after>""" Test cases for the user profile data """

from tentd import db
from tentd.documents import Entity, CoreProfile, Post
from tentd.tests import TentdTestCase, EntityTentdTestCase

class EntityTest(EntityTentdTestCase):
    def test_create_entity(self):
        """Test creating and accessing an Entity"""
        assert self.entity == Entity.objects.get(name="testuser")

    def test_create_identical_entity(self):
        """Check that properly inserting a document does not overwrite an
        existing one"""
        with self.assertRaises(db.NotUniqueError):
            entity = Entity(name="testuser")
            entity.save()

class CoreProfileTest(TentdTestCase):
    def test_core_profile(self):
        self.entity = Entity(name="testuser")
        self.entity.save()

        with self.assertRaises(Exception):
            print self.entity.core

class DeletionTest(TentdTestCase):
    """Test cascading deletes"""

    def test_post_delete(self):
        self.entity = Entity(name="testuser").save()
        self.post = Post(
            entity=self.entity,
            schema="http://example.com/thisisnotrelevant",
            content={'a': 'b'}).save()

        assert self.post in Post.objects
        assert self.post in self.entity.posts
        
        self.entity.delete(safe=True)

        assert self.post not in Post.objects

{'fraction_non_alphanumeric': 0.09721627408993576, 'fraction_numerical': 0.0, 'mean_word_length': 3.0555555555555554, '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': '4312529', 'n_tokens_mistral': 642, 'n_tokens_neox': 622, 'n_words': 168}