Пример #1
0
    def test_edit_object_anonymous(self):
        obj = mommy.make(TestClass)
        url = obj.get_edit_url()

        response = self.client.get(url)
        if coop_settings.is_perm_middleware_installed():
            self.assertEqual(302, response.status_code)
            auth_url = get_login_url()
            self.assertRedirects(response, auth_url + '?next=' + url)
        else:
            self.assertEqual(403, response.status_code)

        field1, field2 = obj.field1, obj.field2
        data = {
            'field1': "ABC",
            'field2': "DEF",
            'bool_field': True,
            'int_field': 2,
            'float_field': 3.14
        }
        response = self.client.post(url, data=data)

        if coop_settings.is_perm_middleware_installed():
            self.assertEqual(302, response.status_code)
            auth_url = get_login_url()
            self.assertRedirects(response, auth_url + '?next=' + url)
        else:
            self.assertEqual(403, response.status_code)

        obj = TestClass.objects.get(id=obj.id)
        self.assertEqual(obj.field1, field1)
        self.assertEqual(obj.field2, field2)
Пример #2
0
 def test_edit_object_anonymous(self):
     obj = mommy.make(TestClass)
     url = obj.get_edit_url()
     
     response = self.client.get(url)
     if coop_settings.is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = get_login_url()
         self.assertRedirects(response, auth_url + '?next=' + url)
     else:
         self.assertEqual(403, response.status_code)
     
     field1, field2 = obj.field1, obj.field2
     data = {'field1': "ABC", 'field2': "DEF", 'bool_field': True, 'int_field': 2, 'float_field': 3.14}
     response = self.client.post(url, data=data)
     
     if coop_settings.is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = get_login_url()
         self.assertRedirects(response, auth_url + '?next=' + url)
     else:
         self.assertEqual(403, response.status_code)
     
     obj = TestClass.objects.get(id=obj.id)
     self.assertEqual(obj.field1, field1)
     self.assertEqual(obj.field2, field2)
Пример #3
0
    def test_edit_formset_anonymous(self):
        obj = mommy.make(TestClass)

        url = reverse('coop_cms_testapp_formset_edit')

        other_field = obj.other_field
        data = {
            'form-0-id': obj.id,
            'form-0-field1': "AZERTYUIOP",
            'form-0-field2': "<p>QWERTY/nUIOP</p>",
            'form-0-bool_field': True,
            'form-0-int_field': 2,
            'form-0-float_field': 3.14,
            'form-TOTAL_FORMS': 1,
            'form-INITIAL_FORMS': 1,
            'form-MAX_NUM_FORMS': 1,
        }

        response = self.client.post(url, data=data)

        if coop_settings.is_perm_middleware_installed():
            self.assertEqual(302, response.status_code)
            auth_url = get_login_url()
            self.assertRedirects(response, auth_url + '?next=' + url)
        else:
            self.assertEqual(403, response.status_code)

        obj = TestClass.objects.get(id=obj.id)

        self.assertNotEqual(data['form-0-field1'], obj.field1)
        self.assertNotEqual(data['form-0-field2'], obj.field2)
Пример #4
0
 def test_edit_formset_anonymous(self):
     obj = mommy.make(TestClass)
     
     url = reverse('coop_cms_testapp_formset_edit')
     
     other_field = obj.other_field
     data = {
         'form-0-id': obj.id,
         'form-0-field1': "AZERTYUIOP",
         'form-0-field2': "<p>QWERTY/nUIOP</p>",
         'form-0-bool_field': True,
         'form-0-int_field': 2,
         'form-0-float_field': 3.14,
         'form-TOTAL_FORMS': 1,
         'form-INITIAL_FORMS': 1,
         'form-MAX_NUM_FORMS': 1,
     }
     
     response = self.client.post(url, data=data)
     
     if coop_settings.is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = get_login_url()
         self.assertRedirects(response, auth_url+'?next='+url)
     else:
         self.assertEqual(403, response.status_code)
     
     obj = TestClass.objects.get(id=obj.id)
     
     self.assertNotEqual(data['form-0-field1'], obj.field1)
     self.assertNotEqual(data['form-0-field2'], obj.field2)
Пример #5
0
 def _check_anonymous_not_allowed(self, response, url):
     """helper to check that anonymous user can not access"""
     if is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = reverse("auth_login")
         self.assertRedirects(response, auth_url+'?next='+url)
     else:
         self.assertEqual(403, response.status_code)
Пример #6
0
 def _check_anonymous_not_allowed(self, response, url):
     """helper to check that anonymous user can not access"""
     if is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = reverse("auth_login")
         self.assertRedirects(response, auth_url + '?next=' + url)
     else:
         self.assertEqual(403, response.status_code)
Пример #7
0
 def test_view_object_anomymous(self):
     obj = mommy.make(TestClass)
     url = obj.get_absolute_url()
     response = self.client.get(url)
     if coop_settings.is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = get_login_url()
         self.assertRedirects(response, auth_url + '?next=' + url)
     else:
         self.assertEqual(403, response.status_code)
Пример #8
0
 def test_view_object_anomymous(self):
     obj = mommy.make(TestClass)
     url = obj.get_absolute_url()
     response = self.client.get(url)
     if coop_settings.is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = get_login_url()
         self.assertRedirects(response, auth_url + '?next=' + url)
     else:
         self.assertEqual(403, response.status_code)
Пример #9
0
 def test_publication_flag_draft(self):
     article = get_article_class().objects.create(title="test", publication=BaseArticle.DRAFT)
     self.assertEqual(article.is_draft(), True)
     url = article.get_absolute_url()
     response = self.client.get(url)
     if is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = get_login_url()
         self.assertRedirects(response, auth_url+'?next='+url)
     else:
         self.assertEqual(403, response.status_code)
