<commit_before>"""
sentry.testutils.fixtures
~~~~~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2010-2014 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
from __future__ import unicode_literals

from exam import fixture
from sentry.models import Activity, Event, Group, Project, Team, User
from sentry.utils.compat import pickle
from sentry.utils.strings import decompress
from django.utils.text import slugify

# an example data blog from Sentry 5.4.1 (db level)
LEGACY_DATA = pickle.loads(decompress("""eJy9WW1v20YS/<KEY>""))


class Fixtures(object):
    @fixture
    def projectkey(self):
        return self.project.key_set.get_or_create(user=self.user)[0]

    @fixture
    def user(self):
        return self.create_user('admin@localhost', username='admin')

    @fixture
    def team(self):
        return self.create_team(
            name='foo',
            slug='foo',
            owner=self.user)

    @fixture
    def project(self):
        return self.create_project(
            name='Bar',
            slug='bar',
            team=self.team,
            owner=self.user,
        )

    @fixture
    def group(self):
        return self.create_group()

    @fixture
    def event(self):
        return self.create_event(event_id='a' * 32)

    @fixture
    def activity(self):
        return Activity.objects.create(
            group=self.group, event=self.event, project=self.project,
            type=Activity.NOTE, user=self.user,
            data={}
        )

    def create_team(self, **kwargs):
        kwargs.setdefault('name', 'foo')
        if not kwargs.get('slug'):
            kwargs['slug'] = slugify(unicode(kwargs['name']))
        if not kwargs.get('owner'):
            kwargs['owner'] = self.user

        return Team.objects.create(**kwargs)

    def create_project(self, **kwargs):
        kwargs.setdefault('name', 'Bar')
        if not kwargs.get('slug'):
            kwargs['slug'] = slugify(unicode(kwargs['name']))
        if not kwargs.get('team'):
            kwargs['team'] = self.team
        if not kwargs.get('owner'):
            kwargs['owner'] = kwargs['team'].owner

        return Project.objects.create(**kwargs)

    def create_user(self, email, **kwargs):
        kwargs.setdefault('username', email)
        kwargs.setdefault('is_staff', True)
        kwargs.setdefault('is_superuser', True)

        user = User(email=email, **kwargs)
        user.set_password('<PASSWORD>')
        user.save()

        return user

    def create_event(self, event_id, **kwargs):
        if 'group' not in kwargs:
            kwargs['group'] = self.group
        kwargs.setdefault('project', kwargs['group'].project)
        kwargs.setdefault('message', kwargs['group'].message)
        kwargs.setdefault('data', LEGACY_DATA)

        return Event.objects.create(
            event_id=event_id,
            **kwargs
        )

    def create_group(self, project=None, **kwargs):
        return Group.objects.create(
            message='Foo bar',
            project=project or self.project,
            **kwargs
        )<commit_msg>Slight improvements to fixtures<commit_after>"""
sentry.testutils.fixtures
~~~~~~~~~~~~~~~~~~~~~~~~~

:copyright: (c) 2010-2014 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
from __future__ import unicode_literals

from exam import fixture
from uuid import uuid4

from sentry.models import Activity, Event, Group, Project, Team, User
from sentry.utils.compat import pickle
from sentry.utils.strings import decompress
from django.utils.text import slugify

# an example data blog from Sentry 5.4.1 (db level)
LEGACY_DATA = pickle.loads(decompress("""eJy9WW1v20YS/<KEY>""))


class Fixtures(object):
    @fixture
    def projectkey(self):
        return self.project.key_set.get_or_create(user=self.user)[0]

    @fixture
    def user(self):
        return self.create_user('admin@localhost', username='admin')

    @fixture
    def team(self):
        return self.create_team(
            name='foo',
            slug='foo',
            owner=self.user)

    @fixture
    def project(self):
        return self.create_project(
            name='Bar',
            slug='bar',
            team=self.team,
            owner=self.user,
        )

    @fixture
    def group(self):
        return self.create_group(message='Foo bar')

    @fixture
    def event(self):
        return self.create_event(event_id='a' * 32)

    @fixture
    def activity(self):
        return Activity.objects.create(
            group=self.group, event=self.event, project=self.project,
            type=Activity.NOTE, user=self.user,
            data={}
        )

    def create_team(self, **kwargs):
        kwargs.setdefault('name', 'foo')
        if not kwargs.get('slug'):
            kwargs['slug'] = slugify(unicode(kwargs['name']))
        if not kwargs.get('owner'):
            kwargs['owner'] = self.user

        return Team.objects.create(**kwargs)

    def create_project(self, **kwargs):
        kwargs.setdefault('name', 'Bar')
        if not kwargs.get('slug'):
            kwargs['slug'] = slugify(unicode(kwargs['name']))
        if not kwargs.get('team'):
            kwargs['team'] = self.team
        if not kwargs.get('owner'):
            kwargs['owner'] = kwargs['team'].owner

        return Project.objects.create(**kwargs)

    def create_user(self, email, **kwargs):
        kwargs.setdefault('username', email)
        kwargs.setdefault('is_staff', True)
        kwargs.setdefault('is_superuser', True)

        user = User(email=email, **kwargs)
        user.set_password('<PASSWORD>')
        user.save()

        return user

    def create_event(self, event_id, **kwargs):
        if 'group' not in kwargs:
            kwargs['group'] = self.group
        kwargs.setdefault('project', kwargs['group'].project)
        kwargs.setdefault('message', kwargs['group'].message)
        kwargs.setdefault('data', LEGACY_DATA)

        return Event.objects.create(
            event_id=event_id,
            **kwargs
        )

    def create_group(self, project=None, **kwargs):
        kwargs.setdefault('message', 'Hello world')
        kwargs.setdefault('checksum', uuid4().hex)
        return Group.objects.create(
            project=project or self.project,
            **kwargs
        )
{'fraction_non_alphanumeric': 0.13530058075655313, 'fraction_numerical': 0.005964526761889813, 'mean_word_length': 2.5204419889502763, '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': '6866256', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1841, 'n_words': 415}