# Copyright (c) 2009-2010 gocept gmbh & co. kg
# See also LICENSE.txt

import transaction
import unittest
import zeit.brightcove.interfaces
import zeit.brightcove.testing
import zeit.cms.repository.interfaces
import zeit.cms.testcontenttype.testcontenttype
import zeit.cms.testing
import zeit.content.cp.testing
import zeit.solr.testing
import zope.component
import zope.security.management
import zope.site.hooks


def create_content(root):
    old_site = zope.site.hooks.getSite()
    zope.site.hooks.setSite(root)
    repository = zope.component.getUtility(
        zeit.cms.repository.interfaces.IRepository)

    for i in range(3):
        name = 'c%s' % (i + 1)
        c = zeit.cms.testcontenttype.testcontenttype.TestContentType()
        c.teaserTitle = c.shortTeaserTitle = u'%s teaser' % name
        repository[name] = c

    zope.site.hooks.setSite(old_site)


CPBrightcoveZCMLLLayer = zeit.cms.testing.ZCMLLayer(
    'ftesting-av.zcml',
    product_config=(zeit.cms.testing.cms_product_config +
                    zeit.brightcove.testing.product_config +
                    zeit.content.cp.testing.product_config +
                    zeit.solr.testing.product_config))


class CPBrightcoveLayer(zeit.brightcove.testing.BrightcoveHTTPLayer,
                        CPBrightcoveZCMLLLayer,
                        zeit.solr.testing.SolrMockLayerBase):

    @classmethod
    def setUp(cls):
        pass

    @classmethod
    def tearDown(cls):
        pass

    @classmethod
    def testSetUp(cls):
        root = CPBrightcoveZCMLLLayer.setup.getRootFolder()
        with zeit.cms.testing.site(root):
            repository = zope.component.getUtility(
                zeit.brightcove.interfaces.IRepository)
            repository.update_from_brightcove()
        transaction.commit()

    @classmethod
    def testTearDown(cls):
        pass


def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(zeit.content.cp.testing.FunctionalDocFileSuite(
        'autopilot.txt',
        'cpextra.txt',
        'fullgraphical.txt',
        'quiz.txt',
        'teaser.txt',
        'teaser-two-column-layout.txt',
        'teaserbar.txt',
        'xml.txt',
        ))
    av_test = zeit.content.cp.testing.FunctionalDocFileSuite(
        'av.txt',
        layer=CPBrightcoveLayer)
    suite.addTest(av_test)
    rss_test = zeit.content.cp.testing.FunctionalDocFileSuite(
        'rss.txt',
        layer=zeit.content.cp.testing.FeedServer)
    suite.addTest(rss_test)
    return suite

@@ -388,31 +388,8 @@
 ent%0A
-import zope.site.hooks%0A
 %0A%0Ade
@@ -420,69 +420,31 @@
     
-old_site = zope.site.hooks.getSite()%0A    zope.site.hooks.setS
+with zeit.cms.testing.s
 ite(
@@ -448,17 +448,22 @@
 te(root)
-%0A
+:%0A    
     repo
@@ -502,24 +502,28 @@
 ty(%0A        
+   
+ 
 zeit.cms.rep
@@ -555,16 +555,20 @@
 itory)%0A%0A
+    
     for 
@@ -590,16 +590,20 @@
         
+   
+ 
 name = '
@@ -617,16 +617,20 @@
 (i + 1)%0A
+    
         
@@ -700,16 +700,20 @@
         
+  
+  
 c.teaser
@@ -761,32 +761,36 @@
  %25 name%0A        
+    
 repository%5Bname%5D
@@ -799,47 +799,8 @@
  c%0A%0A
-    zope.site.hooks.setSite(old_site)%0A%0A
 %0ACPB
@@ -2011,32 +2011,64 @@
   'teaser.txt',%0A
+        'teaser-countings.txt',%0A
         'teaser-

use context manager instead of doing everything ourselves