def test_enabled(self): from woost.models import Publishable, ReadPermission self.everybody_role.permissions.append( ReadPermission(matching_items={ "type": "woost.models.publishable.Publishable" })) a = Publishable() a.enabled = True a.insert() b = Publishable() b.enabled = False b.insert() c = Publishable() c.enabled = True c.insert() d = Publishable() d.enabled = False d.insert() assert self.accessible_items() == set([a, c])
def test_current(self): from woost.models import Publishable, ReadPermission from datetime import datetime, timedelta self.everybody_role.permissions.append( ReadPermission(matching_items={ "type": "woost.models.publishable.Publishable" })) now = datetime.now() a = Publishable() a.enabled = True a.insert() b = Publishable() b.enabled = True b.start_date = now b.end_date = now + timedelta(days=1) b.insert() c = Publishable() c.enabled = True c.start_date = now + timedelta(days=1) c.insert() d = Publishable() d.enabled = True d.end_date = now - timedelta(days=1) d.insert() assert self.accessible_items() == set([a, b])
def test_translation_enabled(self): from cocktail.translations import language_context from woost.models import (Publishable, ReadPermission, ReadTranslationPermission) self.everybody_role.permissions.append( ReadPermission(matching_items={ "type": "woost.models.publishable.Publishable" })) self.everybody_role.permissions.append(ReadTranslationPermission()) self.config.languages = ["en"] self.config.published_languages = [] with language_context("en"): a = Publishable() a.per_language_publication = True a.translation_enabled = True a.insert() b = Publishable() b.per_language_publication = True b.translation_enabled = False b.insert() c = Publishable() c.per_language_publication = True c.translation_enabled = True c.insert() d = Publishable() d.per_language_publication = True d.set("translation_enabled", True, "de") d.insert() e = Publishable() e.per_language_publication = False e.enabled = True e.insert() accessible = self.accessible_items() print a in accessible print b in accessible print c in accessible print d in accessible print e in accessible assert self.accessible_items() == set([a, c, e]) self.config.published_languages = ["en"] assert self.accessible_items() == set([a, c, e]) with language_context("de"): self.config.published_languages = ["de"] assert self.accessible_items() == set([d, e])
def test_allowed(self): from woost.models import Publishable, ReadPermission a = Publishable() a.enabled = True a.insert() b = Publishable() b.enabled = True b.insert() self.everybody_role.permissions.append( ReadPermission( matching_items={ "type": "woost.models.publishable.Publishable", "filter": "member-id", "filter_operator0": "ne", "filter_value0": str(b.id) })) assert self.accessible_items() == set([a])