diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-10-16 15:28:48 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-02-19 14:43:48 +0100 |
commit | b8eef9b6aaed7ee097f8ea86174067f9ca42abd8 (patch) | |
tree | a4befe6351f6992a42482343f50f5c7b5fe4a2ea /ishtar_common | |
parent | e0a3b8644c35ccc7635d16a423ba71526b4d8f3b (diff) | |
download | Ishtar-b8eef9b6aaed7ee097f8ea86174067f9ca42abd8.tar.bz2 Ishtar-b8eef9b6aaed7ee097f8ea86174067f9ca42abd8.zip |
✅ fix tests
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models.py | 8 | ||||
-rw-r--r-- | ishtar_common/tests.py | 14 |
2 files changed, 12 insertions, 10 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 826b9000f..5f57e8398 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -1593,9 +1593,13 @@ class IshtarSiteProfile(models.Model, Cached): return value q = cls.objects.filter(active=True) if not q.count(): - obj = cls.objects.create( - label="Default profile", slug="default", active=True + obj, created = cls.objects.get_or_create( + slug="default", + defaults={"label": "Default profile", "active": True} ) + if not created: + obj.active = True + obj.save() else: obj = q.all()[0] cache.set(cache_key, obj, settings.CACHE_TIMEOUT) diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index f9c928d5e..2a8983048 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -17,16 +17,13 @@ # See the file COPYING for details. from bs4 import BeautifulSoup as Soup -import re import csv -import copy import datetime import importlib import io import json import os import shutil -import sys import tempfile from time import time import zipfile @@ -56,7 +53,7 @@ from django.core.management import call_command from django.db.models.fields import BooleanField from django.db.models.fields.related import ForeignKey from django.template.defaultfilters import slugify -from django.test import tag, TestCase as BaseTestCase +from django.test import TestCase as BaseTestCase from django.test.client import Client from django.test.runner import DiscoverRunner from django.utils.translation import ugettext_lazy as _ @@ -65,7 +62,6 @@ from django.urls import reverse from ishtar_common import models, models_common, forms_common from ishtar_common import views from ishtar_common.apps import admin_site -from ishtar_common.models_imports import Import, ImporterType from ishtar_common.serializers import ( type_serialization, SERIALIZATION_VERSION, @@ -2236,7 +2232,7 @@ class ShortMenuTest(TestCase): self.other_user = User.objects.create_superuser( "John", "nomail@nomail.com", self.password ) - profile = models.get_current_profile() + profile = models.get_current_profile(force=True) profile.files = True profile.context_record = True profile.find = True @@ -3402,9 +3398,11 @@ class IshtarSiteProfileTest(TestCase): cache.set( "default-ishtar_common-IshtarSiteProfile", None, settings.CACHE_TIMEOUT ) - self.assertFalse(models.IshtarSiteProfile.objects.count()) + for isp in models.IshtarSiteProfile.objects.all(): + isp.delete() profile = models.get_current_profile(force=True) self.assertTrue(profile) + self.assertTrue(profile.active) self.assertEqual(models.IshtarSiteProfile.objects.count(), 1) def test_menu_filtering(self): @@ -3425,7 +3423,7 @@ class IshtarSiteProfileTest(TestCase): self.assertIn(b'href="/file_search/"', response.content) def testExternalKey(self): - profile = models.get_current_profile() + profile = models.get_current_profile(force=True) p = models.Person.objects.create(name="plouf", surname="Tégada") self.assertEqual(p.raw_name, "PLOUF Tégada") profile.person_raw_name = "{surname|slug} {name}" |