def test_file_path_anon_user(self): # Make public so we dont get a permission denied self.make_item_public(self.item, self.ra) # Setup downloader get path downloader = FakeDownloader([self.item.id], None, {'include_supporting': True}) path = downloader.get_filepath() self.assertRegex(path, 'anon/[0-9a-f]+/download.fak')
def test_retrieve_file_if_item_not_modified(self): item_created = self.item.created with patch.object(FakeDownloader, 'get_storage') as fake_storage: # File modified before item fake_storage().get_modified_time.return_value = item_created - datetime.timedelta(seconds=1000) fake_storage().url.return_value = 'http://www.example.com/file.txt' downloader = FakeDownloader([self.item.id], self.editor.id, {'include_supporting': True}) url = downloader.retrieve_file('file.txt') self.assertEqual(url, None)
def test_email_file_direct(self): downloader = FakeDownloader([self.item.id], self.editor.id, {}) f = ContentFile('MyFile') size = f.size f.close() downloader.email_file(f, size, 'https://example.com/file.txt') self.assertEqual(len(mail.outbox), 1) message = mail.outbox[0] self.assertEqual(len(message.attachments), 1) content = message.attachments[0][1] self.assertEqual(content, 'MyFile')
def test_email_file(self): downloader = FakeDownloader([self.item.id], self.editor.id, {}) f = ContentFile('MyFile') size = f.size f.close() downloader.email_file(f, size, 'https://example.com/file.txt') self.assertEqual(len(mail.outbox), 1) message = mail.outbox[0] self.assertEqual(len(message.attachments), 0) self.assertTrue('https://example.com/file.txt' in message.body) expected_regen_url = reverse('aristotle:download_options', args=['fake'])\ + '?items=' + str(self.item.id) self.assertTrue(expected_regen_url in message.body)
def test_exception_raised_if_no_items_visible(self): with self.assertRaises(PermissionDenied): downloader = FakeDownloader([self.item.id], self.viewer.id, {})
def test_items_restricted_to_visible_only(self): downloader = FakeDownloader([self.item.id, self.item4.id], self.viewer.id, {}) self.assertEqual(downloader.numitems, 1) self.assertEqual(downloader.items[0].id, self.item4.id)
def test_file_not_created_if_can_be_retrieved(self): fake_url = 'http://www.example.com/existing/file.fak' with patch.object(FakeDownloader, 'retrieve_file', return_value=fake_url): downloader = FakeDownloader([self.item.id], self.editor.id, {'include_supporting': True}) url = downloader.download() self.assertEqual(url, fake_url)
def test_file_path_auth_user(self): downloader = FakeDownloader([self.item.id], self.editor.id, {'include_supporting': True}) path = downloader.get_filepath() self.assertRegex(path, '[0-9]+/[0-9a-f]+/download.fak')