ATFile/ATImage Replacement Types
================================

This test tries to make sure the new, blob-based replacement types for
`ATFile` and `ATImage` can be properly created and edited.


Files
-----

Let's start with creating a "File" content item:

  >>> from StringIO import StringIO
  >>> browser = self.getBrowser()
  >>> browser.open(self.folder.absolute_url())

  >>> browser.getLink(url='createObject?type_name=File').click()
  >>> browser.url
  'http://nohost/plone/.../portal_factory/File/file.../edit'
  >>> browser.getControl(name='title').value = 'Foo'
  >>> control = browser.getControl(name='file_file')
  >>> control.filename = 'foo.pdf'
  >>> control.value = StringIO('%PDF-1.4 fake pdf...' + 'foo' * 1000)
  >>> browser.getControl('Save').click()

  >>> browser.url
  'http://nohost/plone/.../foo.../view'
  >>> browser.contents
  '...Info...Changes saved...
   ...Foo...foo.pdf...PDF document,...2Kb...'

Now let's make sure we can also edit it:

  >>> browser.getLink('Edit').click()
  >>> browser.getControl(name='title').value = 'Foobar'
  >>> browser.getControl('Replace with new file').selected = True
  >>> control = browser.getControl(name='file_file')
  >>> control.filename = 'foobar.pdf'
  >>> control.value = StringIO('%PDF-1.4 fake pdf...' + 'foobar' * 1000)
  >>> browser.getControl('Save').click()

  >>> browser.url
  'http://nohost/plone/.../foo.../view'
  >>> browser.contents
  '...Info...Changes saved...
   ...Foobar...foobar.pdf...PDF document,...5Kb...'


Images
------

Next a similar test is conducted for an "Image" content item:

  >>> from plone.app.blob.tests.utils import getImage
  >>> gif = getImage()
  >>> browser.open(self.folder.absolute_url())

  >>> browser.getLink(url='createObject?type_name=Image').click()
  >>> browser.url
  'http://nohost/plone/.../portal_factory/Image/image.../edit'
  >>> browser.getControl(name='title').value = 'Bar'
  >>> control = browser.getControl(name='image_file')
  >>> control.filename = 'bar.gif'
  >>> control.value = StringIO(gif)
  >>> browser.getControl('Save').click()

  >>> browser.url
  'http://nohost/plone/.../bar.../view'
  >>> browser.contents
  '...Info...Changes saved...
   ...Bar...
   ...<img src="http://.../bar.../image_preview"...title="Bar" height="1" width="1" />...
   ...Click to view full-size...Size...1 kB...'

Now let's make sure we can also edit it:

  >>> browser.getLink('Edit').click()
  >>> browser.getControl(name='title').value = 'Foobar'
  >>> browser.getControl('Replace with new image').selected = True
  >>> control = browser.getControl(name='image_file')
  >>> control.filename = 'foobar.gif'
  >>> control.value = StringIO(gif)
  >>> browser.getControl('Save').click()

  >>> browser.url
  'http://nohost/plone/.../bar.../view'
  >>> browser.contents
  '...Info...Changes saved...
   ...Foobar...
   ...<img src="http://.../bar.../image_preview"...title="Foobar" height="1" width="1" />...
   ...Click to view full-size...Size...1 kB...'

Viewing an image should also work when browsing its URL directly, i.e.
without the `/view` action part:

  >>> url = browser.url.replace('/view', '')
  >>> browser.open(url)
  >>> browser.contents == gif
  True
  >>> browser.headers['status'].upper()
  '200 OK'
  >>> browser.headers['content-type']
  'image/gif'
  >>> browser.headers['content-disposition']
  'inline; filename="foobar.gif"'

Appending `/index_html` should be the same:

  >>> browser.open(url + '/index_html')
  >>> browser.contents == gif
  True
  >>> browser.headers['status'].upper()
  '200 OK'
  >>> browser.headers['content-type']
  'image/gif'
  >>> browser.headers['content-disposition']
  'inline; filename="foobar.gif"'

Let's also check the scaled versions included the un-scaled variant:

  >>> browser.open(url + '/image_thumb')
  >>> browser.contents
  '\x89PNG...'
  >>> browser.headers['status'].upper()
  '200 OK'
  >>> browser.headers['content-type']
  'image/png'

  >>> browser.open(url + '/image')
  >>> browser.contents
  'GIF89a...'
  >>> browser.headers['status'].upper()
  '200 OK'
  >>> browser.headers['content-type']
  'image/gif'

