本文整理汇总了Python中models.Status.put方法的典型用法代码示例。如果您正苦于以下问题:Python Status.put方法的具体用法?Python Status.put怎么用?Python Status.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Status
的用法示例。
在下文中一共展示了Status.put方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_status_normal
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import put [as 别名]
def test_status_normal(self):
s = Status(name=u"Hey", slug=u"hey", description=u"runaway",
image=u"helloworld.png", severity=10)
s.put()
data = s.rest("/api")
self.assertEquals(data["level"], "NORMAL")
示例2: post
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import put [as 别名]
def post(self, version):
if (self.valid_version(version)):
name = self.request.get('name', default_value=None)
description = self.request.get('description', default_value=None)
image = self.request.get('image', default_value=None)
level = self.request.get('level', default_value=None)
severity = Level.get_severity(level)
if name and description and severity and image:
slug = slugify.slugify(name)
status = Status.get_by_slug(slug)
# Update existing resource
if status:
status.description = description
status.severity = severity
status.image = image
status.name = name
status.put()
self.json(status.rest(self.base_url(version)))
# Create new service
else:
status = Status(name=name, slug=slug, description=description,
severity=severity, image=image)
status.put()
self.json(status.rest(self.base_url(version)))
else:
self.error(400, "Bad Data")
else:
self.error(404, "API Version %s not supported" % version)
示例3: put
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import put [as 别名]
def put(self, status):
s = Status()
s.status_id = status.id
s.user = status.from_user
s.text = status.text
s.icon_url = status.profile_image_url
s.put()
示例4: test_status_warning
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import put [as 别名]
def test_status_warning(self):
s = Status(name=u"Hey", slug=u"hey", description=u"runaway",
image=u"helloworld.png", severity=30)
s.put()
data = s.rest("/api")
self.assertEquals(data["level"], "WARNING")
示例5: test_existing_status
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import put [as 别名]
def test_existing_status(self):
"""Services should 400 without a name"""
status = Status(name="Foo", slug="foo", description="hello",
image="cross-circle")
status.put()
response = self.post("/admin/api/v1/statuses",
data={"description": "An example service API",
"name": "Foo",
"image": "cross-circle"})
self.assertEquals(response.status_code, 400)
self.assertEquals(response.headers["Content-Type"], "application/json")
示例6: test_create_event
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import put [as 别名]
def test_create_event(self):
s = Service(slug=u"hey", name=u"you", description=u"lol")
s.put()
stat = Status(name=u"you", slug=u"leave", description=u"why",
image=u"cry")
stat.put()
e = Event(status=stat, service=s, message=u"¨¥¨œ∑´æ")
e.put()
data = e.rest("/api")
示例7: get
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import put [as 别名]
def get(self):
# get all the statuses
query = Status.all()
if query.count() != 0:
for result in query:
# if there are already some, then update them
update(result)
else:
# create an example status and put it in the datastore
test = Status(description='google',
comment='the acclaimed search engine',
link_url='http://www.google.com',
link_text='www.google.com',
update_type='status',
update_url='http://www.google.com')
test.put()
示例8: post
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import put [as 别名]
def post(self, version):
if not self.valid_version(version):
self.error(404, "API Version %s not supported" % version)
return
name = self.request.get('name', default_value=None)
description = self.request.get('description', default_value=None)
image_slug = self.request.get('image', default_value=None)
default = self.request.get('default', default_value="false")
if default not in ["true", "false"]:
self.error(400, "Default must be true or false")
return
if not name or not description or not image_slug:
self.error(400, "Bad Data")
return
slug = slugify.slugify(name)
status = Status.get_by_slug(slug)
image = Image.get_by_slug(image_slug)
if status is not None:
self.error(400, "A Status with the slug %s already exists" % slug)
return
if image is None:
msg = "An Image with the slug %s doesn't exist" % image_slug
self.error(400, msg)
return
# Reset default status
if default == "true":
for stat in Status.all().filter("default", True):
stat.default = False
stat.put()
default = default == "true"
status = Status(name=name, slug=slug, description=description,
image=image.path, default=default)
status.put()
invalidate_cache()
self.response.set_status(201)
self.json(status.rest(self.base_url(version)))
示例9: post
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import put [as 别名]
def post(self):
user = users.get_current_user()
beer = self.request.get('beer')
status_str = self.request.get('status')
if beer and status_str:
num = int(self.request.get('num'))
status = Status(user = user,
beer = beer,
amount = TotalAmount.get_amount_by_beer(beer) * num,
status = status_str,
)
status.put()
total = TotalAmount.all().filter('user = ', user).get()
if not total:
total = TotalAmount(user = user)
total.update(beer, num)
self.redirect('/')
示例10: StatusInstanceTest
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import put [as 别名]
class StatusInstanceTest(StashboardTest):
def setUp(self):
super(StatusInstanceTest, self).setUp()
image = Image(icon_set="fugue", slug="cross-circle",
path="fugue/cross-circle.png")
image.put()
self.status = Status(name="Foo", slug="foo", description="bar",
image="cross-circle")
self.status.put()
def test_update_wrong_image(self):
response = self.post("/admin/api/v1/statuses/foo",
data={"image": "foobar"})
self.assertEquals(response.status_code, 400)
def test_update_default_false(self):
response = self.post("/admin/api/v1/statuses/foo",
data={"default": "false"})
self.assertEquals(response.status_code, 200)
status = Status.get(self.status.key())
self.assertFalse(status.default)
def test_update_default(self):
response = self.post("/admin/api/v1/statuses/foo",
data={"default": "true"})
self.assertEquals(response.status_code, 200)
status = Status.get(self.status.key())
self.assertTrue(status.default)
def test_update_image(self):
response = self.post("/admin/api/v1/statuses/foo",
data={"image": "cross-circle"})
self.assertEquals(response.status_code, 200)
status = Status.get(self.status.key())
self.assertEquals(status.image, "fugue/cross-circle.png")
def test_update_description(self):
response = self.post("/admin/api/v1/statuses/foo",
data={"description": "blah"})
self.assertEquals(response.status_code, 200)
self.assertEquals(response.headers["Content-Type"], "application/json")
status = Status.get(self.status.key())
self.assertEquals(status.description, "blah")
def test_update_name(self):
response = self.post("/admin/api/v1/statuses/foo",
data={"name": "Foobar"})
self.assertEquals(response.status_code, 200)
self.assertEquals(response.headers["Content-Type"], "application/json")
status = Status.get(self.status.key())
self.assertEquals(status.name, "Foobar")
def test_get_wrong_status(self):
response = self.get("/api/v1/statuses/bat")
self.assertEquals(response.status_code, 404)
self.assertEquals(response.headers["Content-Type"], "application/json")
def test_get_status(self):
response = self.get("/api/v1/statuses/foo")
self.assertEquals(response.status_code, 200)
self.assertEquals(response.headers["Content-Type"], "application/json")
def test_url_api_correct(self):
response = self.get("/admin/api/v1/statuses/foo")
data = json.loads(response.content)
self.assertEquals(data['url'], 'http://localhost:80/admin/api/v1/statuses/foo')
def test_url_admin_api_correct(self):
response = self.get("/api/v1/statuses/foo")
data = json.loads(response.content)
self.assertEquals(data['url'], 'http://localhost:80/api/v1/statuses/foo')
def test_delete_success(self):
response = self.delete("/admin/api/v1/statuses/foo")
self.assertEquals(response.status_code, 200)
self.assertEquals(response.headers["Content-Type"], "application/json")
data = json.loads(response.content)
self.assertEquals(data['url'], 'http://localhost:80/admin/api/v1/statuses/foo')
status = Status.get(self.status.key())
self.assertEquals(status, None)
def test_delete_no_slug(self):
response = self.delete("/admin/api/v1/statuses/bar")
self.assertEquals(response.status_code, 404)
self.assertEquals(response.headers["Content-Type"], "application/json")
def test_delete_wrong_version(self):
response = self.delete("/admin/api/hey/statuses/foo")
self.assertEquals(response.status_code, 404)
self.assertEquals(response.headers["Content-Type"], "application/json")
#.........这里部分代码省略.........
示例11: get
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import put [as 别名]
def get(self):
try:
dev_id = self.request.get('id')
uptime = int(self.request.get('uptime'))
digital1 = int(self.request.get('digital1'))
digital2 = int(self.request.get('digital2'))
analog1 = float(self.request.get('analog1'))
except:
logging.info('Input error')
self.response.out.write('<p>Input error</p>')
return
device = Device.get_by_key_name(dev_id)
if device:
# logging.info('Update existing device')
device.uptime = uptime
# update state
current_state = device.state
if current_state == "Unknown" or current_state == "Available":
if analog1 < 5.0:
device.state = "Busy"
elif current_state == "Busy":
if analog1 >= 5.0:
device.state = "Ready"
elif current_state == "Ready":
device.state = "Available"
device.put()
# send notification to subscribers who's trigger state is the current state
subscriber_list = device.subscriber_set.filter('trigger_state =', device.state)
subscriber_email_list = list()
for subscriber in subscriber_list:
subscriber_email_list.append(subscriber.email)
# instead of deleting the subscriber, clear the trigger state
# so that a record of the subscriber is kept but no further email
# is sent
subscriber.trigger_state = ""
subscriber.put()
if len(subscriber_email_list) > 0:
message = mail.EmailMessage(
sender='StatusBot <[email protected]>',
to=subscriber_email_list,
subject='StatusBot #' + device.key().name() + ' Update!',
body="State has changed to " + device.state)
message.send()
else:
logging.info('Update new device')
device = Device(key_name=dev_id, state="Unknown")
device.uptime = uptime
device.put()
# save device status
status = Status(device=device)
status.digital1 = digital1
status.digital2 = digital2
status.analog1 = analog1
status.put()
self.response.out.write('<p>OK</p>')
示例12: test_create_image
# 需要导入模块: from models import Status [as 别名]
# 或者: from models.Status import put [as 别名]
def test_create_image(self):
s = Status(name=u"∆", slug=u"∑´", description=u"œˆø", image=u"©˙")
s.put()
data = s.rest("/api")