Esempio n. 1
0
    def test_valid_category_badge(self):
        from formencode import Invalid
        from adhocracy.forms import ValidCategoryBadge
        from adhocracy.model import CategoryBadge, instance_filter

        # the currently set instance ist the test instance. CategoryBadges from
        # the current instance are valid.
        test_instance = tt_get_instance()
        self.assertEqual(test_instance, instance_filter.get_instance())
        test_category = CategoryBadge.create("test_category", "#ccc", "description", test_instance)
        value = ValidCategoryBadge.to_python(str(test_category.id))
        self.assertEqual(value, test_category)

        # from other instances they are not valid
        other_instance = tt_make_instance("other", "Other Instance")
        other_category = CategoryBadge.create("other_category", "#ccc", "description", other_instance)
        self.assertRaises(Invalid, ValidCategoryBadge.to_python, str(other_category.id))
Esempio n. 2
0
    def test_create_milestone_with_category_that_changes_instance(self):
        from adhocracy.model import CategoryBadge, meta
        milestone, creator = _make_one(u'title', u'text')
        category = CategoryBadge.create(u'Category', u'#ccc', True,
                                        u'descripiton', milestone.instance)
        milestone.category = category
        self.assertEqual(milestone.category.id, category.id)
        self.assertEqual(category.milestones, [milestone])

        # after we set another instance for the category (and refreshed
        # the objects in the Session), the milestone no longer has a category.
        other_instance = tt_make_instance(u'other', u'Other Label')
        category.instance = other_instance
        meta.Session.flush()
        meta.Session.refresh(milestone)
        meta.Session.refresh(category)
        self.assertNotEqual(category.instance, milestone.instance)
        self.assertEqual(milestone.category, None)
        self.assertEqual(category.milestones, [])
Esempio n. 3
0
    def test_create_milestone_with_category_that_changes_instance(self):
        from adhocracy.model import CategoryBadge, meta
        milestone, creator = _make_one(u'title', u'text')
        category = CategoryBadge.create(u'Category', u'#ccc', True,
                                        u'descripiton', 0, milestone.instance)
        milestone.category = category
        self.assertEqual(milestone.category.id, category.id)
        self.assertEqual(category.milestones, [milestone])

        # after we set another instance for the category (and refreshed
        # the objects in the Session), the milestone no longer has a category.
        other_instance = tt_make_instance(u'other', u'Other Label')
        category.instance = other_instance
        meta.Session.flush()
        meta.Session.refresh(milestone)
        meta.Session.refresh(category)
        self.assertNotEqual(category.instance, milestone.instance)
        self.assertEqual(milestone.category, None)
        self.assertEqual(category.milestones, [])
Esempio n. 4
0
 def setUp(self):
     super(ImportExportTest, self).setUp()
     self.u1 = testtools.tt_make_user()
     self.u1.gender = u'f'
     self.badge = model.UserBadge.create(
         title=u'importexport_badge"\'/\\ä↭𝕐',
         color=u'#ff00ff',
         visible=True,
         description=u'This badge tests',
     )
     self.u2 = testtools.tt_make_user()
     self.badge.assign(user=self.u1, creator=self.u2)
     self.instance = testtools.tt_make_instance(u'export_test',
                                                label=u'export_test',
                                                creator=self.u2)
     self.instance.label = u'test"\'/\\ä↭𝕐'
     self.instance.description = u'test"\'/\\ä↭𝕐'
     self.instance.required_majority = 0.42
     self.instance.activation_delay = 5
     self.instance.create_time = datetime.datetime.now()
     self.instance.access_time = datetime.datetime.now()
     self.instance.delete_time = None
     self.instance.default_group_id = 42
     self.instance.allow_adopt = False
     self.instance.allow_delegate = False
     self.instance.allow_propose = False
     self.instance.allow_index = False
     self.instance.hidden = False
     self.instance.locale = u'fr_FR'
     self.instance.css = u'test"\'/\\ä↭𝕐'
     self.instance.frozen = True
     self.instance.milestones = True
     self.instance.use_norms = False
     self.instance.require_selection = True
     self.instance.is_authenticated = True
     self.instance.hide_global_categories = True
     self.instance.editable_comments_default = False
     self.instance.editable_proposals_default = False
     self.instance.require_valid_email = False
     self.instance.allow_thumbnailbadges = True
     self.instance.thumbnailbadges_height = 42
     self.instance.thumbnailbadges_width = 42
Esempio n. 5
0
    def test_valid_category_badge(self):
        from formencode import Invalid
        from adhocracy.forms import ValidCategoryBadge
        from adhocracy.model import CategoryBadge, instance_filter

        # the currently set instance ist the test instance. CategoryBadges from
        # the current instance are valid.
        test_instance = tt_get_instance()
        self.assertEqual(test_instance, instance_filter.get_instance())
        test_category = CategoryBadge.create('test_category', '#ccc',
                                             'description', test_instance)
        value = ValidCategoryBadge.to_python(str(test_category.id))
        self.assertEqual(value, test_category)

        # from other instances they are not valid
        other_instance = tt_make_instance('other', 'Other Instance')
        other_category = CategoryBadge.create('other_category', '#ccc',
                                              'description', other_instance)
        self.assertRaises(Invalid, ValidCategoryBadge.to_python,
                          str(other_category.id))
Esempio n. 6
0
 def setUp(self):
     super(ImportExportTest, self).setUp()
     self.u1 = testtools.tt_make_user()
     self.u1.gender = u"f"
     self.badge = model.UserBadge.create(
         title=u"importexport_badge\"'/\\ä↭𝕐", color=u"#ff00ff", visible=True, description=u"This badge tests"
     )
     self.u2 = testtools.tt_make_user()
     self.badge.assign(user=self.u1, creator=self.u2)
     self.instance = testtools.tt_make_instance(u"export_test", label=u"export_test", creator=self.u2)
     self.instance.label = u"test\"'/\\ä↭𝕐"
     self.instance.description = u"test\"'/\\ä↭𝕐"
     self.instance.required_majority = 0.42
     self.instance.activation_delay = 5
     self.instance.create_time = datetime.datetime.now()
     self.instance.access_time = datetime.datetime.now()
     self.instance.delete_time = None
     self.instance.default_group_id = 42
     self.instance.allow_adopt = False
     self.instance.allow_delegate = False
     self.instance.allow_propose = False
     self.instance.allow_index = False
     self.instance.hidden = False
     self.instance.locale = u"fr_FR"
     self.instance.css = u"test\"'/\\ä↭𝕐"
     self.instance.frozen = True
     self.instance.milestones = True
     self.instance.use_norms = False
     self.instance.require_selection = True
     self.instance.is_authenticated = True
     self.instance.hide_global_categories = True
     self.instance.editable_comments_default = False
     self.instance.editable_proposals_default = False
     self.instance.require_valid_email = False
     self.instance.allow_thumbnailbadges = True
     self.instance.thumbnailbadges_height = 42
     self.instance.thumbnailbadges_width = 42