def test_authenticate(self):
     self.assertRaises(Fault, authenticate, "badcontributor", "badpassword")
     self.assertRaises(Fault, authenticate, "contributor", "badpassword")
     self.assertRaises(Fault, authenticate, "contributor", "password")
     self.contributor.is_staff = True
     self.contributor.save()
     self.assertEqual(authenticate("contributor", "password"), self.contributor)
     self.assertRaises(Fault, authenticate, "contributor", "password", "zinnia.change_entry")
     self.assertEqual(authenticate("webmaster", "password"), self.webmaster)
     self.assertEqual(authenticate("webmaster", "password", "zinnia.change_entry"), self.webmaster)
 def test_authenticate(self):
     self.assertRaises(Fault, authenticate, 'badcontributor', 'badpassword')
     self.assertRaises(Fault, authenticate, 'contributor', 'badpassword')
     self.assertRaises(Fault, authenticate, 'contributor', 'password')
     self.contributor.is_staff = True
     self.contributor.save()
     self.assertEquals(authenticate('contributor', 'password'), self.contributor)
     self.assertRaises(Fault, authenticate, 'contributor', 'password', 'zinnia.change_entry')
     self.assertEquals(authenticate('webmaster', 'password'), self.webmaster)
     self.assertEquals(authenticate('webmaster', 'password', 'zinnia.change_entry'),
                       self.webmaster)
Exemple #3
0
 def test_authenticate(self):
     self.assertRaises(Fault, authenticate, 'badcontributor', 'badpassword')
     self.assertRaises(Fault, authenticate, 'contributor', 'badpassword')
     self.assertRaises(Fault, authenticate, 'contributor', 'password')
     self.contributor.is_staff = True
     self.contributor.save()
     self.assertEqual(authenticate('contributor', 'password'),
                      self.contributor)
     self.assertRaises(Fault, authenticate, 'contributor', 'password',
                       'zinnia.change_entry')
     self.assertEqual(authenticate('webmaster', 'password'), self.webmaster)
     self.assertEqual(
         authenticate('webmaster', 'password', 'zinnia.change_entry'),
         self.webmaster)
Exemple #4
0
def get_recent_posts(blog_id, username, password, number):
    """metaWeblog.getRecentPosts(blog_id, username, password, number)
    => post structure[]"""
    user = metaweblog.authenticate(username, password)
    site = Site.objects.get_current()
    return [post_structure(entry, site) \
            for entry in Entry.objects.filter(authors=user, sites__id=blog_id)[:number]]
Exemple #5
0
def get_post_categories(post_id, username, password):
    """mt.getPostCategories(post_id, username, password)
    => struct[]"""
    user = metaweblog.authenticate(username, password)
    site = Site.objects.get_current()
    entry = Entry.objects.get(id=post_id, authors=user)
    return [metaweblog.category_structure(category, site) \
        for category in entry.categories.all()]
Exemple #6
0
def set_post_categories(post_id, username, password, categories):
    """mt.setPostCategories(post_id, username, password, categories)
    => boolean"""
    user = metaweblog.authenticate(username, password)
    entry = Entry.objects.get(id=post_id, authors=user)
    try:
        entry.categories.clear()
        entry.categories.add(*[Category.objects.get_or_create(
            title=cat['categoryName'], slug=slugify(cat['categoryName']))[0]
                           for cat in categories])
        return True
    except Exception as e:
        logger.error(e)
        return False
Exemple #7
0
def update_post_status(post_id, username, password, post):
    # Update status as appropriate
    if u'post_status' in post:
        user = metaweblog.authenticate(username, password, 'zinnia.change_entry')
        entry = Entry.objects.get(id=post_id, authors=user)
        post_status = post.get('post_status')
        if post_status == u'private':
            entry.login_required = True
            entry.status = PUBLISHED
        else:
            entry.login_required = False
            if post_status == u'draft':
                entry.status = DRAFT
            elif post_status == u'pending':
                entry.status = HIDDEN
            else:
                entry.status = PUBLISHED
        entry.save()
Exemple #8
0
def get_post(post_id, username, password):
    """metaWeblog.getPost(post_id, username, password)
    => post structure"""
    user = metaweblog.authenticate(username, password)
    site = Site.objects.get_current()
    return post_structure(Entry.objects.get(id=post_id, authors=user), site)