<commit_before>import pytest

from adhocracy4.actions.models import Action
from adhocracy4.actions.signals import _add_action, _delete_action
from adhocracy4.actions.verbs import Verbs


@pytest.mark.django_db
def test_project_create(project_factory):
    project = project_factory()
    _add_action(None, project, True)
    action = Action.objects.first()
    assert action.actor is None
    assert action.obj == project
    assert action.verb == Verbs.CREATE.value
    assert action.target is None


@pytest.mark.django_db
def test_item_add(question_factory):
    question = question_factory()
    _add_action(None, question, True)
    action = Action.objects.last()
    assert action.actor == question.creator
    assert action.obj == question
    assert action.verb == Verbs.ADD.value
    assert action.target == question.project
    assert action.project == question.project


@pytest.mark.django_db
def test_item_update(question_factory):
    question = question_factory()
    _add_action(None, question, False)
    action = Action.objects.last()
    assert action.actor == question.creator
    assert action.obj == question
    assert action.verb == Verbs.UPDATE.value
    assert action.target is None
    assert action.project == question.project


@pytest.mark.django_db
def test_item_delete(question_factory):
    question = question_factory()
    _add_action(question_factory._meta.model, question, False)
    _delete_action(question_factory._meta.model, question)
    assert Action.objects.all().count() == 0


@pytest.mark.django_db
def test_content_object_create(question_factory, comment_factory):
    question = question_factory()
    comment = comment_factory(content_object=question)
    _add_action(None, comment, True)
    action = Action.objects.last()
    assert action.actor == comment.creator
    assert action.obj == comment
    assert action.verb == Verbs.ADD.value
    assert action.target == question
    assert action.project == comment.project


@pytest.mark.django_db
def test_content_object_update(question_factory, comment_factory):
    question = question_factory()
    comment = comment_factory(content_object=question)
    _add_action(None, comment, False)
    action = Action.objects.last()<commit_msg>fix action signal tests after last_comment was added to update_fields<commit_after>import pytest

from adhocracy4.actions.models import Action
from adhocracy4.actions.signals import _add_action, _delete_action
from adhocracy4.actions.verbs import Verbs


@pytest.mark.django_db
def test_project_create(project_factory):
    project = project_factory()
    _add_action(None, project, True, None)
    action = Action.objects.first()
    assert action.actor is None
    assert action.obj == project
    assert action.verb == Verbs.CREATE.value
    assert action.target is None


@pytest.mark.django_db
def test_item_add(question_factory):
    question = question_factory()
    _add_action(None, question, True, None)
    action = Action.objects.last()
    assert action.actor == question.creator
    assert action.obj == question
    assert action.verb == Verbs.ADD.value
    assert action.target == question.project
    assert action.project == question.project


@pytest.mark.django_db
def test_item_update(question_factory):
    question = question_factory()
    _add_action(None, question, False, None)
    action = Action.objects.last()
    assert action.actor == question.creator
    assert action.obj == question
    assert action.verb == Verbs.UPDATE.value
    assert action.target is None
    assert action.project == question.project


@pytest.mark.django_db
def test_item_delete(question_factory):
    question = question_factory()
    _add_action(question_factory._meta.model, question, False, None)
    _delete_action(question_factory._meta.model, question)
    assert Action.objects.all().count() == 0


@pytest.mark.django_db
def test_content_object_create(question_factory, comment_factory):
    question = question_factory()
    comment = comment_factory(content_object=question)
    _add_action(None, comment, True, None)
    action = Action.objects.last()
    assert action.actor == comment.creator
    assert action.obj == comment
    assert action.verb == Verbs.ADD.value
    assert action.target == question
    assert action.project == comment.project


@pytest.mark.django_db
def test_content_object_update(question_factory, comment_factory):
    question = question_factory()
    comment = comment_factory(content_object=question)
    _add_action(None, comment, False, None)
    action = Action.objects.last()
{'fraction_non_alphanumeric': 0.09102844638949671, 'fraction_numerical': 0.00175054704595186, 'mean_word_length': 4.40307328605201, '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': '3077314', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1315, 'n_words': 302}