本文整理汇总了Python中models.Tag.clean方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.clean方法的具体用法?Python Tag.clean怎么用?Python Tag.clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Tag
的用法示例。
在下文中一共展示了Tag.clean方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AlbumTest
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import clean [as 别名]
class AlbumTest(TestCase):
def setUp(self):
self.user = User(username='sholmes', email='[email protected]',
first_name='Sherlock', last_name="Holmes",
password='watson')
self.user.full_clean()
self.user.save()
self.photo = Photo(owner=self.user,
image='images/test.png',
name='test',
caption='testing')
self.photo.clean()
self.photo.save()
self.tag = Tag(name='test tag', owner=self.user)
self.tag.clean()
self.tag.save()
self.photo.tags.add(self.tag)
self.album = Album(owner=self.user,
name='test album')
self.album.clean()
self.album.save()
self.album.photos.add(self.photo)
def test_id_creation(self):
self.assertIsNotNone(self.album.id)
def test_owner_entry(self):
self.assertEqual(self.album.name, 'test album')
def test_name_entry(self):
self.assertEqual(self.photo.name, 'test')
def test_album_to_photo_association(self):
photos = Photo.objects.filter(album=self.album.id)
self.assertEqual(photos[0].name, 'test')
示例2: PhotoTest
# 需要导入模块: from models import Tag [as 别名]
# 或者: from models.Tag import clean [as 别名]
class PhotoTest(TestCase):
def setUp(self):
self.user = User(username='sholmes', email='[email protected]',
first_name='Sherlock', last_name="Holmes",
password='watson')
self.user.full_clean()
self.user.save()
self.photo = Photo(owner=self.user,
image='images/test.png',
name='test',
caption='testing')
self.photo.clean()
self.photo.save()
self.tag = Tag(name='test tag', owner=self.user)
self.tag.clean()
self.tag.save()
self.photo.tags.add(self.tag)
def test_id_creation(self):
self.assertIsNotNone(self.photo.id)
def test_owner_entry(self):
self.assertEqual(self.photo.owner.username, 'sholmes')
def test_image_entry(self):
self.assertEqual(self.photo.image, 'images/test.png')
def test_name_entry(self):
self.assertEqual(self.photo.name, 'test')
def test_caption_entry(self):
self.assertEqual(self.photo.caption, 'testing')
def test_tag_creation(self):
self.assertEqual(self.tag.name, 'test tag')
def test_photo_tag_association(self):
tags = Tag.objects.filter(photo=self.photo.id)
self.assertEqual(tags[0].name, 'test tag')