Permalink
Browse files

Merge branch 'develop' into develop-issue779

  • Loading branch information...
2 parents 1efbfe3 + 07e3394 commit 60c06390038836e68e1e855d8a87b25ff11a0881 @mitar committed May 11, 2011
View
@@ -15,6 +15,7 @@ Contributors (in alphabetical order):
* Aaron Renner
* aball
* Adi Sieker
+* Adrián Ribao
* Alberto Paro
* Alessandro Ronchi
* Angelo Dini
@@ -712,6 +712,9 @@ def has_view_permission(self, request):
# staff is allowed to see everything
if request.user.is_staff and settings.CMS_PUBLIC_FOR in ('staff', 'all'):
return True
+
+ if not self.publisher_is_draft and self.publisher_public:
+ return self.publisher_public.has_view_permission(request)
# does any restriction exist?
# direct
#is_restricted = PagePermission.objects.filter(page=self, can_view=True).exists()
@@ -84,10 +84,6 @@ def _post_teardown(self):
menu_pool.clear()
super(CMSTestCase, self)._post_teardown()
- def login_user(self, user):
- self.assertTrue(self.client.login(username=user.username, password=user.username))
- self.user = user
-
def login_user_context(self, user):
return UserLoginContext(self, user)
@@ -108,10 +108,16 @@ def __init__(self, testcase, user):
self.user = user
def __enter__(self):
- self.testcase.login_user(self.user)
+ loginok = self.testcase.client.login(username=self.user.username,
+ password=self.user.username)
+ self.old_user = getattr(self.testcase, 'user', None)
+ self.testcase.user = self.user
+ self.testcase.assertTrue(loginok)
def __exit__(self, exc, value, tb):
- self.testcase.user = None
+ self.testcase.user = self.old_user
+ if not self.testcase.user:
+ delattr(self.testcase, 'user')
self.testcase.client.logout()
View
@@ -32,27 +32,27 @@ def _get_guys(self, admin_only=False):
admin = self.get_superuser()
if admin_only:
return admin
- self.login_user(admin)
- USERNAME = 'test'
-
- normal_guy = User.objects.create_user(USERNAME, 'test@test.com', USERNAME)
- normal_guy.is_staff = True
- normal_guy.is_active = True
- normal_guy.save()
- normal_guy.user_permissions = Permission.objects.filter(
- codename__in=['change_page', 'change_title', 'add_page', 'add_title', 'delete_page', 'delete_title']
- )
- gpp = GlobalPagePermission.objects.create(
- user=normal_guy,
- can_change=True,
- can_delete=True,
- can_change_advanced_settings=False,
- can_publish=True,
- can_change_permissions=False,
- can_move_page=True,
- can_moderate=True,
- )
- gpp.sites = Site.objects.all()
+ with self.login_user_context(admin):
+ USERNAME = 'test'
+
+ normal_guy = User.objects.create_user(USERNAME, 'test@test.com', USERNAME)
+ normal_guy.is_staff = True
+ normal_guy.is_active = True
+ normal_guy.save()
+ normal_guy.user_permissions = Permission.objects.filter(
+ codename__in=['change_page', 'change_title', 'add_page', 'add_title', 'delete_page', 'delete_title']
+ )
+ gpp = GlobalPagePermission.objects.create(
+ user=normal_guy,
+ can_change=True,
+ can_delete=True,
+ can_change_advanced_settings=False,
+ can_publish=True,
+ can_change_permissions=False,
+ can_move_page=True,
+ can_moderate=True,
+ )
+ gpp.sites = Site.objects.all()
return admin, normal_guy
def test_01_edit_does_not_reset_page_adv_fields(self):
@@ -99,59 +99,59 @@ def test_01_edit_does_not_reset_page_adv_fields(self):
page_data['pagepermission_set-2-INITIAL_FORMS'] = 0
page_data['pagepermission_set-2-MAX_NUM_FORMS'] = 0
- self.login_user(normal_guy)
- resp = self.client.post(base.URL_CMS_PAGE_CHANGE % page.pk, page_data,
- follow=True)
- self.assertEqual(resp.status_code, 200)
- self.assertTemplateNotUsed(resp, 'admin/login.html')
- page = Page.objects.get(pk=page.pk)
-
- self.assertEqual(page.get_title(), NEW_PAGE_NAME)
- self.assertEqual(page.reverse_id, REVERSE_ID)
- title = page.get_title_obj()
- self.assertEqual(title.overwrite_url, OVERRIDE_URL)
-
- # The admin edits the page (change the page name for ex.)
- page_data = {
- 'title': OLD_PAGE_NAME,
- 'slug': page.get_slug(),
- 'language': title.language,
- 'site': page.site.pk,
- 'template': page.template,
- 'reverse_id': page.reverse_id,
- }
- # required only if user haves can_change_permission
- page_data['pagepermission_set-TOTAL_FORMS'] = 0
- page_data['pagepermission_set-INITIAL_FORMS'] = 0
- page_data['pagepermission_set-MAX_NUM_FORMS'] = 0
- page_data['pagepermission_set-2-TOTAL_FORMS'] = 0
- page_data['pagepermission_set-2-INITIAL_FORMS'] = 0
- page_data['pagepermission_set-2-MAX_NUM_FORMS'] = 0
-
- self.login_user(admin)
- resp = self.client.post(base.URL_CMS_PAGE_CHANGE % page.pk, page_data,
- follow=True)
- self.assertEqual(resp.status_code, 200)
- self.assertTemplateNotUsed(resp, 'admin/login.html')
- page = Page.objects.get(pk=page.pk)
+ with self.login_user_context(normal_guy):
+ resp = self.client.post(base.URL_CMS_PAGE_CHANGE % page.pk, page_data,
+ follow=True)
+ self.assertEqual(resp.status_code, 200)
+ self.assertTemplateNotUsed(resp, 'admin/login.html')
+ page = Page.objects.get(pk=page.pk)
+
+ self.assertEqual(page.get_title(), NEW_PAGE_NAME)
+ self.assertEqual(page.reverse_id, REVERSE_ID)
+ title = page.get_title_obj()
+ self.assertEqual(title.overwrite_url, OVERRIDE_URL)
+
+ # The admin edits the page (change the page name for ex.)
+ page_data = {
+ 'title': OLD_PAGE_NAME,
+ 'slug': page.get_slug(),
+ 'language': title.language,
+ 'site': page.site.pk,
+ 'template': page.template,
+ 'reverse_id': page.reverse_id,
+ }
+ # required only if user haves can_change_permission
+ page_data['pagepermission_set-TOTAL_FORMS'] = 0
+ page_data['pagepermission_set-INITIAL_FORMS'] = 0
+ page_data['pagepermission_set-MAX_NUM_FORMS'] = 0
+ page_data['pagepermission_set-2-TOTAL_FORMS'] = 0
+ page_data['pagepermission_set-2-INITIAL_FORMS'] = 0
+ page_data['pagepermission_set-2-MAX_NUM_FORMS'] = 0
- self.assertEqual(page.get_title(), OLD_PAGE_NAME)
- self.assertEqual(page.reverse_id, REVERSE_ID)
- title = page.get_title_obj()
- self.assertEqual(title.overwrite_url, None)
+ with self.login_user_context(admin):
+ resp = self.client.post(base.URL_CMS_PAGE_CHANGE % page.pk, page_data,
+ follow=True)
+ self.assertEqual(resp.status_code, 200)
+ self.assertTemplateNotUsed(resp, 'admin/login.html')
+ page = Page.objects.get(pk=page.pk)
+
+ self.assertEqual(page.get_title(), OLD_PAGE_NAME)
+ self.assertEqual(page.reverse_id, REVERSE_ID)
+ title = page.get_title_obj()
+ self.assertEqual(title.overwrite_url, None)
def test_02_delete(self):
admin = self._get_guys(True)
page = create_page("delete-page", "nav_playground.html", "en",
created_by=admin, published=True)
child = create_page('child-page', "nav_playground.html", "en",
created_by=admin, published=True, parent=page)
- self.login_user(admin)
- data = {'post': 'yes'}
- response = self.client.post(URL_CMS_PAGE_DELETE % page.pk, data)
- self.assertRedirects(response, URL_CMS_PAGE)
- self.assertRaises(Page.DoesNotExist, self.reload, page)
- self.assertRaises(Page.DoesNotExist, self.reload, child)
+ with self.login_user_context(admin):
+ data = {'post': 'yes'}
+ response = self.client.post(URL_CMS_PAGE_DELETE % page.pk, data)
+ self.assertRedirects(response, URL_CMS_PAGE)
+ self.assertRaises(Page.DoesNotExist, self.reload, page)
+ self.assertRaises(Page.DoesNotExist, self.reload, child)
def test_03_admin_dialog_form_no_moderation_or_permissions(self):
with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False):
@@ -192,11 +192,11 @@ def test_07_delete_translation(self):
page = create_page("delete-page-translation", "nav_playground.html", "en",
created_by=admin, published=True)
create_title("de", "delete-page-translation-2", page, slug="delete-page-translation-2")
- self.login_user(admin)
- response = self.client.get(URL_CMS_TRANSLATION_DELETE % page.pk, {'language': 'de'})
- self.assertEqual(response.status_code, 200)
- response = self.client.post(URL_CMS_TRANSLATION_DELETE % page.pk, {'language': 'de'})
- self.assertRedirects(response, URL_CMS_PAGE)
+ with self.login_user_context(admin):
+ response = self.client.get(URL_CMS_TRANSLATION_DELETE % page.pk, {'language': 'de'})
+ self.assertEqual(response.status_code, 200)
+ response = self.client.post(URL_CMS_TRANSLATION_DELETE % page.pk, {'language': 'de'})
+ self.assertRedirects(response, URL_CMS_PAGE)
def test_08_change_template(self):
request = self.get_request('/admin/cms/page/1/', 'en')
View
@@ -42,11 +42,11 @@ def test_04_get_site_choices_without_moderator(self):
is_superuser=True)
user_super.set_password("super")
user_super.save()
- self.login_user(user_super)
- create_page("home", "nav_playground.html", "en", created_by=user_super)
- # The proper test
- result = get_site_choices()
- self.assertEquals(result, [(1,'example.com')])
+ with self.login_user_context(user_super):
+ create_page("home", "nav_playground.html", "en", created_by=user_super)
+ # The proper test
+ result = get_site_choices()
+ self.assertEquals(result, [(1,'example.com')])
def test_05_compress_function_raises_when_page_is_none(self):
raised = False
@@ -77,13 +77,13 @@ def test_07_compress_function_gets_a_page_when_one_exists(self):
is_superuser=True)
user_super.set_password("super")
user_super.save()
- self.login_user(user_super)
- home_page = create_page("home", "nav_playground.html", "en", created_by=user_super)
- # The actual test
- fake_field = Mock_PageSelectFormField()
- data_list = (0, home_page.pk) #(site_id, page_id) dsite-id is not used
- result = fake_field.compress(data_list)
- self.assertEquals(home_page,result)
+ with self.login_user_context(user_super):
+ home_page = create_page("home", "nav_playground.html", "en", created_by=user_super)
+ # The actual test
+ fake_field = Mock_PageSelectFormField()
+ data_list = (0, home_page.pk) #(site_id, page_id) dsite-id is not used
+ result = fake_field.compress(data_list)
+ self.assertEquals(home_page,result)
def test_08_superlazy_iterator_behaves_properly_for_sites(self):
normal_result = get_site_choices()
@@ -17,9 +17,8 @@ def setUp(self):
u = User(username="test", is_staff = True, is_active = True, is_superuser = True)
u.set_password("test")
u.save()
- self.login_user(u)
-
- self.create_some_pages()
+ with self.login_user_context(u):
+ self.create_some_pages()
# def tearDown(self):
# menu_pool.menus = self.old_menu
View
@@ -24,7 +24,11 @@ def setUp(self):
u.set_password("test")
u.save()
- self.login_user(u)
+ self._login_context = self.login_user_context(u)
+ self._login_context.__enter__()
+
+ def tearDown(self):
+ self._login_context.__exit__(None, None, None)
def test_01_add_page(self):
"""
Oops, something went wrong.

0 comments on commit 60c0639

Please sign in to comment.