本文整理汇总了Python中waffle.sample_is_active函数的典型用法代码示例。如果您正苦于以下问题:Python sample_is_active函数的具体用法?Python sample_is_active怎么用?Python sample_is_active使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sample_is_active函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sample_inactive_all_sites_override
def test_sample_inactive_all_sites_override(self):
name = 'mysample'
Sample.objects.create(name=name, percent='0.0', site=self.site1)
self.assertFalse(waffle.sample_is_active(get(), name))
with self.settings(SITE_ID=2):
self.assertFalse(waffle.sample_is_active(get(), name))
示例2: test_sample_site_default
def test_sample_site_default(self):
name = "sample"
sample = Sample.objects.create(name=name, percent="100.0") # no site given
self.assertTrue(waffle.sample_is_active(get(), name))
with self.settings(SITE_ID=2):
self.assertTrue(waffle.sample_is_active(get(), name))
示例3: test_sample_by_site
def test_sample_by_site(self):
name = "sample"
sample1 = Sample.objects.create(name=name, percent="100.0", site=self.site1)
sample2 = Sample.objects.create(name=name, percent="0.0", site=self.site2)
self.assertTrue(waffle.sample_is_active(get(), name))
with self.settings(SITE_ID=2):
self.assertFalse(waffle.sample_is_active(get(), name))
示例4: test_sample_did_not_exist
def test_sample_did_not_exist(self):
assert not Sample.objects.filter(name="foo").exists()
with override_sample("foo", active=True):
assert waffle.sample_is_active(req(), "foo")
with override_sample("foo", active=False):
assert not waffle.sample_is_active(req(), "foo")
assert not Sample.objects.filter(name="foo").exists()
示例5: test_sample_existed_and_was_50
def test_sample_existed_and_was_50(self):
Sample.objects.create(name="foo", percent="50.0")
with override_sample("foo", active=True):
assert waffle.sample_is_active(req(), "foo")
with override_sample("foo", active=False):
assert not waffle.sample_is_active("foo")
self.assertEquals(Decimal("50.0"), Sample.objects.get(name="foo").percent)
示例6: test_sample_did_not_exist
def test_sample_did_not_exist(self):
assert not Sample.objects.filter(name='foo').exists()
with override_sample('foo', active=True):
assert waffle.sample_is_active('foo')
with override_sample('foo', active=False):
assert not waffle.sample_is_active('foo')
assert not Sample.objects.filter(name='foo').exists()
示例7: test_cache_is_flushed_by_testutils_even_in_transaction
def test_cache_is_flushed_by_testutils_even_in_transaction(self):
Sample.objects.create(name='foo', percent='100.0')
with transaction.atomic():
with override_sample('foo', active=True):
assert waffle.sample_is_active('foo')
with override_sample('foo', active=False):
assert not waffle.sample_is_active('foo')
assert waffle.sample_is_active('foo')
示例8: test_sample_existed_and_was_50
def test_sample_existed_and_was_50(self):
Sample.objects.create(name='foo', percent='50.0')
with override_sample('foo', active=True):
assert waffle.sample_is_active('foo')
with override_sample('foo', active=False):
assert not waffle.sample_is_active('foo')
self.assertEquals(Decimal('50.0'),
Sample.objects.get(name='foo').percent)
示例9: test_read_from_write_db
def test_read_from_write_db(self):
sample = Sample.objects.create(name='sample', percent='100.0')
# By default, sample_is_active should hit whatever it configured as the
# read DB (so values will be stale if replication is lagged).
assert not waffle.sample_is_active(sample.name)
with override_settings(WAFFLE_READ_FROM_WRITE_DB=True):
# Save the sample again to flush the cache.
sample.save()
# The next read should now be directed to the write DB, ensuring
# the cache and DB are in sync.
assert waffle.sample_is_active(sample.name)
示例10: cspreport
def cspreport(request):
"""Accept CSP reports and log them."""
report = ("blocked-uri", "violated-directive", "original-policy")
if not waffle.sample_is_active("csp-store-reports"):
return HttpResponse()
try:
v = json.loads(request.body)["csp-report"]
# If possible, alter the PATH_INFO to contain the request of the page
# the error occurred on, spec: http://mzl.la/P82R5y
meta = request.META.copy()
meta["PATH_INFO"] = v.get("document-uri", meta["PATH_INFO"])
v = [(k, v[k]) for k in report if k in v]
log_cef(
"CSPViolation",
5,
meta,
username=request.user,
signature="CSPREPORT",
msg="A client reported a CSP violation",
cs6=v,
cs6Label="ContentPolicy",
)
except (KeyError, ValueError), e:
log.debug("Exception in CSP report: %s" % e, exc_info=True)
return HttpResponseBadRequest()
示例11: cspreport
def cspreport(request):
"""Accept CSP reports and log them."""
report = ("blocked-uri", "violated-directive", "original-policy")
if not waffle.sample_is_active("csp-store-reports"):
return HttpResponse()
try:
v = json.loads(request.raw_post_data)["csp-report"]
# CEF module wants a dictionary of environ, we want request
# to be the page with error on it, that's contained in the csp-report
# so we need to modify the meta before we pass in to the logger
meta = request.META.copy()
method, url = v["request"].split(" ", 1)
meta.update({"REQUEST_METHOD": method, "PATH_INFO": url})
v = [(k, v[k]) for k in report if k in v]
log_cef(
"CSP Violation",
5,
meta,
username=request.user,
signature="CSPREPORT",
msg="A client reported a CSP violation",
cs7=v,
cs7Label="ContentPolicy",
)
except Exception, e:
log.debug("Exception in CSP report: %s" % e, exc_info=True)
return HttpResponseBadRequest()
示例12: _generate_waffle_js
def _generate_waffle_js(request):
flags = cache.get(keyfmt(FLAGS_ALL_CACHE_KEY))
if not flags:
flags = Flag.objects.values_list("name", flat=True)
cache.add(keyfmt(FLAGS_ALL_CACHE_KEY), flags)
flag_values = [(f, flag_is_active(request, f)) for f in flags]
switches = cache.get(keyfmt(SWITCHES_ALL_CACHE_KEY))
if not switches:
switches = Switch.objects.values_list("name", "active")
cache.add(keyfmt(SWITCHES_ALL_CACHE_KEY), switches)
samples = cache.get(keyfmt(SAMPLES_ALL_CACHE_KEY))
if not samples:
samples = Sample.objects.values_list("name", flat=True)
cache.add(keyfmt(SAMPLES_ALL_CACHE_KEY), samples)
sample_values = [(s, sample_is_active(s)) for s in samples]
flag_default = getattr(settings, "WAFFLE_FLAG_DEFAULT", False)
switch_default = getattr(settings, "WAFFLE_SWITCH_DEFAULT", False)
sample_default = getattr(settings, "WAFFLE_SAMPLE_DEFAULT", False)
return loader.render_to_string(
"waffle/waffle.js",
{
"flags": flag_values,
"switches": switches,
"samples": sample_values,
"flag_default": flag_default,
"switch_default": switch_default,
"sample_default": sample_default,
},
)
示例13: _generate_waffle_js
def _generate_waffle_js(request):
flags = cache.get(keyfmt(get_setting('ALL_FLAGS_CACHE_KEY')))
if flags is None:
flags = Flag.objects.values_list('name', flat=True)
cache.add(keyfmt(get_setting('ALL_FLAGS_CACHE_KEY')), flags)
flag_values = [(f, flag_is_active(request, f)) for f in flags]
switches = cache.get(keyfmt(get_setting('ALL_SWITCHES_CACHE_KEY')))
if switches is None:
switches = Switch.objects.values_list('name', 'active')
cache.add(keyfmt(get_setting('ALL_SWITCHES_CACHE_KEY')), switches)
samples = cache.get(keyfmt(get_setting('ALL_SAMPLES_CACHE_KEY')))
if samples is None:
samples = Sample.objects.values_list('name', flat=True)
cache.add(keyfmt(get_setting('ALL_SAMPLES_CACHE_KEY')), samples)
sample_values = [(s, sample_is_active(s)) for s in samples]
return loader.render_to_string('waffle/waffle.js', {
'flags': flag_values,
'switches': switches,
'samples': sample_values,
'flag_default': get_setting('FLAG_DEFAULT'),
'switch_default': get_setting('SWITCH_DEFAULT'),
'sample_default': get_setting('SAMPLE_DEFAULT'),
})
示例14: _generate_waffle_js
def _generate_waffle_js(request):
flags = cache.get(keyfmt(FLAGS_ALL_CACHE_KEY))
if not flags:
flags = Flag.objects.values_list('name', flat=True)
cache.add(keyfmt(FLAGS_ALL_CACHE_KEY), flags)
flag_values = [(f, flag_is_active(request, f)) for f in flags]
switches = cache.get(keyfmt(SWITCHES_ALL_CACHE_KEY))
if not switches:
switches = Switch.objects.values_list('name', 'active')
cache.add(keyfmt(SWITCHES_ALL_CACHE_KEY), switches)
samples = cache.get(keyfmt(SAMPLES_ALL_CACHE_KEY))
if not samples:
samples = Sample.objects.values_list('name', flat=True)
cache.add(keyfmt(SAMPLES_ALL_CACHE_KEY), samples)
sample_values = [(s, sample_is_active(s)) for s in samples]
flag_default = getattr(settings, 'WAFFLE_FLAG_DEFAULT', False)
switch_default = getattr(settings, 'WAFFLE_SWITCH_DEFAULT', False)
sample_default = getattr(settings, 'WAFFLE_SAMPLE_DEFAULT', False)
return loader.render_to_string('waffle/waffle.js',
{
'flags': flag_values,
'switches': switches,
'samples': sample_values,
'flag_default': flag_default,
'switch_default': switch_default,
'sample_default': sample_default,
})
示例15: wafflejs
def wafflejs(request):
flags = cache.get(keyfmt(FLAGS_ALL_CACHE_KEY))
if not flags:
flags = Flag.objects.values_list('name', flat=True)
cache.add(keyfmt(FLAGS_ALL_CACHE_KEY), flags)
flag_values = [(f, flag_is_active(request, f)) for f in flags]
switches = cache.get(keyfmt(SWITCHES_ALL_CACHE_KEY))
if not switches:
switches = Switch.objects.values_list('name', 'active')
cache.add(keyfmt(SWITCHES_ALL_CACHE_KEY), switches)
samples = cache.get(keyfmt(SAMPLES_ALL_CACHE_KEY))
if not samples:
samples = Sample.objects.values_list('name', flat=True)
cache.add(keyfmt(SAMPLES_ALL_CACHE_KEY), samples)
sample_values = [(s, sample_is_active(s)) for s in samples]
flag_default = getattr(settings, 'WAFFLE_FLAG_DEFAULT', False)
switch_default = getattr(settings, 'WAFFLE_SWITCH_DEFAULT', False)
sample_default = getattr(settings, 'WAFFLE_SAMPLE_DEFAULT', False)
return render_to_response('waffle/waffle.js',
{
'flags': flag_values,
'switches': switches,
'samples': sample_values,
'flag_default': flag_default,
'switch_default': switch_default,
'sample_default': sample_default,
},
mimetype='application/x-javascript')