Show
Ignore:
Timestamp:
03/03/09 15:32:56 (13 months ago)
Author:
JensDiemer
Message:

blog: change the check referer mode values, add more unittests

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/pylucid_project/tests/plugin_admin_blog.py

    r1837 r1838  
    3131from django.conf import settings 
    3232 
    33 from PyLucid.models import Page 
     33from PyLucid.models import Page, Plugin 
    3434 
    3535ONE_BROWSER_TRACEBACK = True 
     
    5555        super(TestPluginBlog, self).__init__(*args, **kwargs) 
    5656 
     57        from PyLucid.plugins_internal.blog import blog_cfg 
     58        self.blog_cfg = blog_cfg 
     59         
    5760        self.base_url = "/%s/%s/blog/" % ( 
    5861            settings.COMMAND_URL_PREFIX, PAGE_ID 
     
    141144        ) 
    142145         
     146    def _create_new_blog_entry(self): 
     147        """ 
     148        Create a blog entry. 
     149        """ 
     150        self.login("staff") 
     151         
     152        post_data = BLOG_POST_DATA1.copy() 
     153        post_data.update({u'save': u'save'}) 
     154         
     155        # Create a new blog entry 
     156        response = self.client.post(self.add_entry_url, post_data) 
     157        self.failUnlessEqual(response.status_code, 200) 
     158        self.assertResponse( 
     159            response, 
     160            must_contain=( 
     161                "New blog entry created.", 
     162                "New tags created:", "unittest", "blog", "tags", 
     163                "blog - all entries","tag cloud", "syndication feeds", 
     164            ), 
     165            must_not_contain=("Traceback", "Error",), 
     166        ) 
     167         
    143168    def test_create_new_blog_entry(self): 
    144169        """ 
     
    147172        2. Leave a comment  
    148173        """ 
    149         self.login("staff") 
    150          
    151         post_data = BLOG_POST_DATA1.copy() 
    152         post_data.update({u'save': u'save'}) 
    153          
    154         # Create a new blog entry 
    155         response = self.client.post(self.add_entry_url, post_data) 
    156         self.failUnlessEqual(response.status_code, 200) 
    157         self.assertResponse( 
    158             response, 
    159             must_contain=( 
    160                 "New blog entry created.", 
    161                 "New tags created:", "unittest", "blog", "tags", 
    162                 "blog - all entries","tag cloud", "syndication feeds", 
    163             ), 
    164             must_not_contain=("Traceback", "Error",), 
    165         ) 
     174        self._create_new_blog_entry() 
    166175         
    167176        # Get the blog entry detail page as a staff user 
     
    201210        ) 
    202211         
    203         # TODO: 
    204 #        self.client.logout() 
    205 #        # Leave a comment as a anonymous user 
    206 #        response = self.client.post( 
    207 #            self.detail_url, 
    208 #            { 
    209 #                u'person_name': u'anonymous name', 
    210 #                u'email': u'email@address.tld', 
    211 #                u'homepage': u'http://homepage.tld', 
    212 #                u'content': u'the anonymous comment content.', 
    213 #            } 
    214 #        ) 
    215 #        self.failUnlessEqual(response.status_code, 200) 
    216 #        self.assertResponse( 
    217 #            response, 
    218 #            must_contain=( 
    219 #                "Your comment saved.", 
    220 #                "comments", 
    221 #                "the person name", "the comment content.", 
    222 #            ), 
    223 #            must_not_contain=("Traceback", "Error",), 
    224 #        ) 
     212    def test_anonymous_comment(self): 
     213        """ 
     214        Try to leave a comment as a anonymous user 
     215        """ 
     216        self._create_new_blog_entry() 
     217        self.client.logout() 
     218         
     219        commend_data = { 
     220            u'person_name': u'anonymous name', 
     221            u'email': u'email@address.tld', 
     222            u'homepage': u'http://homepage.tld', 
     223            u'content': u'the anonymous comment content.', 
     224        } 
     225         
     226        def test(check_referer, referer, must_contain): 
     227            """ 
     228            1. setup check_refere mode in the blog preferences 
     229            2. sent the post data 
     230            3. check the response 
     231            """ 
     232            Plugin.objects.set_preferences( 
     233                plugin_name="blog", 
     234                key = 'check_referer', 
     235                value = check_referer, 
     236                user=None, id=None 
     237            ) 
     238             
     239            response = self.client.post( 
     240                self.detail_url, 
     241                commend_data, 
     242                HTTP_REFERER=referer, 
     243            ) 
     244            self.failUnlessEqual(response.status_code, 200) 
     245            self.assertResponse( 
     246                response, 
     247                must_contain=must_contain, 
     248                must_not_contain=("Traceback", "Error",), 
     249            ) 
     250                 
     251        # Test with wrong http refere and "moderate" mode 
     252        test( 
     253            check_referer=self.blog_cfg.MODERATED, 
     254            referer = "wrong", 
     255            must_contain=( 
     256                "Your comment must wait for authorization.", 
     257                "Your comment saved.", 
     258                "comments", "there exist no comment", 
     259            ) 
     260        ) 
     261         
     262        # Test with wrong http refere and "spam reject" mode 
     263        test( 
     264            check_referer=self.blog_cfg.REJECT_SPAM, 
     265            referer = "wrong", 
     266            must_contain=( 
     267                "Sorry, your comment identify as spam.", 
     268                "comments", "there exist no comment", 
     269            ) 
     270        ) 
     271         
     272        # Test with the right referer 
     273        test( 
     274            check_referer=self.blog_cfg.MODERATED, 
     275            referer = "http://testserver/_command/1/blog/detail/1/", 
     276            must_contain=(                 
     277                "Your comment saved.", 
     278                "comments", 
     279                "anonymous name", "the anonymous comment content.", 
     280            ) 
     281        ) 
     282         
    225283         
    226284