<commit_before>import pytest
from filer.models import Folder, Image

from shoop.core.models import Shop, ShopStatus
from shoop.testing.factories import DEFAULT_IDENTIFIER, DEFAULT_NAME


@pytest.mark.django_db
def test_shop_wont_be_deleted():
    shop = Shop.objects.create(
        name=DEFAULT_NAME,
        identifier=DEFAULT_IDENTIFIER,
        status=ShopStatus.ENABLED,
        public_name=DEFAULT_NAME
    )

    folder = Folder.objects.create(name="Root")
    img = Image.objects.create(name="imagefile", folder=folder)

    shop.logo = img
    shop.save()
    img.delete()

    Shop.objects.get(pk=shop.pk)<commit_msg>Add tests for translating shops<commit_after>import parler.appsettings
import pytest
from filer.models import Folder, Image

from shoop.core.models import Shop, ShopStatus
from shoop.testing.factories import DEFAULT_IDENTIFIER, DEFAULT_NAME


caching_was_enabled = None


def setup_module(module):
    # override_settings does to work with parler, since it does not read
    # django.conf.settings but parler.appsettings
    global caching_was_enabled
    caching_was_enabled = parler.appsettings.PARLER_ENABLE_CACHING
    parler.appsettings.PARLER_ENABLE_CACHING = False


def teardown_module(module):
    parler.appsettings.PARLER_ENABLE_CACHING = caching_was_enabled


@pytest.mark.django_db
def test_shop_wont_be_deleted():
    shop = Shop.objects.create(
        name=DEFAULT_NAME,
        identifier=DEFAULT_IDENTIFIER,
        status=ShopStatus.ENABLED,
        public_name=DEFAULT_NAME
    )

    folder = Folder.objects.create(name="Root")
    img = Image.objects.create(name="imagefile", folder=folder)

    shop.logo = img
    shop.save()
    img.delete()

    Shop.objects.get(pk=shop.pk)


@pytest.mark.django_db
def test_shop_translations_get_saved():
    obj = Shop.objects.language('en').create(name="Store")
    obj.set_current_language('fi')
    obj.name = "Liike"
    assert set(obj.get_available_languages(include_unsaved=True)) == set(['en', 'fi'])
    assert set(obj.get_available_languages()) == set(['en'])
    obj.save()
    assert set(obj.get_available_languages()) == set(['en', 'fi'])
    assert Shop.objects.language('en').get(pk=obj.pk).name == "Store"
    assert Shop.objects.language('fi').get(pk=obj.pk).name == "Liike"


@pytest.mark.django_db
def test_shop_translations_manager():
    shop = Shop.objects.language('en').create(name="Store")
    shop.set_current_language('fi')
    shop.name = "Liike"
    shop.save()

    found = Shop.objects.language('fi').get(pk=shop.pk)
    assert found == shop
    assert found.name == "Liike"

    found = Shop.objects.language('en').get(pk=shop.pk)
    assert found == shop
    assert found.name == "Store"

    found = Shop.objects.translated('fi', name="Liike").get(pk=shop.pk)
    assert found == shop

    found = Shop.objects.translated('en', name="Store").get(pk=shop.pk)
    assert found == shop
{'fraction_non_alphanumeric': 0.12431129476584023, 'fraction_numerical': 0.0, 'mean_word_length': 4.0964912280701755, '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': '3603617', 'n_tokens_mistral': 951, 'n_tokens_neox': 939, 'n_words': 168}