<commit_before>import pytest
from wagtail.wagtailcore.models import Site, Page

from bvspca.animals.management.commands.sync_petpoint_data import Command
from bvspca.animals.models import AnimalCountSettings


@pytest.mark.django_db(transaction=False)
def test_increment_animal_count():
    root_page = Page(title='test', path='test', depth=1)
    root_page.save()
    site = Site(hostname='www.example.com', root_page=root_page)
    site.save()
    count_settings = AnimalCountSettings(site_id=site.id)
    count_settings.save()
    for _ in range(1, 100):
        Command.increment_animal_count('Cat', 'adopted')
    count_settings.refresh_from_db()
    assert count_settings.cats_adopted == 99
    for _ in range(1, 10):
        Command.increment_animal_count('Cat', 'rescued')
    count_settings.refresh_from_db()
    assert count_settings.cats_rescued == 9
    for _ in range(1, 200):
        Command.increment_animal_count('Dog', 'adopted')
    count_settings.refresh_from_db()
    assert count_settings.dogs_adopted == 199
    for _ in range(1, 50):
        Command.increment_animal_count('Dog', 'rescued')
    count_settings.refresh_from_db()
    assert count_settings.dogs_rescued == 49<commit_msg>Add decrement animal count test<commit_after>import pytest
from wagtail.wagtailcore.models import Page, Site

from bvspca.animals.management.commands.sync_petpoint_data import Command
from bvspca.animals.models import AnimalCountSettings


@pytest.fixture(scope="module")
def animal_settings():
    root_page = Page(title='test', path='test', depth=1)
    root_page.save()
    site = Site(hostname='www.example.com', root_page=root_page)
    site.save()
    count_settings = AnimalCountSettings(site_id=site.id)
    count_settings.save()
    return count_settings


@pytest.mark.django_db(transaction=False)
def test_increment_animal_count(animal_settings):
    for _ in range(1, 100):
        Command.increment_animal_count('Cat', 'adopted')
        animal_settings.refresh_from_db()
    assert animal_settings.cats_adopted == 99
    for _ in range(1, 10):
        Command.increment_animal_count('Cat', 'rescued')
        animal_settings.refresh_from_db()
    assert animal_settings.cats_rescued == 9
    for _ in range(1, 200):
        Command.increment_animal_count('Dog', 'adopted')
        animal_settings.refresh_from_db()
    assert animal_settings.dogs_adopted == 199
    for _ in range(1, 50):
        Command.increment_animal_count('Dog', 'rescued')
        animal_settings.refresh_from_db()
    assert animal_settings.dogs_rescued == 49


@pytest.mark.django_db(transaction=False)
def test_decrement_animal_count(animal_settings):
    animal_settings.cats_adopted = 22
    animal_settings.cats_rescued = 44
    animal_settings.dogs_adopted = 55
    animal_settings.dogs_rescued = 66
    animal_settings.save()

    Command.increment_animal_count('Cat', 'adopted', -1)
    animal_settings.refresh_from_db()
    assert animal_settings.cats_adopted == 21
    Command.increment_animal_count('Dog', 'rescued', -1)
    animal_settings.refresh_from_db()
    assert animal_settings.dogs_rescued == 65
{'fraction_non_alphanumeric': 0.10289389067524116, 'fraction_numerical': 0.01929260450160772, 'mean_word_length': 4.585278276481149, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '515789', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1018, 'n_words': 174}