<commit_before># Copyright (c) 2009-2011 gocept gmbh & co. kg
# See also LICENSE.txt

import mock
import zeit.cms.testing
import zeit.solr.interfaces
import zope.component
import zope.interface


class RequestHandler(zeit.cms.testing.BaseHTTPRequestHandler):

    serve = []

    def do_GET(self):
        if self.serve:
            serve = self.serve.pop(0)
            self.send_response(200)
            self.end_headers()
            self.wfile.write(serve)
        else:
            self.send_response(500)
            self.send_header('Reason', 'Nothing to serve for %s' % self.path)
            self.end_headers()


BaseHTTPLayer, port = zeit.cms.testing.HTTPServerLayer(RequestHandler)
SOLR_URL = 'http://localhost:%s/solr/' % port

product_config = """\
<product-config zeit.solr>
    solr-url %s
</product-config>
""" % SOLR_URL


class HTTPLayer(BaseHTTPLayer):

    SOLR_URL = SOLR_URL
    REQUEST_HANDLER = RequestHandler

    @classmethod
    def testTearDown(cls):
        cls.REQUEST_HANDLER.serve[:] = []

    @classmethod
    def testSetUp(cls):
        pass

    @classmethod
    def tearDown(cls):
        pass

    @classmethod
    def setUp(cls):
        pass


BaseSolrLayer = zeit.cms.testing.ZCMLLayer(
    'ftesting.zcml',
    product_config=zeit.cms.testing.cms_product_config + product_config)


class SolrLayer(HTTPLayer, BaseSolrLayer):

    @classmethod
    def testTearDown(cls):
        pass

    @classmethod
    def testSetUp(cls):
        pass

    @classmethod
    def tearDown(cls):
        pass

    @classmethod
    def setUp(cls):
        pass


class SolrMockLayerBase(object):

    @classmethod
    def setUp(cls):
        cls.solr = mock.Mock()
        zope.interface.alsoProvides(cls.solr, zeit.solr.interfaces.ISolr)
        zope.component.getSiteManager().registerUtility(cls.solr)

    @classmethod
    def tearDown(cls):
        zope.component.getSiteManager().unregisterUtility(cls.solr)

    @classmethod
    def testTearDown(cls):
        cls.solr.reset_mock()


class SolrMockLayer(SolrLayer, SolrMockLayerBase):
    """Mocked solr."""


class MockedFunctionalTestCase(zeit.cms.testing.FunctionalTestCase):

    layer = SolrMockLayer

    def setUp(self):
        super(MockedFunctionalTestCase, self).setUp()
        self.solr = self.layer.solr


class FunctionalTestCase(zeit.cms.testing.FunctionalTestCase):

    layer = SolrLayer

    def setUp(self):
        super(FunctionalTestCase, self).setUp()
        self.solr = zope.component.getUtility(zeit.solr.interfaces.ISolr)
<commit_msg>Re VIV-249: Set up article product config in tests (the layout sources need it now)<commit_after># Copyright (c) 2009-2011 gocept gmbh & co. kg
# See also LICENSE.txt

import mock
import zeit.cms.testing
import zeit.content.article.testing
import zeit.solr.interfaces
import zope.component
import zope.interface


class RequestHandler(zeit.cms.testing.BaseHTTPRequestHandler):

    serve = []

    def do_GET(self):
        if self.serve:
            serve = self.serve.pop(0)
            self.send_response(200)
            self.end_headers()
            self.wfile.write(serve)
        else:
            self.send_response(500)
            self.send_header('Reason', 'Nothing to serve for %s' % self.path)
            self.end_headers()


BaseHTTPLayer, port = zeit.cms.testing.HTTPServerLayer(RequestHandler)
SOLR_URL = 'http://localhost:%s/solr/' % port

product_config = """\
<product-config zeit.solr>
    solr-url %s
</product-config>
""" % SOLR_URL


class HTTPLayer(BaseHTTPLayer):

    SOLR_URL = SOLR_URL
    REQUEST_HANDLER = RequestHandler

    @classmethod
    def testTearDown(cls):
        cls.REQUEST_HANDLER.serve[:] = []

    @classmethod
    def testSetUp(cls):
        pass

    @classmethod
    def tearDown(cls):
        pass

    @classmethod
    def setUp(cls):
        pass


BaseSolrLayer = zeit.cms.testing.ZCMLLayer(
    'ftesting.zcml',
    product_config=zeit.cms.testing.cms_product_config
    + zeit.content.article.testing.product_config
    + product_config)


class SolrLayer(HTTPLayer, BaseSolrLayer):

    @classmethod
    def testTearDown(cls):
        pass

    @classmethod
    def testSetUp(cls):
        pass

    @classmethod
    def tearDown(cls):
        pass

    @classmethod
    def setUp(cls):
        pass


class SolrMockLayerBase(object):

    @classmethod
    def setUp(cls):
        cls.solr = mock.Mock()
        zope.interface.alsoProvides(cls.solr, zeit.solr.interfaces.ISolr)
        zope.component.getSiteManager().registerUtility(cls.solr)

    @classmethod
    def tearDown(cls):
        zope.component.getSiteManager().unregisterUtility(cls.solr)

    @classmethod
    def testTearDown(cls):
        cls.solr.reset_mock()


class SolrMockLayer(SolrLayer, SolrMockLayerBase):
    """Mocked solr."""


class MockedFunctionalTestCase(zeit.cms.testing.FunctionalTestCase):

    layer = SolrMockLayer

    def setUp(self):
        super(MockedFunctionalTestCase, self).setUp()
        self.solr = self.layer.solr


class FunctionalTestCase(zeit.cms.testing.FunctionalTestCase):

    layer = SolrLayer

    def setUp(self):
        super(FunctionalTestCase, self).setUp()
        self.solr = zope.component.getUtility(zeit.solr.interfaces.ISolr)

{'fraction_non_alphanumeric': 0.10522302706824246, 'fraction_numerical': 0.006290507052992757, 'mean_word_length': 2.8723247232472326, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5291578', 'n_tokens_mistral': 1810, 'n_tokens_neox': 1700, 'n_words': 307}