Browser tests
=============

Setup
-----

  >>> from kotti import testing
  >>> from kotti.resources import get_root
  >>> tools = testing.setUpFunctional(**{
  ...     'kotti.configurators': 'kotti_media.kotti_configure',
  ...     })
  >>> browser = tools['Browser']()
  >>> ctrl = browser.getControl
  >>> root = get_root()


Login
-----

  >>> browser.open(testing.BASE_URL + '/edit')
  >>> "Log in" in browser.contents
  True
  >>> ctrl("Username or email", index=0).value = "admin"
  >>> ctrl("Password").value = "secret"
  >>> ctrl(name="submit").click()
  >>> "Welcome, Administrator" in browser.contents
  True

Add audio content
-----------------

  >>> browser.open(testing.BASE_URL + '/view')
  >>> browser.getLink("Add").click()
  >>> browser.getLink("Audio").click()
  >>> ctrl("Title").value = "My Audio"
  >>> ctrl("save").click()
  >>> "Item was added" in browser.contents
  True
  >>> browser.url == testing.BASE_URL + '/my-audio/'
  True

Test the audio view
-------------------

  >>> "<audio" in browser.contents
  True
  >>> "</audio>" in browser.contents
  True
  >>> '<source type="audio/mp3"' in browser.contents
  False
  >>> '<source type="audio/mp4"' in browser.contents
  False
  >>> '<source type="audio/ogg"' in browser.contents
  False
  >>> '<source type="audio/wav"' in browser.contents
  False

Add some audio files
--------------------

  >>> import os
  >>> import kotti_media
  >>> here = os.path.join(os.path.dirname(kotti_media.__file__), 'tests')

Try adding without file or external_url

  >>> browser.open(testing.BASE_URL + '/my-audio/')
  >>> browser.getLink("Add").click()
  >>> browser.getLink("Audio file (*.m4a)").click()
  >>> ctrl("save").click()
  >>> "Either a file or an external URL is required" in browser.contents
  True
  >>> "Required if no external URL is supplied" in browser.contents
  True
  >>> "Required if no file is supplied" in browser.contents
  True

Try adding with file *and* external_url

  >>> m4a = open(os.path.join(here, "distortion.m4a")).read()
  >>> browser.open(testing.BASE_URL + '/my-audio/')
  >>> browser.getLink("Add").click()
  >>> browser.getLink("Audio file (*.m4a)").click()
  >>> ctrl("File").add_file(m4a, 'audio/mp4', 'distortion.m4a')
  >>> ctrl("External URL").value = "http://binary-punks.com/distortion.mp3"
  >>> ctrl("save").click()
  >>> "Either a file or an external URL is required, bot not both" in browser.contents
  True
  >>> "Must not be supplied if an external URL is supplied" in browser.contents
  True
  >>> "Must not be supplied if a file is supplied" in browser.contents
  True

M4A

  >>> m4a = open(os.path.join(here, "distortion.m4a")).read()
  >>> browser.open(testing.BASE_URL + '/my-audio/')
  >>> browser.getLink("Add").click()
  >>> browser.getLink("Audio file (*.m4a)").click()
  >>> ctrl("File").add_file(m4a, 'audio/mp4', 'distortion.m4a')
  >>> ctrl("save").click()
  >>> "Item was added" in browser.contents
  True

MP3

  >>> mp3 = open(os.path.join(here, "distortion.mp3")).read()
  >>> browser.open(testing.BASE_URL + '/my-audio/')
  >>> browser.getLink("Add").click()
  >>> browser.getLink("Audio file (*.mp3)").click()
  >>> ctrl("File").add_file(m4a, 'audio/mp3', 'distortion.mp3')
  >>> ctrl("save").click()
  >>> "Item was added" in browser.contents
  True

