Fix test
This commit is contained in:
parent
80fb25dbd5
commit
2de4ba3778
3 changed files with 60 additions and 17 deletions
|
@ -201,8 +201,9 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
|
|||
def get_queryset(self, request):
|
||||
qs = super(PostAdmin, self).get_queryset(request)
|
||||
sites = self.get_restricted_sites(request)
|
||||
pks = list(sites.all().values_list('pk', flat=True))
|
||||
if sites.exists():
|
||||
qs = qs.filter(sites__in=sites.all())
|
||||
qs = qs.filter(sites__in=pks)
|
||||
return qs.distinct()
|
||||
|
||||
def save_related(self, request, form, formsets, change):
|
||||
|
|
|
@ -6,6 +6,8 @@ from copy import deepcopy
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core.cache import cache
|
||||
from django.core.management import call_command
|
||||
|
||||
from djangocms_helper.base_test import BaseTestCase
|
||||
from haystack import connections
|
||||
from haystack.constants import DEFAULT_ALIAS
|
||||
|
@ -109,22 +111,26 @@ class BaseTest(BaseTestCase):
|
|||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(BaseTest, cls).setUpClass()
|
||||
cls.thumb_1 = ThumbnailOption.objects.create(
|
||||
cls.thumb_1, __ = ThumbnailOption.objects.get_or_create(
|
||||
name='base', width=100, height=100, crop=True, upscale=False
|
||||
)
|
||||
cls.thumb_2 = ThumbnailOption.objects.create(
|
||||
cls.thumb_2, __ = ThumbnailOption.objects.get_or_create(
|
||||
name='main', width=200, height=200, crop=False, upscale=False
|
||||
)
|
||||
cls.app_config_1 = BlogConfig.objects.create(
|
||||
namespace='sample_app', app_title='app1', object_name='Blog'
|
||||
cls.app_config_1, __ = BlogConfig.objects.get_or_create(
|
||||
namespace='sample_app'
|
||||
)
|
||||
cls.app_config_2 = BlogConfig.objects.create(
|
||||
namespace='sample_app2', app_title='app2', object_name='Article'
|
||||
cls.app_config_2, __ = BlogConfig.objects.get_or_create(
|
||||
namespace='sample_app2'
|
||||
)
|
||||
cls.app_config_1.app_title = 'app1'
|
||||
cls.app_config_1.object_name = 'Blog'
|
||||
cls.app_config_1.app_data.config.paginate_by = 1
|
||||
cls.app_config_1.app_data.config.send_knock_create = True
|
||||
cls.app_config_1.app_data.config.send_knock_update = True
|
||||
cls.app_config_1.save()
|
||||
cls.app_config_2.app_title = 'app2'
|
||||
cls.app_config_2.object_name = 'Article'
|
||||
cls.app_config_2.app_data.config.paginate_by = 2
|
||||
cls.app_config_2.app_data.config.send_knock_create = True
|
||||
cls.app_config_2.app_data.config.send_knock_update = True
|
||||
|
@ -133,21 +139,30 @@ class BaseTest(BaseTestCase):
|
|||
'sample_app': cls.app_config_1,
|
||||
'sample_app2': cls.app_config_2,
|
||||
}
|
||||
cls.category_1 = BlogCategory.objects.create(name='category 1',
|
||||
app_config=cls.app_config_1)
|
||||
cls.category_1 = BlogCategory.objects.create(
|
||||
name='category 1', app_config=cls.app_config_1
|
||||
)
|
||||
cls.category_1.set_current_language('it', initialize=True)
|
||||
cls.category_1.name = 'categoria 1'
|
||||
cls.category_1.save()
|
||||
cls.site_2 = Site.objects.create(domain='http://example2.com', name='example 2')
|
||||
cls.site_3 = Site.objects.create(domain='http://example3.com', name='example 3')
|
||||
cls.site_2, __ = Site.objects.get_or_create(domain='http://example2.com', name='example 2')
|
||||
cls.site_3, __ = Site.objects.get_or_create(domain='http://example3.com', name='example 3')
|
||||
cache.clear()
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
super(BaseTest, cls).tearDownClass()
|
||||
BlogConfig.objects.all().delete()
|
||||
BlogCategory.objects.all().delete()
|
||||
ThumbnailOption.objects.all().delete()
|
||||
cache.clear()
|
||||
super(BaseTest, cls).tearDownClass()
|
||||
|
||||
def tearDown(self):
|
||||
self.user.sites.clear()
|
||||
for post in Post.objects.all():
|
||||
post.sites.clear()
|
||||
post.tags.clear()
|
||||
super(BaseTest, self).tearDown()
|
||||
|
||||
def _get_category(self, data, category=None, lang='en'):
|
||||
data = deepcopy(data)
|
||||
|
|
|
@ -320,7 +320,10 @@ class AdminTest(BaseTest):
|
|||
|
||||
# no restrictions, sites are assigned
|
||||
with self.login_user_context(self.user):
|
||||
data = {'sites': [1, 2], 'title': 'some title', 'app_config': 1}
|
||||
data = {
|
||||
'sites': [self.site_1.pk, self.site_2.pk], 'title': 'some title',
|
||||
'app_config': self.app_config_1.pk
|
||||
}
|
||||
request = self.post_request(pages[0], 'en', user=self.user, data=data, path='/en/')
|
||||
self.assertEquals(post.sites.count(), 0)
|
||||
msg_mid = MessageMiddleware()
|
||||
|
@ -330,13 +333,20 @@ class AdminTest(BaseTest):
|
|||
self.assertEqual(response.status_code, 302)
|
||||
post = self.reload_model(post)
|
||||
self.assertEquals(post.sites.count(), 2)
|
||||
post.sites.clear()
|
||||
post = self.reload_model(post)
|
||||
|
||||
# user only allowed on 2 sites, can add both
|
||||
self.user.sites.add(self.site_2)
|
||||
self.user.sites.add(self.site_3)
|
||||
post = self.reload_model(post)
|
||||
post.sites.add(self.site_1)
|
||||
post.sites.add(self.site_2)
|
||||
self.user = self.reload_model(self.user)
|
||||
with self.login_user_context(self.user):
|
||||
data = {'sites': [2, 3], 'title': 'some title', 'app_config': 1}
|
||||
data = {
|
||||
'sites': [self.site_2.pk, self.site_3.pk], 'title': 'some title',
|
||||
'app_config': self.app_config_1.pk
|
||||
}
|
||||
request = self.post_request(pages[0], 'en', user=self.user, data=data, path='/en/')
|
||||
self.assertEquals(post.sites.count(), 2)
|
||||
msg_mid = MessageMiddleware()
|
||||
|
@ -348,12 +358,20 @@ class AdminTest(BaseTest):
|
|||
post = self.reload_model(post)
|
||||
self.assertEquals(post.sites.count(), 3)
|
||||
self.user.sites.clear()
|
||||
post.sites.clear()
|
||||
|
||||
# user only allowed on 2 sites, can remove one of his sites
|
||||
post = self.reload_model(post)
|
||||
post.sites.add(self.site_1)
|
||||
post.sites.add(self.site_2)
|
||||
post.sites.add(self.site_3)
|
||||
self.user.sites.add(self.site_2)
|
||||
self.user.sites.add(self.site_3)
|
||||
with self.login_user_context(self.user):
|
||||
data = {'sites': [3], 'title': 'some title', 'app_config': 1}
|
||||
data = {
|
||||
'sites': [self.site_3.pk], 'title': 'some title',
|
||||
'app_config': self.app_config_1.pk
|
||||
}
|
||||
request = self.post_request(pages[0], 'en', user=self.user, data=data, path='/en/')
|
||||
self.assertEquals(post.sites.count(), 3)
|
||||
msg_mid = MessageMiddleware()
|
||||
|
@ -365,13 +383,20 @@ class AdminTest(BaseTest):
|
|||
post = self.reload_model(post)
|
||||
self.assertEquals(post.sites.count(), 2)
|
||||
self.user.sites.clear()
|
||||
post.sites.clear()
|
||||
|
||||
# user only allowed on 2 sites, if given sites is empty, the site with no permission on
|
||||
# is kept
|
||||
post = self.reload_model(post)
|
||||
post.sites.add(self.site_1)
|
||||
post.sites.add(self.site_3)
|
||||
self.user.sites.add(self.site_2)
|
||||
self.user.sites.add(self.site_3)
|
||||
with self.login_user_context(self.user):
|
||||
data = {'sites': [], 'title': 'some title', 'app_config': 1}
|
||||
data = {
|
||||
'sites': [], 'title': 'some title',
|
||||
'app_config': self.app_config_1.pk
|
||||
}
|
||||
request = self.post_request(pages[0], 'en', user=self.user, data=data, path='/en/')
|
||||
self.assertEquals(post.sites.count(), 2)
|
||||
msg_mid = MessageMiddleware()
|
||||
|
@ -383,6 +408,8 @@ class AdminTest(BaseTest):
|
|||
post = self.reload_model(post)
|
||||
self.assertEquals(post.sites.count(), 1)
|
||||
self.user.sites.clear()
|
||||
post.sites.clear()
|
||||
post = self.reload_model(post)
|
||||
|
||||
def test_admin_clear_menu(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue