本文整理汇总了Python中pykeg.backend.get_kegbot_backend函数的典型用法代码示例。如果您正苦于以下问题:Python get_kegbot_backend函数的具体用法?Python get_kegbot_backend怎么用?Python get_kegbot_backend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_kegbot_backend函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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
示例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)
示例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)
示例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()
示例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)
示例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()
示例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)
示例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)
示例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)
示例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',
)
示例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
示例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')
示例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()