本文整理汇总了Python中popit.serializers.PostSerializer.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python PostSerializer.is_valid方法的具体用法?Python PostSerializer.is_valid怎么用?Python PostSerializer.is_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类popit.serializers.PostSerializer
的用法示例。
在下文中一共展示了PostSerializer.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_post_otherlabels_links
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_update_post_otherlabels_links(self):
data = {
"other_labels": [
{
"id": "aee39ddd-6785-4a36-9781-8e745c6359b7",
"links": [
{
"id": "6c928027-4813-4770-80a5-ba413a43efae",
"note": "It is on facebook but it is hard to see"
}
]
}
]
}
post = Post.objects.untranslated().get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
serializer = PostSerializer(post, data=data, partial=True, language="en")
serializer.is_valid()
self.assertEqual(serializer.errors, {})
serializer.save()
post = Post.objects.language("en").get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
other_labels = post.other_labels.language("en").get(id="aee39ddd-6785-4a36-9781-8e745c6359b7")
link = other_labels.links.language("en").get(id="6c928027-4813-4770-80a5-ba413a43efae")
self.assertEqual(link.note, "It is on facebook but it is hard to see")
示例2: test_create_post_minimal_field_serializer
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_create_post_minimal_field_serializer(self):
data = {
"role": "Honorary Member",
}
serializer = PostSerializer(data=data, language="en")
serializer.is_valid()
self.assertEqual(serializer.errors, {})
serializer.save()
post = Post.objects.language("en").get(role="Honorary Member")
self.assertEqual(post.role, "Honorary Member")
示例3: test_create_post_translated
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_create_post_translated(self):
data = {
"label": "Ahli Terhormat",
"role": "Ahli Terhormat",
}
serializer = PostSerializer(data=data, language="ms")
serializer.is_valid()
self.assertEqual(serializer.errors, {})
serializer.save()
post = Post.objects.language("ms").get(role="Ahli Terhormat")
self.assertEqual(post.role, "Ahli Terhormat")
示例4: test_update_post_translated
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_update_post_translated(self):
data = {
"label": "ahli"
}
post = Post.objects.untranslated().get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
serializer = PostSerializer(post, data=data, language="ms", partial=True)
serializer.is_valid()
self.assertEqual(serializer.errors, {})
serializer.save()
post = Post.objects.language("ms").get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
self.assertEqual(post.label, "ahli")
示例5: test_create_post_serializer_invalid_organization
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_create_post_serializer_invalid_organization(self):
data = {
"label": "Honorary Member",
"organization_id": "not exist",
"role": "Honorary Member",
"area_id": "640c0f1d-2305-4d17-97fe-6aa59f079cc4",
"start_date": "2000-02-02",
"end_date": "2030-02-02",
}
serializer = PostSerializer(data=data, language="en")
serializer.is_valid()
self.assertNotEqual(serializer.errors, {})
示例6: test_create_post_serializer_invalid_area_id
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_create_post_serializer_invalid_area_id(self):
data = {
"label": "Honorary Member",
"organization_id": "3d62d9ea-0600-4f29-8ce6-f7720fd49aa3",
"role": "Honorary Member",
"area_id": "not exist",
"start_date": "2000-02-02",
"end_date": "2030-02-02",
}
serializer = PostSerializer(data=data, language="en")
serializer.is_valid()
self.assertNotEqual(serializer.errors, {})
示例7: test_serializer_create_post_invalid_date
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_serializer_create_post_invalid_date(self):
data = {
"label": "Honorary Member",
"organization_id": "3d62d9ea-0600-4f29-8ce6-f7720fd49aa3",
"role": "Honorary Member",
"area_id": "640c0f1d-2305-4d17-97fe-6aa59f079cc4",
"start_date": "invalid date",
"end_date": "invalid date",
}
serializer = PostSerializer(data=data, language="en")
serializer.is_valid()
self.assertNotEqual(serializer.errors, {})
示例8: test_create_post_otherlabels_serializer
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_create_post_otherlabels_serializer(self):
data = {
"other_labels": [{
"name": "sampan party"
}]
}
post = Post.objects.untranslated().get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
serializer = PostSerializer(post, data=data, language="en", partial=True)
serializer.is_valid()
self.assertEqual(serializer.errors, {})
serializer.save()
post = Post.objects.language("en").get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
other_labels = post.other_labels.language("en").get(name="sampan party")
self.assertEqual(other_labels.name, "sampan party")
示例9: test_update_post_translated
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_update_post_translated(self):
data = {
"label": "ahli"
}
# When translation do not exist, the following is used in production
# post = Post.objects.untranslated().get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
# But when translation exist, fetch existing translation
post = Post.objects.language("ms").get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
serializer = PostSerializer(post, data=data, language="ms", partial=True)
serializer.is_valid()
self.assertEqual(serializer.errors, {})
serializer.save()
post = Post.objects.language("ms").get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
self.assertEqual(post.label, "ahli")
示例10: test_create_post_links_serializer
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_create_post_links_serializer(self):
data = {
"links": [
{
"url": "http://www.yahoo.com"
}
]
}
post = Post.objects.untranslated().get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
serializer = PostSerializer(post, data=data, partial=True, language="en")
serializer.is_valid()
self.assertEqual(serializer.errors, {})
serializer.save()
post = Post.objects.language("en").get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
link = post.links.language("en").get(url="http://www.yahoo.com")
self.assertEqual(link.url, "http://www.yahoo.com")
示例11: test_create_post_serializer
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_create_post_serializer(self):
data = {
"label": "Honorary Member",
"organization_id": "3d62d9ea-0600-4f29-8ce6-f7720fd49aa3",
"role": "Honorary Member",
"area_id": "640c0f1d-2305-4d17-97fe-6aa59f079cc4",
"start_date": "2000-02-02",
"end_date": "2030-02-02",
}
serializer = PostSerializer(data=data, language="en")
serializer.is_valid()
self.assertEqual(serializer.errors, {})
serializer.save()
post = Post.objects.language("en").get(role="Honorary Member")
self.assertEqual(post.organization_id, "3d62d9ea-0600-4f29-8ce6-f7720fd49aa3")
示例12: test_update_post_otherlabels_serializer
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_update_post_otherlabels_serializer(self):
data = {
"other_labels": [
{
"id":"aee39ddd-6785-4a36-9781-8e745c6359b7",
"name": "Bilge Rat"
}
]
}
post = Post.objects.untranslated().get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
serializer = PostSerializer(post, data=data, partial=True, language="en")
serializer.is_valid()
self.assertEqual(serializer.errors, {})
serializer.save()
post = Post.objects.language("en").get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
other_labels = post.other_labels.language("en").get(id="aee39ddd-6785-4a36-9781-8e745c6359b7")
self.assertEqual(other_labels.name, "Bilge Rat")
示例13: test_create_post_contacts_serializer
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_create_post_contacts_serializer(self):
data = {
"contact_details": [
{
"type": "sms",
"value": "231313123131",
}
]
}
post = Post.objects.untranslated().get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
serializer = PostSerializer(post, data=data, partial=True, language="en")
serializer.is_valid()
self.assertEqual(serializer.errors, {})
serializer.save()
post = Post.objects.language("en").get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
contact = post.contact_details.language("en").get(value="231313123131")
self.assertEqual(contact.type, "sms")
示例14: test_update_post_links_serializer
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_update_post_links_serializer(self):
data = {
"links": [
{
"id": "ce15a9ee-6742-4467-bbfb-c86459ee685b",
"note": "just a link"
}
]
}
post = Post.objects.untranslated().get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
serializer = PostSerializer(post, data=data, partial=True, language="en")
serializer.is_valid()
self.assertEqual(serializer.errors, {})
serializer.save()
post = Post.objects.language("en").get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
link = post.links.language("en").get(id="ce15a9ee-6742-4467-bbfb-c86459ee685b")
self.assertEqual(link.note, "just a link")
示例15: test_update_post_contacts_serializer
# 需要导入模块: from popit.serializers import PostSerializer [as 别名]
# 或者: from popit.serializers.PostSerializer import is_valid [as 别名]
def test_update_post_contacts_serializer(self):
data = {
"contact_details": [
{
"id": "7f3f67c4-6afd-4de9-880e-943560cf56c0",
"type": "phone"
}
]
}
post = Post.objects.untranslated().get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
serializer = PostSerializer(post, data=data, partial=True, language="en")
serializer.is_valid()
self.assertEqual(serializer.errors, {})
serializer.save()
post = Post.objects.language("en").get(id="c1f0f86b-a491-4986-b48d-861b58a3ef6e")
contact = post.contact_details.language("en").get(id="7f3f67c4-6afd-4de9-880e-943560cf56c0")
self.assertEqual(contact.type, "phone")