本文整理汇总了Python中pykeg.backend.get_kegbot_backend函数的典型用法代码示例。如果您正苦于以下问题:Python get_kegbot_backend函数的具体用法?Python get_kegbot_backend怎么用?Python get_kegbot_backend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_kegbot_backend函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_privacy
def test_privacy(self):
b = get_kegbot_backend()
keg = b.start_keg(
"kegboard.flow0",
beverage_name="Unknown",
producer_name="Unknown",
beverage_type="beer",
style_name="Unknown",
)
self.assertIsNotNone(keg)
d = b.record_drink("kegboard.flow0", ticks=100)
# URLs to expected contents
urls = {
"/kegs/": "Keg List",
"/stats/": "System Stats",
"/sessions/": "All Sessions",
"/kegs/{}".format(keg.id): "Keg {}".format(keg.id),
"/drinks/{}".format(d.id): "Drink {}".format(d.id),
}
def test_urls(expect_fail, urls=urls):
for url, expected_content in urls.iteritems():
response = self.client.get(url)
if expect_fail:
self.assertNotContains(response, expected_content, status_code=401, msg_prefix=url)
else:
self.assertContains(response, expected_content, status_code=200, msg_prefix=url)
b = get_kegbot_backend()
user = b.create_new_user("testuser", "[email protected]", password="1234")
kbsite = models.KegbotSite.get()
self.client.logout()
# Public mode.
test_urls(expect_fail=False)
# Members-only.
kbsite.privacy = "members"
kbsite.save()
test_urls(expect_fail=True)
logged_in = self.client.login(username="testuser", password="1234")
self.assertTrue(logged_in)
test_urls(expect_fail=False)
# Staff-only
kbsite.privacy = "staff"
kbsite.save()
test_urls(expect_fail=True)
user.is_staff = True
user.save()
test_urls(expect_fail=False)
self.client.logout()
test_urls(expect_fail=True)
开发者ID:vmtyler,项目名称:kegbot-server,代码行数:56,代码来源:kegweb_test.py
示例2: test_privacy
def test_privacy(self):
b = get_kegbot_backend()
keg = b.start_keg('kegboard.flow0', beverage_name='Unknown', producer_name='Unknown',
beverage_type='beer', style_name='Unknown')
self.assertIsNotNone(keg)
d = b.record_drink('kegboard.flow0', ticks=100)
drink_id = d.id
# URLs to expected contents
urls = {
'/kegs/': 'Keg List',
'/stats/': 'System Stats',
'/sessions/': 'All Sessions',
'/kegs/{}'.format(keg.id): 'Keg {}'.format(keg.id),
'/drinks/{}'.format(d.id): 'Drink {}'.format(d.id),
}
def test_urls(expect_fail, urls=urls):
for url, expected_content in urls.iteritems():
response = self.client.get(url)
if expect_fail:
self.assertNotContains(response, expected_content, status_code=401,
msg_prefix=url)
else:
self.assertContains(response, expected_content, status_code=200,
msg_prefix=url)
b = get_kegbot_backend()
user = b.create_new_user('testuser', '[email protected]', password='1234')
kbsite = models.KegbotSite.get()
self.client.logout()
# Public mode.
test_urls(expect_fail=False)
# Members-only.
kbsite.privacy = 'members'
kbsite.save()
test_urls(expect_fail=True)
logged_in = self.client.login(username='testuser', password='1234')
self.assertTrue(logged_in)
test_urls(expect_fail=False)
# Staff-only
kbsite.privacy = 'staff'
kbsite.save()
test_urls(expect_fail=True)
user.is_staff = True
user.save()
test_urls(expect_fail=False)
self.client.logout()
test_urls(expect_fail=True)
开发者ID:mik3y,项目名称:kegbot-server,代码行数:54,代码来源:kegweb_test.py
示例3: process_request
def process_request(self, request):
epoch = None
request.need_setup = False
request.need_upgrade = False
request.kbsite = None
# Select only the `epoch` column, as pending database migrations could
# make a full select crash.
rows = models.KegbotSite.objects.filter(name='default').values('epoch')
if not rows:
request.need_setup = True
elif rows[0].get('epoch', 0) < EPOCH:
request.need_upgrade = True
else:
request.kbsite = models.KegbotSite.objects.get(name='default')
if request.kbsite.is_setup:
timezone.activate(request.kbsite.timezone)
request.plugins = dict((p.get_short_name(), p) for p in plugin_util.get_plugins())
else:
request.need_setup = True
request.kbcache = KegbotCache()
request.backend = get_kegbot_backend()
return None
开发者ID:mik3y,项目名称:kegbot-server,代码行数:25,代码来源:middleware.py
示例4: testBasicEndpoints
def testBasicEndpoints(self):
for endpoint in ('/kegs/', '/stats/'):
response = self.client.get(endpoint)
self.assertEquals(200, response.status_code)
for endpoint in ('/sessions/',):
response = self.client.get(endpoint)
self.assertEquals(404, response.status_code)
b = get_kegbot_backend()
keg = b.start_keg('kegboard.flow0', beverage_name='Unknown', producer_name='Unknown',
beverage_type='beer', style_name='Unknown')
self.assertIsNotNone(keg)
response = self.client.get('/kegs/')
self.assertEquals(200, response.status_code)
d = b.record_drink('kegboard.flow0', ticks=100)
drink_id = d.id
response = self.client.get('/d/%s' % drink_id, follow=True)
self.assertRedirects(response, '/drinks/%s' % drink_id, status_code=301)
session_id = d.session.id
response = self.client.get('/s/%s' % session_id, follow=True)
self.assertRedirects(response, d.session.get_absolute_url(), status_code=301)
开发者ID:mik3y,项目名称:kegbot-server,代码行数:25,代码来源:kegweb_test.py
示例5: testShout
def testShout(self):
b = get_kegbot_backend()
keg = b.start_keg('kegboard.flow0', beverage_name='Unknown', producer_name='Unknown',
beverage_type='beer', style_name='Unknown')
d = b.record_drink('kegboard.flow0', ticks=123, shout='_UNITTEST_')
response = self.client.get(d.get_absolute_url())
self.assertContains(response, '<p>_UNITTEST_</p>', status_code=200)
开发者ID:mik3y,项目名称:kegbot-server,代码行数:7,代码来源:kegweb_test.py
示例6: save
def save(self, tap):
if not self.is_valid():
raise ValueError('Form is not valid.')
b = get_kegbot_backend()
if tap.is_active():
b.end_keg(tap.current_keg)
keg_size = self.cleaned_data.get('keg_size')
full_volume_ml = self.cleaned_data.get('full_volume_ml')
if keg_size != 'other':
full_volume_ml = None
else:
full_volume_ml = self.cleaned_data.get('initial_volume')
# TODO(mikey): Support non-beer beverage types.
cd = self.cleaned_data
keg = b.start_keg(tap, beverage_name=cd['beverage_name'], producer_name=cd['producer_name'],
beverage_type='beer', style_name=cd['style_name'], keg_type=cd['keg_size'],
full_volume_ml=full_volume_ml)
if cd.get('description'):
keg.description = cd['description']
keg.save()
开发者ID:Kegbot,项目名称:kegbot-server,代码行数:25,代码来源:forms.py
示例7: testBasicEndpoints
def testBasicEndpoints(self):
for endpoint in ("/kegs/", "/stats/", "/drinkers/guest/", "/drinkers/guest/sessions/"):
response = self.client.get(endpoint)
self.assertEquals(200, response.status_code)
for endpoint in ("/sessions/",):
response = self.client.get(endpoint)
self.assertEquals(404, response.status_code)
b = get_kegbot_backend()
keg = b.start_keg(
"kegboard.flow0",
beverage_name="Unknown",
producer_name="Unknown",
beverage_type="beer",
style_name="Unknown",
)
self.assertIsNotNone(keg)
response = self.client.get("/kegs/")
self.assertEquals(200, response.status_code)
d = b.record_drink("kegboard.flow0", ticks=100)
drink_id = d.id
response = self.client.get("/d/%s" % drink_id, follow=True)
self.assertRedirects(response, "/drinks/%s" % drink_id, status_code=301)
session_id = d.session.id
response = self.client.get("/s/%s" % session_id, follow=True)
self.assertRedirects(response, d.session.get_absolute_url(), status_code=301)
开发者ID:vmtyler,项目名称:kegbot-server,代码行数:30,代码来源:kegweb_test.py
示例8: setUp
def setUp(self):
self.backend = get_kegbot_backend()
defaults.set_defaults(set_is_setup=True)
self.user = core_models.User.objects.create(username='notification_user',
email='[email protected]')
# Password reset requires a usable password.
self.user.set_password('1234')
self.user.save()
开发者ID:Indemnity83,项目名称:kegbot-server,代码行数:10,代码来源:registration_test.py
示例9: setUp
def setUp(self):
self.backend = get_kegbot_backend()
defaults.set_defaults(set_is_setup=True, create_controller=True)
self.user = models.User.objects.create(username='notification_user',
email='[email protected]')
self.prefs = models.NotificationSettings.objects.create(user=self.user,
backend='pykeg.notification.backends.email.EmailNotificationBackend',
keg_tapped=False, session_started=False, keg_volume_low=False,
keg_ended=False)
开发者ID:Indemnity83,项目名称:kegbot-server,代码行数:11,代码来源:email_test.py
示例10: register
def register(request):
context = RequestContext(request)
form = KegbotRegistrationForm()
# Check if we need an invitation before processing the request further.
invite = None
if request.kbsite.registration_mode != "public":
invite_code = None
if "invite_code" in request.GET:
invite_code = request.GET["invite_code"]
request.session["invite_code"] = invite_code
else:
invite_code = request.session.get("invite_code", None)
if not invite_code:
r = render_to_response("registration/invitation_required.html", context_instance=context)
r.status_code = 401
return r
try:
invite = models.Invitation.objects.get(invite_code=invite_code)
except models.Invitation.DoesNotExist:
pass
if not invite or invite.is_expired():
r = render_to_response("registration/invitation_expired.html", context_instance=context)
r.status_code = 401
return r
if request.method == "POST":
form = KegbotRegistrationForm(request.POST)
if form.is_valid():
username = form.cleaned_data["username"]
email = form.cleaned_data["email"]
password = form.cleaned_data.get("password1")
backend = get_kegbot_backend()
backend.create_new_user(username=username, email=email, password=password)
if invite:
invite.delete()
if "invite_code" in request.session:
del request.session["invite_code"]
if password:
new_user = authenticate(username=username, password=password)
login(request, new_user)
return redirect("kb-account-main")
return render_to_response("registration/registration_complete.html", context_instance=context)
context["form"] = form
return render_to_response("registration/registration_form.html", context_instance=context)
开发者ID:rasem,项目名称:kegbot-server,代码行数:53,代码来源:views.py
示例11: testShout
def testShout(self):
b = get_kegbot_backend()
b.start_keg(
"kegboard.flow0",
beverage_name="Unknown",
producer_name="Unknown",
beverage_type="beer",
style_name="Unknown",
)
d = b.record_drink("kegboard.flow0", ticks=123, shout="_UNITTEST_")
response = self.client.get(d.get_absolute_url())
self.assertContains(response, "<p>_UNITTEST_</p>", status_code=200)
开发者ID:vmtyler,项目名称:kegbot-server,代码行数:12,代码来源:kegweb_test.py
示例12: setUp
def setUp(self):
models.KegbotSite.get() # create the site
self.backend = get_kegbot_backend()
self.producer = models.BeverageProducer.objects.create(
name='Moonshine Beers',
country='USA',
origin_state='Anystate',
origin_city='Bathtub',
url='http://example.com/',
description='Pretty bad beers.',
)
self.beverage = models.Beverage.objects.create(
name='Moonshine Porter',
producer=self.producer,
style='Porter',
calories_per_ml=3.0,
carbs_per_ml=10.0,
abv_percent=0.05,
)
self.keg = models.Keg.objects.create(
type=self.beverage,
keg_type='other',
start_time=make_datetime(2000, 4, 1),
end_time=make_datetime(2000, 5, 1),
description='Our first keg!',
full_volume_ml=2000,
)
self.tap = models.KegTap.objects.create(
name='Test Tap',
current_keg=self.keg,
)
self.controller = models.Controller.objects.create(
name='kegboard'
)
self.meter = models.FlowMeter.objects.create(
controller=self.controller,
port_name='flow0',
ticks_per_ml=2.2,
tap=self.tap
)
self.user = models.User.objects.create(
username='kb_tester',
)
self.user2 = models.User.objects.create(
username='kb_tester2',
)
开发者ID:iargue,项目名称:kegbot-server,代码行数:53,代码来源:models_test.py
示例13: save
def save(self):
if not self.is_valid():
raise ValueError('Form is not valid.')
keg_size = self.cleaned_data.get('keg_size')
if keg_size != 'other':
full_volume_ml = None
else:
full_volume_ml = self.cleaned_data.get('initial_volume')
# TODO(mikey): Support non-beer beverage types.
cd = self.cleaned_data
b = get_kegbot_backend()
keg = b.create_keg(beverage=cd['beverage_name'], keg_type=cd['keg_size'])
return keg
开发者ID:StewartJarod,项目名称:kegbot-server,代码行数:14,代码来源:forms.py
示例14: setUp
def setUp(self):
self.backend = get_kegbot_backend()
models.User.objects.create_user('guest')
test_usernames = ('user1', 'user2', 'user3')
self.users = [self.backend.create_new_user(name, '%[email protected]' % name) for name in test_usernames]
self.taps = [
self.backend.create_tap('tap1', 'kegboard.flow0', ticks_per_ml=2.2),
self.backend.create_tap('tap2', 'kegboard.flow1', ticks_per_ml=2.2),
]
self.keg = self.backend.start_keg('kegboard.flow0', beverage_name='Unknown',
beverage_type='beer', producer_name='Unknown', style_name='Unknown')
开发者ID:Indemnity83,项目名称:kegbot-server,代码行数:14,代码来源:stats_test.py
示例15: setUp
def setUp(self):
self.datastore = InMemoryDatastore(plugin.UntappdPlugin.get_short_name())
self.fsq = FoursquarePlugin(datastore=self.datastore)
self.fake_plugin_registry = {'foursquare': self.fsq}
self.plugin = plugin.UntappdPlugin(datastore=self.datastore,
plugin_registry=self.fake_plugin_registry)
self.user = models.User.objects.create(username='untappd_test')
self.backend = get_kegbot_backend()
self.tap = self.backend.create_tap('Test Tap', 'test.flow0')
self.keg = self.backend.start_keg(tap=self.tap, beverage_name='Test Beer',
beverage_type='beer', producer_name='Test Producer', style_name='Test Style')
self.beverage = self.keg.type
self.beverage.untappd_beer_id = '9876'
self.beverage.save()
开发者ID:Indemnity83,项目名称:kegbot-server,代码行数:16,代码来源:untappd_test.py
示例16: setUp
def setUp(self):
self.datastore = InMemoryDatastore(plugin.FoursquarePlugin.get_short_name())
self.plugin = plugin.FoursquarePlugin(datastore=self.datastore)
self.user = models.User.objects.create(username='foursquare_test')
self.backend = get_kegbot_backend()
self.tap = self.backend.create_tap('Test Tap', 'test.flow0')
self.keg = self.backend.start_keg(tap=self.tap, beverage_name='Test Beer',
beverage_type='beer', producer_name='Test Producer', style_name='Test Style')
fsq_settings = self.plugin.get_site_settings_form()
fsq_settings.cleaned_data = {
'venue_id': '54321',
'client_id': 'fake-client-id',
'client_secret': 'fake-client-secret',
}
self.plugin.save_site_settings_form(fsq_settings)
开发者ID:Indemnity83,项目名称:kegbot-server,代码行数:16,代码来源:foursquare_test.py
示例17: save
def save(
self,
domain_override=None,
subject_template_name="registration/password_reset_subject.txt",
email_template_name="registration/password_reset_email.html",
use_https=False,
token_generator=default_token_generator,
from_email=None,
request=None,
):
"""
Generates a one-use only link for resetting password and sends to the
user.
"""
from django.core.mail import send_mail
email = self.cleaned_data["email"]
active_users = User._default_manager.filter(email__iexact=email, is_active=True)
for user in active_users:
# Make sure that no email is sent to a user that actually has
# a password marked as unusable
if not user.has_usable_password():
continue
from_email = getattr(settings, "EMAIL_FROM_ADDRESS", from_email)
be = get_kegbot_backend()
base_url = be.get_base_url()
parsed = urlparse.urlparse(base_url)
domain = parsed.netloc
protocol = parsed.scheme
kbsite = models.KegbotSite.get()
site_name = kbsite.title
c = {
"email": user.email,
"site_name": site_name,
"uid": urlsafe_base64_encode(force_bytes(user.pk)),
"user": user,
"token": token_generator.make_token(user),
"domain": domain,
"protocol": protocol,
}
subject = loader.render_to_string(subject_template_name, c)
# Email subject *must not* contain newlines
subject = "".join(subject.splitlines())
email = loader.render_to_string(email_template_name, c)
send_mail(subject, email, from_email, [user.email])
开发者ID:rasem,项目名称:kegbot-server,代码行数:47,代码来源:forms.py
示例18: save
def save(self):
if not self.is_valid():
raise ValueError('Form is not valid.')
b = get_kegbot_backend()
keg_size = self.cleaned_data.get('keg_size')
notes = self.cleaned_data.get('notes')
description = self.cleaned_data.get('description')
if keg_size != 'other':
full_volume_ml = None
else:
full_volume_ml = self.cleaned_data.get('initial_volume')
# TODO(mikey): Support non-beer beverage types.
cd = self.cleaned_data
keg = b.add_keg(beverage_name=cd['beverage_name'], producer_name=cd['producer_name'],
beverage_type='beer', style_name=cd['style_name'], keg_type=cd['keg_size'],
full_volume_ml=full_volume_ml, notes=cd['notes'], description=cd['description'])
return keg
开发者ID:mik3y,项目名称:kegbot-server,代码行数:18,代码来源:forms.py
示例19: setUp
def setUp(self):
self.backend = get_kegbot_backend()
models.User.objects.create_user("guest")
test_usernames = ("user1", "user2", "user3")
self.users = [self.backend.create_new_user(name, "%[email protected]" % name) for name in test_usernames]
self.taps = [
self.backend.create_tap("tap1", "kegboard.flow0", ticks_per_ml=2.2),
self.backend.create_tap("tap2", "kegboard.flow1", ticks_per_ml=2.2),
]
self.keg = self.backend.start_keg(
"kegboard.flow0",
beverage_name="Unknown",
beverage_type="beer",
producer_name="Unknown",
style_name="Unknown",
)
开发者ID:rasem,项目名称:kegbot-server,代码行数:19,代码来源:stats_test.py
示例20: test_activation
def test_activation(self):
b = get_kegbot_backend()
kbsite = models.KegbotSite.get()
self.assertEqual('public', kbsite.privacy)
user = b.create_new_user('testuser', '[email protected]')
self.assertIsNotNone(user.activation_key)
self.assertFalse(user.has_usable_password())
activation_key = user.activation_key
self.assertIsNotNone(activation_key)
activation_url = reverse('activate-account', args=(),
kwargs={'activation_key': activation_key})
# Activation works regardless of privacy settings.
self.client.logout()
response = self.client.get(activation_url)
self.assertContains(response, 'Choose a Password', status_code=200)
kbsite.privacy = 'staff'
kbsite.save()
response = self.client.get(activation_url)
self.assertContains(response, 'Choose a Password', status_code=200)
kbsite.privacy = 'members'
kbsite.save()
response = self.client.get(activation_url)
self.assertContains(response, 'Choose a Password', status_code=200)
# Activate the account.
form_data = {
'password': '123',
'password2': '123',
}
response = self.client.post(activation_url, data=form_data, follow=True)
self.assertContains(response, 'Your account has been activated!', status_code=200)
user = models.User.objects.get(pk=user.id)
self.assertIsNone(user.activation_key)
开发者ID:mik3y,项目名称:kegbot-server,代码行数:40,代码来源:kegweb_test.py
注:本文中的pykeg.backend.get_kegbot_backend函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论