本文整理汇总了Python中models.Tag.urlsafe方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.urlsafe方法的具体用法?Python Tag.urlsafe怎么用?Python Tag.urlsafe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tag
的用法示例。
在下文中一共展示了Tag.urlsafe方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import urlsafe [as 别名]
def post(self, *args, **kwargs):
super(AjaxTags, self).post()
new_tag_name = self.request.POST.get('name')
new_tag = None
if Tag.get_by_key(new_tag_name) is None:
new_tag = Tag(name=new_tag_name).put()
response = json.dumps(
None if new_tag is None
else {'key': new_tag.urlsafe(), 'name': new_tag_name})
self.response.out.write(response)
示例2: EditPostTests
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import urlsafe [as 别名]
class EditPostTests(BaseTest):
def setUp(self):
super(EditPostTests, self).setUp()
self.test_tag_1 = Tag(name="test tag 1").put()
self.test_tag_2 = Tag(name="test tag 2").put()
self.test_tag_3 = Tag(name="test tag 3").put()
self.test_author = Author(nickname="test", email="[email protected]").put()
self.test_post = (
Post(
subject="test post",
mark_down="test mark down",
html="test html",
is_published=True,
author=self.test_author,
tags=[self.test_tag_1],
)
.put()
.get()
)
def test_must_be_admin_to_view_page(self):
self.app.get(get_route("edit_post", key=self.test_post.key.urlsafe()), status=403)
def test_existing_tags_available_on_page_load(self):
self.login("[email protected]", admin=True)
response = self.app.get(get_route("edit_post", key=self.test_post.key.urlsafe()))
soup = BeautifulSoup(response.body)
multiselect_box = soup.find("select", {"name": "tags"})
options = multiselect_box.findAll("option")
self.assertEqual(len(options), 3)
def test_existing_post_content_loads_on_edit(self):
self.login("[email protected]", admin=True)
response = self.app.get(get_route("edit_post", key=self.test_post.key.urlsafe()), status=200)
edit_form = response.form
self.assertEqual(edit_form["subject"].value, "test post")
self.assertEqual(edit_form["mark_down"].value, "test mark down")
self.assertEqual(edit_form["is_published"].value, "on")
self.assertEqual(edit_form["tags"].value, [self.test_tag_1.urlsafe()])
self.assertEqual(edit_form["key"].value, self.test_post.key.urlsafe())
示例3: ModelDeserializationTests
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import urlsafe [as 别名]
class ModelDeserializationTests(BaseTest):
def setUp(self):
super(ModelDeserializationTests, self).setUp()
self.login("[email protected]")
self.test_key = Tag(name="Test Tag for Key").put()
self.testing_model = (
TestModel(
bool_prop=True,
string_prop="unmodified",
text_prop="unmodified",
datetime_prop=datetime(1982, 5, 21, 16, 0, 0, 0),
)
.put()
.get()
)
def test_can_deserialize_a_dict_to_model(self):
test_dict = {
"bool_prop": True,
"string_prop": "string value",
"text_prop": "text value",
"datetime_prop": "1982-05-21 16:00",
"key_prop": self.test_key.urlsafe(),
}
deser_model = TestModel.deserialize(test_dict)
self.assertTrue(deser_model.bool_prop)
self.assertEqual(deser_model.string_prop, test_dict["string_prop"])
self.assertEqual(deser_model.text_prop, test_dict["text_prop"])
self.assertEqual(deser_model.datetime_prop, datetime(1982, 5, 21, 16, 0, 0, 0))
self.assertEqual(deser_model.key_prop, self.test_key)
def test_can_deserialize_a_serialized_array_with_repeated_keys(self):
post_serialized_array = [
{"name": "repeated_key_prop", "value": self.test_key.urlsafe()},
{"name": "repeated_key_prop", "value": self.test_key.urlsafe()},
]
deser_model = TestModel2.deserialize(post_serialized_array)
self.assertIsNotNone(deser_model)
self.assertIsNotNone(deser_model.repeated_key_prop)
self.assertEqual(len(deser_model.repeated_key_prop), 2)
def test_can_deserialize_a_serialized_array_with_regular_key_prop(self):
post_serialized_array = [{"name": "regular_key_prop", "value": self.test_key.urlsafe()}]
deser_model = TestModel2.deserialize(post_serialized_array)
self.assertIsNotNone(deser_model)
self.assertIsNotNone(deser_model.regular_key_prop)
self.assertEqual(deser_model.regular_key_prop, self.test_key)
def test_can_deserialize_serialized_array_with_datetime_props(self):
post_serialized_array = [
{"name": "repeated_datetime_prop", "value": "1982-05-21 16:00"},
{"name": "repeated_datetime_prop", "value": "1982-05-21 17:00"},
]
deser_model = TestModel2.deserialize(post_serialized_array)
self.assertIsNotNone(deser_model)
self.assertIsNotNone(deser_model.repeated_datetime_prop)
self.assertEqual(len(deser_model.repeated_datetime_prop), 2)
self.assertIn(datetime(1982, 5, 21, 16, 0, 0, 0), deser_model.repeated_datetime_prop)
self.assertIn(datetime(1982, 5, 21, 17, 0, 0, 0), deser_model.repeated_datetime_prop)
def test_can_deserialize_serialized_array_with_regular_datetime_prop(self):
post_serialized_array = [{"name": "regular_datetime_prop", "value": "1982-05-21 16:00"}]
deser_model = TestModel2.deserialize(post_serialized_array)
self.assertIsNotNone(deser_model)
self.assertIsNotNone(deser_model.regular_datetime_prop)
self.assertEqual(deser_model.regular_datetime_prop, datetime(1982, 5, 21, 16, 0, 0, 0))
def test_can_deserialize_serialized_array_with_date_props(self):
post_serialized_array = [
{"name": "repeated_date_prop", "value": "1982-05-21"},
{"name": "repeated_date_prop", "value": "1982-05-21"},
]
deser_model = TestModel2.deserialize(post_serialized_array)
self.assertIsNotNone(deser_model)
self.assertIsNotNone(deser_model.repeated_date_prop)
self.assertEqual(len(deser_model.repeated_date_prop), 2)
self.assertIn(datetime(1982, 5, 21), deser_model.repeated_date_prop)
self.assertIn(datetime(1982, 5, 21), deser_model.repeated_date_prop)
def test_can_deserialize_serialized_array_with_regular_date_prop(self):
post_serialized_array = [{"name": "regular_date_prop", "value": "1982-05-21"}]
deser_model = TestModel2.deserialize(post_serialized_array)
self.assertIsNotNone(deser_model)
self.assertIsNotNone(deser_model.regular_date_prop)
#.........这里部分代码省略.........