def test_objects_know_their_filenames(self): # Setup f = SimpleUploadedFile('dummy_file.txt', force_bytes('file_content')) attachment = AttachmentFactory.create(post=self.post, file=f) # Run & check assert attachment.filename == 'dummy_file.txt' attachment.file.delete()
def test_is_able_to_handle_unknown_file_content_types(self): # Setup f = open(settings.MEDIA_ROOT + '/attachment.kyz', 'rb') attachment_file = File(f) attachment = AttachmentFactory.create( post=self.post, file=attachment_file) correct_url = reverse('forum_conversation:attachment', kwargs={'pk': attachment.id}) # Run response = self.client.get(correct_url, follow=True) # Check assert response.status_code == 200 assert response['Content-Type'] == 'text/plain' attachment_file.close() attachment.file.delete()
def setup(self): # Permission handler self.perm_handler = PermissionHandler() # Set up a top-level forum self.top_level_forum = create_forum() # Set up a topic and some posts self.topic = create_topic(forum=self.top_level_forum, poster=self.user) self.post = PostFactory.create(topic=self.topic, poster=self.user) # Set up an attachment f = open(settings.MEDIA_ROOT + '/attachment.jpg', 'rb') self.attachment_file = File(f) self.attachment = AttachmentFactory.create(post=self.post, file=self.attachment_file) # Mark the forum as read ForumReadTrackFactory.create(forum=self.top_level_forum, user=self.user) # Assign some permissions assign_perm('can_read_forum', self.user, self.top_level_forum) assign_perm('can_download_file', self.user, self.top_level_forum) yield # teardown # -- self.attachment_file.close() attachments = Attachment.objects.all() for attachment in attachments: try: attachment.file.delete() except: pass
def setup(self): # Permission handler self.perm_handler = PermissionHandler() # Set up a top-level forum self.top_level_forum = create_forum() # Set up a topic and some posts self.topic = create_topic(forum=self.top_level_forum, poster=self.user) self.post = PostFactory.create(topic=self.topic, poster=self.user) # Set up an attachment f = open(settings.MEDIA_ROOT + '/attachment.jpg', 'rb') self.attachment_file = File(f) self.attachment = AttachmentFactory.create( post=self.post, file=self.attachment_file) # Mark the forum as read ForumReadTrackFactory.create(forum=self.top_level_forum, user=self.user) # Assign some permissions assign_perm('can_read_forum', self.user, self.top_level_forum) assign_perm('can_download_file', self.user, self.top_level_forum) yield # teardown # -- self.attachment_file.close() attachments = Attachment.objects.all() for attachment in attachments: try: attachment.file.delete() except: pass