OGA

  >>> oga = open(os.path.join(here, "distortion.oga")).read()
  >>> browser.open(testing.BASE_URL + '/my-audio/')
  >>> browser.getLink("Add").click()
  >>> browser.getLink("Audio file (*.oga)").click()
  >>> ctrl("File").add_file(m4a, 'audio/ogg', 'distortion.oga')
  >>> ctrl("save").click()
  >>> "Item was added" in browser.contents
  True

WAV

  >>> wav = open(os.path.join(here, "distortion.wav")).read()
  >>> browser.open(testing.BASE_URL + '/my-audio/')
  >>> browser.getLink("Add").click()
  >>> browser.getLink("Audio file (*.wav)").click()
  >>> ctrl("File").add_file(m4a, 'audio/wav', 'distortion.wav')
  >>> ctrl("save").click()
  >>> "Item was added" in browser.contents
  True

Replace M4A with external URL

M4A

  >>> browser.open(testing.BASE_URL + '/my-audio/distortion.m4a/@@edit')
  >>> ctrl("External URL").value = "http://binary-punks.com/external_distortion.m4a"
  >>> ctrl("save").click()
  >>> "Either a file or an external URL is required, bot not both" in browser.contents
  True

Delete the M4A and add it with external_url *only* again

  >>> browser.open(testing.BASE_URL + '/my-audio/distortion.m4a/@@delete')
  >>> ctrl("delete").click()
  >>> "distortion.m4a was deleted" in browser.contents
  True
  >>> browser.open(testing.BASE_URL + '/my-audio/')
  >>> browser.getLink("Add").click()
  >>> browser.getLink("Audio file (*.m4a)").click()
  >>> ctrl("save").click()
  >>> ctrl("External URL").value = "http://binary-punks.com/external_distortion.m4a"
  >>> ctrl("save").click()
  >>> "Item was added" in browser.contents
  True
  >>> browser.url == testing.BASE_URL + '/my-audio/external_distortion.m4a/'
  True

Test the audio view again
-------------------------
  >>> browser.open(testing.BASE_URL + '/my-audio/')
  >>> "<audio" in browser.contents
  True
  >>> "</audio>" in browser.contents
  True
  >>> '<source type="audio/mp3"' in browser.contents
  True
  >>> '<source type="audio/mp4"' in browser.contents
  True
  >>> '<source type="audio/ogg"' in browser.contents
  True
  >>> '<source type="audio/wav"' in browser.contents
  True
  >>> 'http://binary-punks.com/external_distortion.m4a' in browser.contents
  True

Edit the M4A

  >>> browser.open(testing.BASE_URL + '/my-audio/external_distortion.m4a/@@edit')
  >>> ctrl("External URL").value = ""
  >>> ctrl("save").click()
  >>> 'Either a file or an external URL is required' in browser.contents
  True
  >>> 'Required if no external URL is supplied' in browser.contents
  True
  >>> 'Required if no file is supplied' in browser.contents
  True

  >>> ctrl("External URL").value = "http://binary-punks.com/external_distortion.m4a"
  >>> m4a = open(os.path.join(here, "distortion.m4a")).read()
  >>> ctrl("File").add_file(m4a, 'audio/mp4', 'distortion.m4a')
  >>> ctrl("save").click()
  >>> 'Either a file or an external URL is required, bot not both' in browser.contents
  True
  >>> 'Must not be supplied if an external URL is supplied' in browser.contents
  True
  >>> 'Must not be supplied if a file is supplied' in browser.contents
  True

Add video content
-----------------

  >>> browser.open(testing.BASE_URL + '/view')
  >>> browser.getLink("Add").click()
  >>> browser.getLink("Video").click()
  >>> ctrl("Title").value = "My Video"
  >>> ctrl("save").click()
  >>> "Item was added" in browser.contents
  True
  >>> browser.url == testing.BASE_URL + '/my-video/'
  True

Test the video view
-------------------

  >>> "<video" in browser.contents
  True
  >>> "</video>" in browser.contents
  True
  >>> #import pdb; pdb.set_trace()
