def test_post_audio(self):
# Build a fake file
fake_file = ContentFile(b("A boring example song"))
fake_file.name = 'song.mp3'
# Submit
post_data = {
'title': "Test media",
'file': fake_file,
'duration': 100,
}
response = self.client.post(reverse('wagtailmedia:add', args=('audio', )), post_data)
# User should be redirected back to the index
self.assertRedirects(response, reverse('wagtailmedia:index'))
# Media should be created with type 'audio' and in the 'evil plans' collection,
# despite there being no collection field in the form, because that's the
# only one the user has access to
self.assertTrue(models.Media.objects.filter(title="Test media").exists())
media = models.Media.objects.get(title="Test media")
self.assertEqual(media.collection, self.evil_plans_collection)
self.assertEqual(media.type, 'audio')
评论列表
文章目录