.. -*-doctest-*-

Plone Image
===========

Image support in Plone now consists of taking the zope3 image support
and wrapping it with a Plone integration layer.

We begin this process by creating a new instance of a image content
type.

  >>> id = self.folder.invokeFactory(self.image_type, 'testimage1')
  >>> testimage1 = self.folder[id]

By default, doing an IImage adapter lookup on that image should fail since
its media properties have not yet been activated.

  >>> from p4a.image.interfaces import IImage
  >>> IImage(testimage1)
  Traceback (most recent call last):
  ...
  TypeError: ('Could not adapt'...)

So the next step would be to actually activate the image enhancements on
this image instance.

  >>> media_config = testimage1.restrictedTraverse('@@media-config.html')
  >>> media_config.media_activated
  False
  >>> media_config.media_activated = True
  >>> media_config.media_activated
  True
    
This is what the testimage looks like before adaptation to IImage
  >>> testimage1
  <ATImage at /plone/Members/test_user_1_/testimage1>

Now adapting it should work fine.

  >>> IImage(testimage1)
  <p4a.image ATCTImageEnhanced title=None>

Lets do the same thing with a folder.  Since p4a.image allows folders
to additionally be media enhanced (as image containers).

  >>> id = self.folder.invokeFactory('Folder', 'testfolder1')
  >>> testfolder1 = self.folder[id]

So the next step would be to actually activate the image enhancements on
this folder.

  >>> media_config = testfolder1.restrictedTraverse('@@media-config.html')
  >>> media_config.media_activated
  False
  >>> media_config.media_activated = True
  >>> media_config.media_activated
  True

Make sure the *IImageFileProvider* adapter works on the folder.

  >>> from p4a.image.interfaces import IImageProvider
  >>> adapted = IImageProvider(testfolder1)
  >>> adapted.image_items
  []
  
This was interesting, but the adapted folder has no items.
Now we'll add something to that folder because we want to explore accessing view
attributes on the item from the context of the container (and we don't know 
how to do it!)
  
  >>> id = testfolder1.invokeFactory(self.image_type, 'testimage2')
  >>> testimage2 = testfolder1[id]

By default, doing an IImage adapter lookup on that image should fail since
its media properties have not yet been activated.

  >>> from p4a.image.interfaces import (
  ...     IImage, IImageDataAccessor, IPossibleImage)
  >>> IImage(testimage2)
  Traceback (most recent call last):
  ...
  TypeError: ('Could not adapt'...)

So the next step would be to actually activate the image enhancements on
this image instance.

  >>> media_config = testimage2.restrictedTraverse('@@media-config.html')
  >>> media_config.media_activated
  False
  >>> media_config.media_activated = True
  >>> media_config.media_activated
  True
    
This is what the testimage looks like before adaptation to IImage
  >>> testimage2
  <ATImage at /plone/Members/test_user_1_/testfolder1/testimage2>

Now adapting it should work fine.

  >>> IImage(testimage2)
  <p4a.image ATCTImageEnhanced title=None>
  
And we can get to the image data - which has no keys, because it was a 
fake image.

  >>> IImage(testimage2).image_data.keys()
  []
 
We know that Smart Folders are potential image containers as well.  So we
should test those as well.

Need more permissions first to create smart folders, will adopt ``Manager``
role.

  >>> self.setRoles('Manager')

  >>> id = self.folder.invokeFactory('Topic', 'testtopic1')
  >>> testtopic1 = self.folder[id]
  
Make sure sure we can activate image enhancements on this smart folder.

  >>> media_config = testtopic1.restrictedTraverse('@@media-config.html')
  >>> media_config.media_activated
  False
  >>> media_config.media_activated = True
  >>> media_config.media_activated
  True
