Skip to content

Commit

Permalink
migrate test to PLONE_APP_CONTENTTYPES_FIXTURE
Browse files Browse the repository at this point in the history
  • Loading branch information
pbauer committed Jun 10, 2018
1 parent 65f197d commit 2991e74
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Products/MimetypesRegistry/mime_types/mtr_mimetypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class text_xml(MimeTypeItem):
binary = 0

def classify(self, data):
m = re.search('^\s*<\\?xml.*\\?>', data)
m = re.search(b'^\\s*<\\?xml.*\\?>', data)
if m:
return 1 # True
return None # False
Expand Down
30 changes: 30 additions & 0 deletions Products/MimetypesRegistry/testing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
from plone.app.testing import applyProfile
from plone.app.testing import IntegrationTesting
from plone.app.testing import PloneSandboxLayer

import Products.MimetypesRegistry


class ProductsMimetypesregistryLayer(PloneSandboxLayer):

defaultBases = (PLONE_APP_CONTENTTYPES_FIXTURE,)

def setUpZope(self, app, configurationContext):
# Load any other ZCML that is required for your tests.
# The z3c.autoinclude feature is disabled in the Plone fixture base
# layer.
self.loadZCML(package=Products.MimetypesRegistry)

def setUpPloneSite(self, portal):
applyProfile(portal, 'Products.MimetypesRegistry:MimetypesRegistry')


PRODUCTS_MIMETYPESREGISTRY_FIXTURE = ProductsMimetypesregistryLayer()


PRODUCTS_MIMETYPESREGISTRY_INTEGRATION_TESTING = IntegrationTesting(
bases=(PRODUCTS_MIMETYPESREGISTRY_FIXTURE,),
name='ProductsMimetypesregistryLayer:IntegrationTesting',
)
9 changes: 7 additions & 2 deletions Products/MimetypesRegistry/tests/test_encoding.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# -*- coding: utf-8 -*-
from plone.app.testing.bbb import PloneTestCase as ATSiteTestCase
from Products.MimetypesRegistry.encoding import guess_encoding
from Products.MimetypesRegistry.testing import PRODUCTS_MIMETYPESREGISTRY_INTEGRATION_TESTING

import unittest


class TestGuessEncoding(unittest.TestCase):

layer = PRODUCTS_MIMETYPESREGISTRY_INTEGRATION_TESTING

class TestGuessEncoding(ATSiteTestCase):

def testUTF8(self):
e = guess_encoding('\xef\xbb\xbf any UTF-8 data')
Expand Down
16 changes: 10 additions & 6 deletions Products/MimetypesRegistry/tests/test_magic.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
from .utils import input_file_path
from plone.app.testing.bbb import PloneTestCase as ATSiteTestCase
from Products.MimetypesRegistry.tests.utils import input_file_path
from Products.CMFCore.utils import getToolByName
from Products.MimetypesRegistry.mime_types.magic import guessMime
from Products.MimetypesRegistry.testing import PRODUCTS_MIMETYPESREGISTRY_INTEGRATION_TESTING

import unittest


samplefiles = [
Expand All @@ -13,15 +15,17 @@
]


class TestGuessMagic(ATSiteTestCase):
class TestGuessMagic(unittest.TestCase):

layer = PRODUCTS_MIMETYPESREGISTRY_INTEGRATION_TESTING

def afterSetUp(self):
ATSiteTestCase.afterSetUp(self)
def setUp(self):
self.portal = self.layer['portal']
self.registry = getToolByName(self.portal, 'mimetypes_registry')

def test_guessMime(self):
for filename, expected in samplefiles:
file = open(input_file_path(filename))
file = open(input_file_path(filename), 'rb')
data = file.read()
file.close()

Expand Down
15 changes: 10 additions & 5 deletions Products/MimetypesRegistry/tests/test_mimetypes.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# -*- coding: utf-8 -*-
from .utils import input_file_path
from plone.app.testing.bbb import PloneTestCase as ATSiteTestCase
from Products.MimetypesRegistry.tests.utils import input_file_path
# from plone.app.testing.bbb import PloneTestCase as ATSiteTestCase
from Products.CMFCore.utils import getToolByName
from Products.MimetypesRegistry.mime_types import application_octet_stream
from Products.MimetypesRegistry.mime_types import text_plain
from Products.MimetypesRegistry.mime_types import text_xml
from Products.MimetypesRegistry.testing import PRODUCTS_MIMETYPESREGISTRY_INTEGRATION_TESTING

import unittest

class TestMimeTypesclass(ATSiteTestCase):

def afterSetUp(self):
ATSiteTestCase.afterSetUp(self)
class TestMimeTypesclass(unittest.TestCase):

layer = PRODUCTS_MIMETYPESREGISTRY_INTEGRATION_TESTING

def setUp(self):
self.portal = self.layer['portal']
self.registry = getToolByName(self.portal, 'mimetypes_registry')

def testClassify(self):
Expand Down

0 comments on commit 2991e74

Please sign in to comment.