Пример #10
0
 def test_publication_flag_draft(self):
     article = get_article_class().objects.create(
         title="test", publication=BaseArticle.DRAFT)
     self.assertEqual(article.is_draft(), True)
     url = article.get_absolute_url()
     response = self.client.get(url)
     if is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = get_login_url()
         self.assertRedirects(response, auth_url + '?next=' + url)
     else:
         self.assertEqual(403, response.status_code)
Пример #11
0
 def test_login_required_not_authenticated(self):
     """raise permission denied if permission required not authenticated"""
     self.client.logout()
     article = get_article_class().objects.create(
         title="test", publication=BaseArticle.PUBLISHED, login_required=True
     )
     url = article.get_absolute_url()
     response = self.client.get(url)
     if is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = get_login_url()
         self.assertRedirects(response, auth_url+'?next='+url)
     else:
         self.assertEqual(403, response.status_code)
Пример #12
0
 def test_login_required_not_authenticated(self):
     """raise permission denied if permission required not authenticated"""
     self.client.logout()
     article = get_article_class().objects.create(
         title="test",
         publication=BaseArticle.PUBLISHED,
         login_required=True)
     url = article.get_absolute_url()
     response = self.client.get(url)
     if is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = get_login_url()
         self.assertRedirects(response, auth_url + '?next=' + url)
     else:
         self.assertEqual(403, response.status_code)
Пример #13
0
 def test_view_draft_article(self):
     self.client.logout()
     article = get_article_class().objects.create(title="test", publication=BaseArticle.DRAFT)
     url = article.get_absolute_url()
     response = self.client.get(url)
     if is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = get_login_url()
         self.assertRedirects(response, auth_url+'?next='+url)
     else:
         self.assertEqual(403, response.status_code)
     
     self._log_as_editor()
     response = self.client.get(article.get_absolute_url())
     self.assertEqual(200, response.status_code)
Пример #14
0
    def test_view_draft_article(self):
        self.client.logout()
        article = get_article_class().objects.create(
            title="test", publication=BaseArticle.DRAFT)
        url = article.get_absolute_url()
        response = self.client.get(url)
        if is_perm_middleware_installed():
            self.assertEqual(302, response.status_code)
            auth_url = get_login_url()
            self.assertRedirects(response, auth_url + '?next=' + url)
        else:
            self.assertEqual(403, response.status_code)

        self._log_as_editor()
        response = self.client.get(article.get_absolute_url())
        self.assertEqual(200, response.status_code)
Пример #15
0
 def test_article_edition_permission(self):
     initial_data = {'title': "test", 'content': "this is my article content"}
     article = get_article_class().objects.create(publication=BaseArticle.PUBLISHED, **initial_data)
     url = article.get_edit_url()
     data = {"title": 'salut', "content": 'oups'}
     response = self.client.post(url, data=data)
     if is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = get_login_url()
         self.assertRedirects(response, auth_url+'?next='+url)
     else:
         self.assertEqual(403, response.status_code)
     
     article = get_article_class().objects.get(id=article.id)
     self.assertEquals(article.title, initial_data['title'])
     self.assertEquals(article.content, initial_data['content'])
Пример #16
0
 def test_edit_permission(self):
     initial_data = {'title': "ceci est un test", 'content': "this is my article content"}
     article = get_article_class().objects.create(publication=BaseArticle.PUBLISHED, **initial_data)
     response = self.client.get(article.get_absolute_url(), follow=True)
     self.assertEqual(200, response.status_code)
     
     url = article.get_edit_url()
     response = self.client.get(url, follow=False)
     if is_perm_middleware_installed():
         self.assertEqual(302, response.status_code)
         auth_url = get_login_url()
         self.assertRedirects(response, auth_url+'?next='+url)
     else:
         self.assertEqual(403, response.status_code)
 
     self._log_as_editor()
     response = self.client.get(article.get_edit_url(), follow=False)
     self.assertEqual(200, response.status_code)
Пример #17
0
    def test_article_edition_permission(self):
        initial_data = {
            'title': "test",
            'content': "this is my article content"
        }
        article = get_article_class().objects.create(
            publication=BaseArticle.PUBLISHED, **initial_data)
        url = article.get_edit_url()
        data = {"title": 'salut', "content": 'oups'}
        response = self.client.post(url, data=data)
        if is_perm_middleware_installed():
            self.assertEqual(302, response.status_code)
            auth_url = get_login_url()
            self.assertRedirects(response, auth_url + '?next=' + url)
        else:
            self.assertEqual(403, response.status_code)

        article = get_article_class().objects.get(id=article.id)
        self.assertEquals(article.title, initial_data['title'])
        self.assertEquals(article.content, initial_data['content'])
Пример #18
0
    def test_edit_permission(self):
        initial_data = {
            'title': "ceci est un test",
            'content': "this is my article content"
        }
        article = get_article_class().objects.create(
            publication=BaseArticle.PUBLISHED, **initial_data)
        response = self.client.get(article.get_absolute_url(), follow=True)
        self.assertEqual(200, response.status_code)

        url = article.get_edit_url()
        response = self.client.get(url, follow=False)
        if is_perm_middleware_installed():
            self.assertEqual(302, response.status_code)
            auth_url = get_login_url()
            self.assertRedirects(response, auth_url + '?next=' + url)
        else:
            self.assertEqual(403, response.status_code)

        self._log_as_editor()
        response = self.client.get(article.get_edit_url(), follow=False)
        self.assertEqual(200, response.status_code)