예제 #1
0
 def test_publication_logic(self):
     """
     Verify that unpublished entries cannot be viewed
     """
     unpub_state = filter(
         lambda s: s[0] not in BloggingSettings.PUBLISHED_ENTRY_STATES,
         BloggingSettings.PUB_STATES
     )[0][0]
     pub_state = BloggingSettings.PUBLISHED_ENTRY_STATES[0]
     slug = 'publication-test'
     # Start by creating a new, unpublished entry:
     entry = TumblelogEntry(
         slug=slug,
         title='Headline TKTK',
         post='Loren ipsum...',
         author=Author.objects.all()[0], #any author is fine...
         status=unpub_state,
     )
     entry.save()
     # Trying to view it should show a 404:
     response = self.client.get(entry.get_absolute_url())
     self.assertTrue(response.status_code == 404)
     # Now publish it:
     entry.status = pub_state
     entry.save()
     # Should be visible:
     response = self.client.get(entry.get_absolute_url())
     self.assertTrue(response.status_code == 200)
예제 #2
0
 def create_sample_tumblelog_entries(klass, count=50):
     """
     Create N number of sample tumblelog entries where N = the count 
     parameter. Text in posts till be random lorem ipsum text. Author will be
     a randomly selected author from the system, and date will be a random 
     date from the last 2 years. All test entries will be marked "published".
     """    
     klass._setup(TumblelogEntry, count)
     while count > 0:
         title = words(randrange(3,12), common=False).capitalize()
         slug = klass._check_slug(slugify(title)[:klass.field_len])
         b = TumblelogEntry(
             slug = slug,
             title= title,
             post = klass._join_paras(
                 paragraphs(randrange(1,3), common=False)
             ),
             pub_date = klass._get_rand_date(),
             status = BloggingSettings.PUBLISHED_ENTRY_STATES[0],
             author = Author.objects.order_by('?')[0]
         )
         b.save()
         count += -1