class TestAdminButtons(TestAdminButtonsBase, TestCase): def setUp(self): super(TestAdminButtons, self).setUp() self.client.login(username='******', password='******') def test_status_embryo(self): url = urlresolvers.reverse('admin:widgy_mezzanine_widgypage_add') response = self.client.get(url) self.assertIn('Save', response.content) def test_status_embryo_save(self): url = urlresolvers.reverse('admin:widgy_mezzanine_widgypage_add') response = self.client.get(url) data = { '_continue': '', 'title': 'Title', 'slug': 'test_status_embryo_save', 'root_node': ContentType.objects.get_for_model(DefaultLayout).pk, } response = self.client.post(url, data) self.assertEqual(response.status_code, 302) page = WidgyPage.objects.get(slug='test_status_embryo_save') self.assertEqual(page.status, CONTENT_STATUS_DRAFT) def test_save_and_commit(self): self.page.status = CONTENT_STATUS_DRAFT self.page.save() req = self.factory.post('/') req.user = self.superuser self.model_admin._save_and_commit(req, self.page) self.assertEqual(self.page.status, CONTENT_STATUS_PUBLISHED) def test_save_and_commit_without_permission(self): self.model_admin = WidgyPageAdmin(WidgyPage, admin.site) req = self.factory.post('/') req.user = self.staffuser self.staffuser.user_permissions.filter(codename='add_versioncommit').delete() with mock.patch('django.contrib.messages.error') as error_mock: self.model_admin._save_and_commit(req, self.page) error_mock.assert_called_with(req, mock.ANY) self.assertEqual(self.page.root_node.commits.count(), 0) def test_status_draft(self): self.page.status = CONTENT_STATUS_DRAFT self.page.save() url = urlresolvers.reverse('admin:widgy_mezzanine_widgypage_change', args=(self.page.pk,)) response = self.client.get(url) self.assertIn('Save as Draft', response.content) self.assertIn('Publish', response.content) def test_status_published(self): url = urlresolvers.reverse('admin:widgy_mezzanine_widgypage_change', args=(self.page.pk,)) response = self.client.get(url) self.assertIn('Publish Changes', response.content)
def test_save_and_commit_without_permission(self): self.model_admin = WidgyPageAdmin(WidgyPage, admin.site) req = self.factory.post('/') req.user = self.staffuser self.staffuser.user_permissions.filter(codename='add_versioncommit').delete() with mock.patch('django.contrib.messages.error') as error_mock: self.model_admin._save_and_commit(req, self.page) error_mock.assert_called_with(req, mock.ANY) self.assertEqual(self.page.root_node.commits.count(), 0)
class AdminButtonsTestBase(PageSetup, UserSetup): def setUp(self): super(AdminButtonsTestBase, self).setUp() self.model_admin = WidgyPageAdmin(WidgyPage, admin.site) def test_save_and_commit_without_changes(self): req = self.factory.post('/') req.user = self.superuser self.model_admin._save_and_commit(req, self.page) self.assertEqual(self.page.root_node.commits.count(), 1) # save and commit again should not commit again when there are no # changes to commit self.model_admin._save_and_commit(req, self.page) self.assertEqual(self.page.root_node.commits.count(), 1)
class AdminButtonsTestBase(PageSetup, UserSetup): urls = 'widgy.contrib.widgy_mezzanine.tests.test_core' def setUp(self): super(AdminButtonsTestBase, self).setUp() self.model_admin = WidgyPageAdmin(WidgyPage, admin.site) def test_save_and_commit_without_changes(self): req = self.factory.post('/') req.user = self.superuser self.model_admin._save_and_commit(req, self.page) self.assertEqual(self.page.root_node.commits.count(), 1) # save and commit again should not commit again when there are no # changes to commit self.model_admin._save_and_commit(req, self.page) self.assertEqual(self.page.root_node.commits.count(), 1)
def setUp(self): super(AdminButtonsTestBase, self).setUp() self.model_admin = WidgyPageAdmin(WidgyPage, admin.site)
class TestAdminButtons(AdminButtonsTestBase, TestCase): def setUp(self): super(TestAdminButtons, self).setUp() self.client.login(username='******', password='******') def test_status_embryo(self): url = urlresolvers.reverse('admin:widgy_mezzanine_widgypage_add') response = self.client.get(url) self.assertIn('Save', response.rendered_content) def test_status_embryo_save(self): url = urlresolvers.reverse('admin:widgy_mezzanine_widgypage_add') response = self.client.get(url) data = { '_continue': '', 'title': 'Title', 'slug': 'test_status_embryo_save', 'root_node': ContentType.objects.get_for_model(DefaultLayout).pk, } response = self.client.post(url, data) self.assertEqual(response.status_code, 302) page = WidgyPage.objects.get(slug='test_status_embryo_save') self.assertEqual(page.status, CONTENT_STATUS_DRAFT) def test_save_and_commit(self): self.page.status = CONTENT_STATUS_DRAFT self.page.save() req = self.factory.post('/') req.user = self.superuser self.model_admin._save_and_commit(req, self.page) self.assertEqual(self.page.status, CONTENT_STATUS_PUBLISHED) def test_save_and_commit_without_permission(self): self.model_admin = WidgyPageAdmin(WidgyPage, admin.site) req = self.factory.post('/') req.user = self.staffuser self.staffuser.user_permissions.filter( codename='add_versioncommit').delete() with mock.patch('django.contrib.messages.error') as error_mock: self.model_admin._save_and_commit(req, self.page) error_mock.assert_called_with(req, mock.ANY) self.assertEqual(self.page.root_node.commits.count(), 0) def test_status_draft(self): self.page.status = CONTENT_STATUS_DRAFT self.page.save() url = urlresolvers.reverse('admin:widgy_mezzanine_widgypage_change', args=(self.page.pk, )) response = self.client.get(url) self.assertIn('Save as Draft', response.rendered_content) self.assertIn('Publish', response.rendered_content) def test_status_published(self): url = urlresolvers.reverse('admin:widgy_mezzanine_widgypage_change', args=(self.page.pk, )) response = self.client.get(url) self.assertIn('Publish Changes', response.rendered_content) def test_delete_button(self): url = urlresolvers.reverse('admin:widgy_mezzanine_widgypage_add') response = self.client.get(url) self.assertNotIn('Delete', response.rendered_content) url = urlresolvers.reverse('admin:widgy_mezzanine_widgypage_change', args=(self.page.pk, )) response = self.client.get(url) self.assertIn('Delete', response.rendered_content)