diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-02-18 13:10:24 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2016-02-18 13:10:24 +0100 |
commit | 303110c526124e76ea40cf4abaad3bd4a5223104 (patch) | |
tree | abac5732281694b364c299124a53f2cf446f572c | |
parent | 6a868f55d08cd9be71be95af6617abdcab80a57c (diff) | |
download | Ishtar-303110c526124e76ea40cf4abaad3bd4a5223104.tar.bz2 Ishtar-303110c526124e76ea40cf4abaad3bd4a5223104.zip |
Update tests for module management
-rw-r--r-- | ishtar_common/models.py | 9 | ||||
-rw-r--r-- | ishtar_common/tests.py | 32 |
2 files changed, 33 insertions, 8 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 0b1f42460..77a9bf868 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -42,7 +42,7 @@ from django.core.urlresolvers import reverse, NoReverseMatch from django.db.utils import DatabaseError from django.db.models import Q, Max, Count from django.db.models.base import ModelBase -from django.db.models.signals import post_save, pre_delete +from django.db.models.signals import post_save, pre_delete, post_delete from django.utils.translation import ugettext_lazy as _, ugettext, \ pgettext_lazy @@ -801,7 +801,7 @@ class IshtarSiteProfile(models.Model, Cached): obj = self if raw: return obj - q = self.__class__.objects.filter(active=True).exclude(pk=self.pk) + q = self.__class__.objects.filter(active=True).exclude(slug=self.slug) if obj.active and q.count(): for profile in q.all(): profile.active = False @@ -822,7 +822,7 @@ class IshtarSiteProfile(models.Model, Cached): def get_current_profile(force=False): - cache_key, value = get_cache(IshtarSiteProfile, 'is-current-profile') + cache_key, value = get_cache(IshtarSiteProfile, ['is-current-profile']) if value and not force: return value q = IshtarSiteProfile.objects.filter(active=True) @@ -836,11 +836,10 @@ def get_current_profile(force=False): def cached_site_changed(sender, **kwargs): - if not kwargs['instance']: - return get_current_profile(force=True) post_save.connect(cached_site_changed, sender=IshtarSiteProfile) +post_delete.connect(cached_site_changed, sender=IshtarSiteProfile) class GlobalVar(models.Model, Cached): diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py index e2c9b233f..82ab009e0 100644 --- a/ishtar_common/tests.py +++ b/ishtar_common/tests.py @@ -17,10 +17,14 @@ # See the file COPYING for details. +from django.conf import settings from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType +from django.core.cache import cache +from django.core.urlresolvers import reverse from django.template.defaultfilters import slugify from django.test import TestCase +from django.test.client import Client from ishtar_common import models @@ -161,16 +165,19 @@ class ImportKeyTest(TestCase): class IshtarSiteProfileTest(TestCase): def testRelevance(self): - profile = models.IshtarSiteProfile.objects.create( - label="Test profile", slug='test-profile') + cache.set('default-ishtarsiteprofile-is-current-profile', None, + settings.CACHE_TIMEOUT) + profile = models.get_current_profile() + default_slug = profile.slug profile2 = models.IshtarSiteProfile.objects.create( label="Test profile 2", slug='test-profile-2') + profile2.save() # when no profile is the current, activate by default the first created self.assertTrue(profile.active and not profile2.active) profile2.active = True profile2 = profile2.save() - profile = models.IshtarSiteProfile.objects.get(slug='test-profile') # only one profile active at a time + profile = models.IshtarSiteProfile.objects.get(slug=default_slug) self.assertTrue(profile2.active and not profile.active) # activate find active automatically context records self.assertFalse(profile.context_record) @@ -184,7 +191,26 @@ class IshtarSiteProfileTest(TestCase): self.assertTrue(profile2.context_record and profile2.find) def testDefaultProfile(self): + cache.set('default-ishtarsiteprofile-is-current-profile', None, + settings.CACHE_TIMEOUT) self.assertFalse(models.IshtarSiteProfile.objects.count()) profile = models.get_current_profile() self.assertTrue(profile) self.assertTrue(models.IshtarSiteProfile.objects.count()) + + def testMenuFiltering(self): + cache.set('default-ishtarsiteprofile-is-current-profile', None, + settings.CACHE_TIMEOUT) + username = 'username4277' + password = 'dcbqj756456!@%' + User.objects.create_superuser(username, "nomail@nomail.com", + password) + c = Client() + c.login(username=username, password=password) + response = c.get(reverse('start')) + self.assertFalse("section-file_management" in response.content) + profile = models.get_current_profile() + profile.files = True + profile.save() + response = c.get(reverse('start')) + self.assertTrue("section-file_management" in response.content) |