summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archaeological_context_records/tests.py21
-rw-r--r--archaeological_context_records/views.py2
-rw-r--r--archaeological_finds/tests.py8
-rw-r--r--archaeological_operations/views.py3
-rw-r--r--ishtar_common/models.py8
-rw-r--r--ishtar_common/tests.py14
6 files changed, 35 insertions, 21 deletions
diff --git a/archaeological_context_records/tests.py b/archaeological_context_records/tests.py
index da6bcfc30..efeab4670 100644
--- a/archaeological_context_records/tests.py
+++ b/archaeological_context_records/tests.py
@@ -1400,10 +1400,9 @@ class ContextRecordRelationTest(ContextRecordInit, TestCase):
user.user_permissions.add(
Permission.objects.get(codename="change_own_contextrecord")
)
- # by default associated to the first user
- self.create_context_record({"label": "CR 1"})
- self.create_context_record({"label": "CR 2"})
- self.create_context_record({"label": "CR 3"})
+ self.create_context_record({"label": "CR 1"}, user=user)
+ self.create_context_record({"label": "CR 2"}, user=user)
+ self.create_context_record({"label": "CR 3"}, user=user)
self.username2, self.password2, user2 = create_user( # nosec
username="Saroumane", password="ushallnotpass"
@@ -1484,7 +1483,9 @@ class ContextRecordRelationTest(ContextRecordInit, TestCase):
right_record=self.cr2,
relation_type=self.sym_rel_type
)
- nb_record_relation = models.RecordRelations.objects.filter(left_record=self.cr1).count()
+ nb_record_relation = models.RecordRelations.objects.filter(
+ left_record=self.cr1
+ ).count()
c.login(username=self.username, password=self.password)
data = self.init_data()
@@ -1494,12 +1495,18 @@ class ContextRecordRelationTest(ContextRecordInit, TestCase):
"form-0-relation_type": self.rel_type_below.pk,
"form-0-DELETE": "on"
})
- url = reverse("context-record-relation-modify", kwargs={"pk": self.context_records[0].pk})
+ url = reverse(
+ "context-record-relation-modify",
+ kwargs={"pk": self.context_records[0].pk}
+ )
post_response = c.post(url, data)
self.assertEqual(post_response.status_code, 302)
q_rel = models.RecordRelations.objects.filter(pk=rel1.pk)
self.assertEqual(q_rel.count(), 0)
- self.assertEqual(models.RecordRelations.objects.filter(left_record=self.cr1).count(), nb_record_relation - 1)
+ self.assertEqual(
+ models.RecordRelations.objects.filter(left_record=self.cr1).count(),
+ nb_record_relation - 1
+ )
class AutocompleteTest(AutocompleteTestBase, TestCase):
diff --git a/archaeological_context_records/views.py b/archaeological_context_records/views.py
index 330a4ab3e..15b2aee30 100644
--- a/archaeological_context_records/views.py
+++ b/archaeological_context_records/views.py
@@ -21,7 +21,7 @@ import json
from django.db.models import Q
from django.http import HttpResponse, HttpResponseRedirect, Http404
-from django.shortcuts import render, redirect
+from django.shortcuts import redirect
from django.urls import reverse
from ishtar_common.utils import ugettext_lazy as _
from django.views.generic import RedirectView
diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py
index e7b520fb6..b521e0b97 100644
--- a/archaeological_finds/tests.py
+++ b/archaeological_finds/tests.py
@@ -1065,7 +1065,9 @@ class FindTest(FindInit, TestCase):
self.create_finds(force=True)
self.password = "mypassword"
self.username = "myuser"
- User.objects.create_superuser(self.username, "myemail@test.com", self.password)
+ self.user = User.objects.create_superuser(
+ self.username, "myemail@test.com", self.password
+ )
self.client = Client()
self.client.login(username=self.username, password=self.password)
@@ -1364,7 +1366,9 @@ class FindSearchTest(FindInit, TestCase, SearchText):
self.create_finds(force=True)
self.username = "myuser"
self.password = "mypassword"
- User.objects.create_superuser(self.username, "myemail@test.com", self.password)
+ self.user = User.objects.create_superuser(
+ self.username, "myemail@test.com", self.password
+ )
self.client = Client()
def test_item_count(self):
diff --git a/archaeological_operations/views.py b/archaeological_operations/views.py
index 0cede556c..20193e197 100644
--- a/archaeological_operations/views.py
+++ b/archaeological_operations/views.py
@@ -530,7 +530,8 @@ def _formset_get_deleted(request, data, pk_key):
return new_data, deleted
-def get_relation_modify(model, model_relation, formset_class, url_name, filter_operations=False):
+def get_relation_modify(model, model_relation, formset_class, url_name,
+ filter_operations=False):
def _modify_relation(request, pk, current_right=None):
try:
item = model.objects.get(pk=pk)
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}"