<commit_before># This file is part of Indico.
# Copyright (C) 2002 - 2016 European Organization for Nuclear Research (CERN).
#
# Indico is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# Indico is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Indico; if not, see <http://www.gnu.org/licenses/>.

import pytest

from indico.modules.events import Event
from indico.testing.mocks import MockConference, MockConferenceHolder
from MaKaC.conference import ConferenceHolder


@pytest.yield_fixture
def create_event(monkeypatch, monkeypatch_methods, mocker, dummy_user, db):
    """Returns a callable which lets you create dummy events"""
    mocker.patch('MaKaC.conference.CategoryManager')
    monkeypatch_methods('MaKaC.conference.ConferenceHolder', MockConferenceHolder)
    monkeypatch.setattr('MaKaC.conference.Conference', MockConference)  # for some isinstance checks

    _events = []
    ch = ConferenceHolder()

    def _create_event(id_=None, legacy=False):
        conf = MockConference()
        # we specify `acl_entries` so SA doesn't load it when accessing it for
        # the first time, which would require no_autoflush blocks in some cases
        conf.as_event = Event(id=id_, creator=dummy_user, acl_entries=set(), category_id=1)
        conf.as_event.category_chain = [1, 0]  # set after __init__ (setting category_id modifies it)
        db.session.flush()
        conf.id = str(conf.as_event.id)
        ch.add(conf)
        _events.append(conf)
        return conf if legacy else conf.as_event

    yield _create_event

    for event in _events:
        ch.remove(event)


@pytest.fixture
def dummy_event(create_event):
    """Creates a mocked dummy event"""
    return create_event('0', legacy=True)


@pytest.fixture
def dummy_event_new(create_event):
    """Creates a mocked dummy event"""<commit_msg>Fix event creation in tests<commit_after># This file is part of Indico.
# Copyright (C) 2002 - 2016 European Organization for Nuclear Research (CERN).
#
# Indico is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.
#
# Indico is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Indico; if not, see <http://www.gnu.org/licenses/>.

from datetime import timedelta

import pytest

from indico.modules.events import Event
from indico.testing.mocks import MockConference, MockConferenceHolder
from indico.util.date_time import now_utc
from MaKaC.conference import ConferenceHolder


@pytest.yield_fixture
def create_event(monkeypatch, monkeypatch_methods, mocker, dummy_user, db):
    """Returns a callable which lets you create dummy events"""
    mocker.patch('MaKaC.conference.CategoryManager')
    monkeypatch_methods('MaKaC.conference.ConferenceHolder', MockConferenceHolder)
    monkeypatch.setattr('MaKaC.conference.Conference', MockConference)  # for some isinstance checks

    _events = []
    ch = ConferenceHolder()

    def _create_event(id_=None, legacy=False):
        conf = MockConference()
        # we specify `acl_entries` so SA doesn't load it when accessing it for
        # the first time, which would require no_autoflush blocks in some cases
        now = now_utc(exact=False)
        conf.as_event = Event(id=id_, creator=dummy_user, acl_entries=set(), category_id=1, title='dummy#{}'.format(id),
                              start_dt=now, end_dt=now + timedelta(hours=1), timezone='UTC')
        conf.as_event.category_chain = [1, 0]  # set after __init__ (setting category_id modifies it)
        db.session.flush()
        conf.id = str(conf.as_event.id)
        ch.add(conf)
        _events.append(conf)
        return conf if legacy else conf.as_event

    yield _create_event

    for event in _events:
        ch.remove(event)


@pytest.fixture
def dummy_event(create_event):
    """Creates a mocked dummy event"""
    return create_event('0', legacy=True)


@pytest.fixture
def dummy_event_new(create_event):
    """Creates a mocked dummy event"""
{'fraction_non_alphanumeric': 0.08275862068965517, 'fraction_numerical': 0.005642633228840125, 'mean_word_length': 3.9238683127572016, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7535564', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1364, 'n_words': 490}