def test_bucket_contents_view_with_folder(self): bucket, bucket_acl = self.make_bucket() bucket.new_key("/folder-one/").set_contents_from_string('') request = self.create_request(matchdict=dict(name=bucket.name)) request.environ = {'PATH_INFO': u'test_bucket/folder-one'} request.subpath = ('folder-one', ) view = BucketContentsView(request, bucket=bucket).bucket_contents() self.assertEqual(view.get('display_path'), 'folder-one')
def test_generated_icon_class_for_file_types(self): request = testing.DummyRequest() view = BucketContentsView(request) self.assertEqual(view.get_icon_class('/foo/bar/baz.pdf'), 'fi-page-pdf') # Test PDF self.assertEqual(view.get_icon_class('/foo/bar/baz.jpg'), 'fi-photo') # Test image self.assertEqual(view.get_icon_class('/foo/bar/baz.txt'), 'fi-page') # Test text file self.assertEqual(view.get_icon_class('/foo/bar/baz.zip'), 'fi-archive') # Test zip file self.assertEqual(view.get_icon_class('/foo/bar/baz.unknown'), '') # Test unknown
def test_generated_icon_class_for_file_types(self): request = testing.DummyRequest() view = BucketContentsView(request) self.assertEqual(view.get_icon_class("/foo/bar/baz.pdf"), "fi-page-pdf") # Test PDF self.assertEqual(view.get_icon_class("/foo/bar/baz.jpg"), "fi-photo") # Test image self.assertEqual(view.get_icon_class("/foo/bar/baz.txt"), "fi-page") # Test text file self.assertEqual(view.get_icon_class("/foo/bar/baz.zip"), "fi-archive") # Test zip file self.assertEqual(view.get_icon_class("/foo/bar/baz.unknown"), "") # Test unknown
def test_bucket_contents_view_with_folder(self): bucket, bucket_acl = self.make_bucket() bucket.new_key("/folder-one/").set_contents_from_string("") request = self.create_request(matchdict=dict(name=bucket.name)) request.environ = {"PATH_INFO": u"test_bucket/folder-one"} request.subpath = ("folder-one",) view = BucketContentsView(request, bucket=bucket).bucket_contents() self.assertEqual(view.get("display_path"), "folder-one")
def test_upload_post_returns_400_when_file_uploads_config_is_disabled( self): """File upload post handler should return a 400 when file.uploads.enabled is False""" request = testing.DummyRequest() request.registry.settings = {'file.uploads.enabled': 'false'} view = BucketContentsView(request).bucket_upload_post self.assertRaises(HTTPBadRequest, view)
def test_upload_page_returns_404_when_file_uploads_config_is_disabled( self): """File upload page should return a 404 when file.uploads.enabled is False""" request = testing.DummyRequest() request.registry.settings = {'file.uploads.enabled': 'false'} view = BucketContentsView(request).bucket_upload self.assertRaises(HTTPNotFound, view)
def test_get_unprefixed_key_name(self): request = testing.DummyRequest() view = BucketContentsView(request) prefixed_key = '/foo/bar/baz/bat.txt' unprefixed_key = view.get_unprefixed_key_name(prefixed_key) self.assertEqual(unprefixed_key, 'bat.txt')
def test_bucket_contents_view_with_bucket(self): bucket, bucket_acl = self.make_bucket() request = self.create_request(matchdict=dict(name=bucket.name)) view = BucketContentsView(request, bucket_name=bucket.name).bucket_contents() self.assertEqual(view.get('display_path'), 'test_bucket')