Ejemplo n.º 1
0
    def test_load_with_compound_primary_keys(self):
        # load() does not like compound primary keys.
        flags = [
            FeatureFlag(u'foo', 0, u'bar', u'true'),
            FeatureFlag(u'foo', 0, u'baz', u'false'),
            ]
        other_flag = FeatureFlag(u'notfoo', 0, u'notbar', u'true')
        for flag in flags + [other_flag]:
            getFeatureStore().add(flag)

        self.assertContentEqual(
            flags,
            bulk.load(FeatureFlag, [(ff.scope, ff.flag) for ff in flags]))
Ejemplo n.º 2
0
    def test_load_with_compound_primary_keys(self):
        # load() does not like compound primary keys.
        flags = [
            FeatureFlag(u'foo', 0, u'bar', u'true'),
            FeatureFlag(u'foo', 0, u'baz', u'false'),
        ]
        other_flag = FeatureFlag(u'notfoo', 0, u'notbar', u'true')
        for flag in flags + [other_flag]:
            getFeatureStore().add(flag)

        self.assertContentEqual(
            flags, bulk.load(FeatureFlag,
                             [(ff.scope, ff.flag) for ff in flags]))
Ejemplo n.º 3
0
 def append(diff, comment, person):
     """Append a FeatureFlagChangelogEntry to the ChangeLog."""
     store = getFeatureStore()
     feature_flag_change = FeatureFlagChangelogEntry(
         diff, comment, person)
     store.add(feature_flag_change)
     return feature_flag_change
Ejemplo n.º 4
0
    def setAllRules(self, new_rules):
        """Replace all existing rules with a new set.

        :param new_rules: List of (name, scope, priority, value) tuples.
        """
        # XXX: would be slightly better to only update rules as necessary so
        # we keep timestamps, and to avoid the direct sql etc -- mbp 20100924
        store = getFeatureStore()
        store.execute('DELETE FROM FeatureFlag')
        for (flag, scope, priority, value) in new_rules:
            store.add(
                FeatureFlag(scope=unicode(scope),
                            flag=unicode(flag),
                            value=value,
                            priority=priority))
        store.flush()
Ejemplo n.º 5
0
    def setAllRules(self, new_rules):
        """Replace all existing rules with a new set.

        :param new_rules: List of (name, scope, priority, value) tuples.
        """
        # XXX: would be slightly better to only update rules as necessary so
        # we keep timestamps, and to avoid the direct sql etc -- mbp 20100924
        store = getFeatureStore()
        store.execute('DELETE FROM FeatureFlag')
        for (flag, scope, priority, value) in new_rules:
            store.add(FeatureFlag(
                scope=unicode(scope),
                flag=unicode(flag),
                value=value,
                priority=priority))
        store.flush()
Ejemplo n.º 6
0
 def getAllRulesAsTuples(self):
     try:
         # This LBYL may look odd but it is needed. Rendering OOPSes and
         # timeouts also looks up flags, but doing such a lookup can
         # will cause a doom if the db request is not executed or is
         # canceled by the DB - and then results in a failure in
         # zope.app.publication.ZopePublication.handleError when it
         # calls transaction.commit.
         # By Looking this up first, we avoid this and also permit
         # code using flags to work in timed out requests (by appearing to
         # have no rules).
         adapter.get_request_remaining_seconds()
     except adapter.RequestExpired:
         return
     store = getFeatureStore()
     rs = (store.find(FeatureFlag).order_by(FeatureFlag.flag,
                                            Desc(FeatureFlag.priority)))
     for r in rs:
         yield Rule(str(r.flag), str(r.scope), r.priority, r.value)
Ejemplo n.º 7
0
 def getAllRulesAsTuples(self):
     try:
         # This LBYL may look odd but it is needed. Rendering OOPSes and
         # timeouts also looks up flags, but doing such a lookup can
         # will cause a doom if the db request is not executed or is
         # canceled by the DB - and then results in a failure in
         # zope.app.publication.ZopePublication.handleError when it
         # calls transaction.commit.
         # By Looking this up first, we avoid this and also permit
         # code using flags to work in timed out requests (by appearing to
         # have no rules).
         adapter.get_request_remaining_seconds()
     except adapter.RequestExpired:
         return
     store = getFeatureStore()
     rs = (store
             .find(FeatureFlag)
             .order_by(
                 FeatureFlag.flag,
                 Desc(FeatureFlag.priority)))
     for r in rs:
         yield Rule(str(r.flag), str(r.scope), r.priority, r.value)
Ejemplo n.º 8
0
 def get():
     """return a result set of `FeatureFlagChangelogEntry` items."""
     store = getFeatureStore()
     rs = store.find(FeatureFlagChangelogEntry)
     rs.order_by(Desc(FeatureFlagChangelogEntry.date_changed))
     return rs
Ejemplo n.º 9
0
 def enable_queue_flag(self):
     getFeatureStore().add(FeatureFlag(
         scope=u'default', flag=u'code.branchmergequeue',
         value=u'on', priority=1))
Ejemplo n.º 10
0
 def test_defaultEmptyCollection(self):
     # there are no settings in the sampledata
     store = getFeatureStore()
     self.assertTrue(store.find(FeatureFlag).is_empty())
 def enable_queue_flag(self):
     getFeatureStore().add(FeatureFlag(
         scope=u'default', flag=u'code.branchmergequeue',
         value=u'on', priority=1))
Ejemplo n.º 12
0
 def append(diff, comment, person):
     """Append a FeatureFlagChangelogEntry to the ChangeLog."""
     store = getFeatureStore()
     feature_flag_change = FeatureFlagChangelogEntry(diff, comment, person)
     store.add(feature_flag_change)
     return feature_flag_change
Ejemplo n.º 13
0
 def get():
     """return a result set of `FeatureFlagChangelogEntry` items."""
     store = getFeatureStore()
     rs = store.find(FeatureFlagChangelogEntry)
     rs.order_by(Desc(FeatureFlagChangelogEntry.date_changed))
     return rs