From d693b1822952826c640f8637d6603e2578d5fc75 Mon Sep 17 00:00:00 2001 From: Luthando Date: Fri, 20 Oct 2023 15:43:13 +0200 Subject: [PATCH] Initial Tests added for EXTRAS --- src/bika/extras/testing.py | 53 ----- src/bika/extras/tests/__init__.py | 10 + src/bika/extras/tests/base.py | 253 ++++++++++++++++++++++ src/bika/extras/tests/doctests/EXTRAS.rst | 163 ++++++++++++++ src/bika/extras/tests/layers.py | 57 +++++ src/bika/extras/tests/test_add_client.py | 105 +++++++++ src/bika/extras/tests/test_doctests.py | 25 +++ src/bika/extras/tests/test_robot.py | 28 --- src/bika/extras/tests/test_setup.py | 78 ++----- 9 files changed, 626 insertions(+), 146 deletions(-) delete mode 100644 src/bika/extras/testing.py create mode 100644 src/bika/extras/tests/base.py create mode 100644 src/bika/extras/tests/doctests/EXTRAS.rst create mode 100644 src/bika/extras/tests/layers.py create mode 100644 src/bika/extras/tests/test_add_client.py create mode 100644 src/bika/extras/tests/test_doctests.py delete mode 100644 src/bika/extras/tests/test_robot.py diff --git a/src/bika/extras/testing.py b/src/bika/extras/testing.py deleted file mode 100644 index aa25981..0000000 --- a/src/bika/extras/testing.py +++ /dev/null @@ -1,53 +0,0 @@ -# -*- coding: utf-8 -*- -from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE -from plone.app.robotframework.testing import REMOTE_LIBRARY_BUNDLE_FIXTURE -from plone.app.testing import ( - applyProfile, - FunctionalTesting, - IntegrationTesting, - PloneSandboxLayer, -) -from plone.testing import z2 - -import bika.extras - - -class BikaExtrasLayer(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. - import plone.restapi - self.loadZCML(package=plone.restapi) - self.loadZCML(package=bika.extras) - - def setUpPloneSite(self, portal): - applyProfile(portal, 'bika.extras:default') - - -BIKA_EXTRAS_FIXTURE = BikaExtrasLayer() - - -BIKA_EXTRAS_INTEGRATION_TESTING = IntegrationTesting( - bases=(BIKA_EXTRAS_FIXTURE,), - name='BikaExtrasLayer:IntegrationTesting', -) - - -BIKA_EXTRAS_FUNCTIONAL_TESTING = FunctionalTesting( - bases=(BIKA_EXTRAS_FIXTURE,), - name='BikaExtrasLayer:FunctionalTesting', -) - - -BIKA_EXTRAS_ACCEPTANCE_TESTING = FunctionalTesting( - bases=( - BIKA_EXTRAS_FIXTURE, - REMOTE_LIBRARY_BUNDLE_FIXTURE, - z2.ZSERVER_FIXTURE, - ), - name='BikaExtrasLayer:AcceptanceTesting', -) diff --git a/src/bika/extras/tests/__init__.py b/src/bika/extras/tests/__init__.py index e69de29..a66e9bf 100644 --- a/src/bika/extras/tests/__init__.py +++ b/src/bika/extras/tests/__init__.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# +# This file is part of BIKA.EXTRAS +# +# Copyright 2018 by it's authors. +class TestFile(object): + def __init__(self, file, filename=None): + self.file = file + self.headers = {} + self.filename = filename diff --git a/src/bika/extras/tests/base.py b/src/bika/extras/tests/base.py new file mode 100644 index 0000000..0a2dc37 --- /dev/null +++ b/src/bika/extras/tests/base.py @@ -0,0 +1,253 @@ +# -*- coding: utf-8 -*- +# +# This file is part of SENAITE.INSTRUMENTS +# +# Copyright 2018 by it's authors. + +from datetime import datetime + +import unittest2 as unittest +from plone.app.testing import FunctionalTesting +from plone.app.testing import PLONE_FIXTURE +from plone.app.testing import PloneSandboxLayer +from plone.app.testing import TEST_USER_ID +from plone.app.testing import TEST_USER_NAME +from plone.app.testing import TEST_USER_PASSWORD +from plone.app.testing import applyProfile +from plone.app.testing import setRoles +from plone.app.testing.bbb_at import PloneTestCase +from plone.testing import z2 +from senaite.core.tests.layers import BASE_TESTING +from senaite.core.tests.layers import DATA_TESTING + +from Products.Archetypes.event import ObjectInitializedEvent +from Products.CMFPlone.utils import _createObjectByType +from bika.lims import SETUP_CATALOG +from bika.lims import api +from bika.lims.idserver import renameAfterCreation +from bika.lims.utils import tmpID +from bika.lims.utils.analysisrequest import create_analysisrequest +from plone.protect.authenticator import createToken +from zope.event import notify +from zope.testbrowser.browser import Browser + + +class SimpleTestLayer(PloneSandboxLayer): + """Setup Plone with installed AddOn only + """ + defaultBases = (BASE_TESTING, PLONE_FIXTURE,) + + def setUpZope(self, app, configurationContext): + super(SimpleTestLayer, self).setUpZope(app, configurationContext) + + # Load ZCML + import bika.lims + import bika.extras + + self.loadZCML(package=bika.lims) + self.loadZCML(package=bika.extras) + + # Install product and call its initialize() function + z2.installProduct(app, "bika.extras") + + def setUpPloneSite(self, portal): + super(SimpleTestLayer, self).setUpPloneSite(portal) + + # Apply Setup Profile (portal_quickinstaller) + applyProfile(portal, 'bika.lims:default') + + +### +# Use for simple tests (w/o contents) +### +SIMPLE_FIXTURE = SimpleTestLayer() +SIMPLE_TESTING = FunctionalTesting( + bases=(SIMPLE_FIXTURE,), + name="bika.extras:SimpleTesting" +) + + +class SimpleTestCase(unittest.TestCase): + layer = SIMPLE_TESTING + + def setUp(self): + super(SimpleTestCase, self).setUp() + + self.app = self.layer["app"] + self.portal = self.layer["portal"] + self.request = self.layer["request"] + self.request["ACTUAL_URL"] = self.portal.absolute_url() + setRoles(self.portal, TEST_USER_ID, ["LabManager", "Manager"]) + + +class FunctionalTestCase(unittest.TestCase): + layer = SIMPLE_TESTING + + def setUp(self): + super(FunctionalTestCase, self).setUp() + + self.app = self.layer["app"] + self.portal = self.layer["portal"] + self.request = self.layer["request"] + self.request["ACTUAL_URL"] = self.portal.absolute_url() + setRoles(self.portal, TEST_USER_ID, ["LabManager", "Member"]) + + +class BaseTestCase(PloneTestCase): + """from senaite.core.tests.base.BaseTestCase + """ + layer = BASE_TESTING + + def setUp(self): + super(BaseTestCase, self).setUp() + self.request = self.layer["request"] + self.request.form["_authenticator"] = createToken() + self.request.environ["REQUEST_METHOD"] = "POST" + self.portal.changeSkin("Plone Default") + + def getBrowser(self, + username=TEST_USER_NAME, + password=TEST_USER_PASSWORD, + loggedIn=True): + # Instantiate and return a testbrowser for convenience + browser = Browser(self.portal) + browser.addHeader("Accept-Language", "en-US") + browser.handleErrors = False + if loggedIn: + browser.open(self.portal.absolute_url()) + browser.getControl("Login Name").value = username + browser.getControl("Password").value = password + browser.getControl("Log in").click() + self.assertTrue("You are now logged in" in browser.contents) + return browser + + def add_client(self, **kwargs): + folder = self.portal.clients + obj = _createObjectByType('Client', folder, tmpID()) + obj.edit(**kwargs) + obj.unmarkCreationFlag() + renameAfterCreation(obj) + notify(ObjectInitializedEvent(obj)) + return obj + + def add_contact(self, folder, **kwargs): + obj = _createObjectByType('Contact', folder, tmpID()) + obj.edit(**kwargs) + obj.unmarkCreationFlag() + renameAfterCreation(obj) + notify(ObjectInitializedEvent(obj)) + return obj + + def add_manufacturer(self, **kwargs): + folder = self.portal.bika_setup.bika_manufacturers + obj = _createObjectByType('Manufacturer', folder, tmpID()) + obj.edit(**kwargs) + obj.unmarkCreationFlag() + renameAfterCreation(obj) + notify(ObjectInitializedEvent(obj)) + return obj + + def add_supplier(self, **kwargs): + folder = self.portal.bika_setup.bika_suppliers + obj = _createObjectByType('Supplier', folder, tmpID()) + obj.edit(**kwargs) + obj.unmarkCreationFlag() + renameAfterCreation(obj) + notify(ObjectInitializedEvent(obj)) + return obj + + def add_instrumenttype(self, **kwargs): + folder = self.portal.bika_setup.bika_instrumenttypes + obj = _createObjectByType('InstrumentType', folder, tmpID()) + obj.edit(**kwargs) + obj.unmarkCreationFlag() + renameAfterCreation(obj) + notify(ObjectInitializedEvent(obj)) + return obj + + def add_instrument(self, **kwargs): + folder = self.portal.bika_setup.bika_instruments + obj = _createObjectByType('Instrument', folder, tmpID()) + obj.edit(**kwargs) + obj.unmarkCreationFlag() + renameAfterCreation(obj) + notify(ObjectInitializedEvent(obj)) + return obj + + def add_analysiscategory(self, **kwargs): + folder = self.portal.bika_setup.bika_analysiscategories + obj = _createObjectByType('AnalysisCategory', folder, tmpID()) + obj.edit(**kwargs) + obj.unmarkCreationFlag() + renameAfterCreation(obj) + notify(ObjectInitializedEvent(obj)) + return obj + + def add_analysisservice(self, **kwargs): + # service + folder = self.portal.bika_setup.bika_analysisservices + obj = _createObjectByType('AnalysisService', folder, tmpID()) + obj.edit(**kwargs) + # done + obj.unmarkCreationFlag() + renameAfterCreation(obj) + notify(ObjectInitializedEvent(obj)) + + return obj + + def add_calculation(self, **kwargs): + folder = self.portal.bika_setup.bika_calculations + obj = _createObjectByType('Calculation', folder, tmpID()) + obj.edit(**kwargs) + obj.unmarkCreationFlag() + renameAfterCreation(obj) + notify(ObjectInitializedEvent(obj)) + return obj + + def add_sampletype(self, **kwargs): + folder = self.portal.bika_setup.bika_sampletypes + if 'folder' in kwargs: + folder = kwargs.get('folder', folder) + del(kwargs['folder']) + obj = _createObjectByType('SampleType', folder, tmpID()) + obj.edit(**kwargs) + obj.unmarkCreationFlag() + renameAfterCreation(obj) + notify(ObjectInitializedEvent(obj)) + return obj + + def add_analysisrequest(self, client, kwargs, services): + return create_analysisrequest(client, self.request, kwargs, services) + + def add_worksheet(self, ar, **kwargs): + # Worksheet creation + wsfolder = self.portal.worksheets + ws = _createObjectByType("Worksheet", wsfolder, tmpID()) + ws.processForm() + bsc = api.get_tool('senaite_catalog_setup') + lab_contacts = [o.getObject() for o in bsc(portal_type="LabContact")] + lab_contact = [o for o in lab_contacts if o.getUsername() == 'analyst1'] + self.assertEquals(len(lab_contact), 1) + lab_contact = lab_contact[0] + ws.setAnalyst(lab_contact.getUsername()) + ws.setResultsLayout(self.portal.bika_setup.getWorksheetLayout()) + # Add analyses into the worksheet + self.request['context_uid'] = ws.UID() + for analysis in ar.getAnalyses(): + ws.addAnalysis(analysis.getObject()) + self.assertEquals(len(ws.getAnalyses()), 2) + return ws + + def add_duplicate(self, worksheet, **kwargs): + # Add a duplicate for slot 1 (there's only one slot) + worksheet.addDuplicateAnalyses('1', None) + ans = worksheet.getAnalyses() + reg = [an for an in ans if an.portal_type == 'Analysis'] + dup = [an for an in ans if an.portal_type == 'DuplicateAnalysis'] + return dup + + +class DataTestCase(BaseTestCase): + """Use for test cases which rely on the demo data + """ + layer = DATA_TESTING diff --git a/src/bika/extras/tests/doctests/EXTRAS.rst b/src/bika/extras/tests/doctests/EXTRAS.rst new file mode 100644 index 0000000..04f2efc --- /dev/null +++ b/src/bika/extras/tests/doctests/EXTRAS.rst @@ -0,0 +1,163 @@ +BIKA EXTRAS +=================== + +Import and export instrument adapters for SENAITE + +Running this test from the buildout directory:: + + bin/test test_doctests -t EXTRAS + + +Test Setup +---------- +Needed imports:: + + >>> import os + >>> import cStringIO + >>> from bika.lims import api + >>> from bika.lims.utils.analysisrequest import create_analysisrequest + >>> from DateTime import DateTime + + >>> from senaite.app.supermodel.interfaces import ISuperModel + >>> from bika.extras.tests import test_setup + >>> from zope.component import getAdapter + >>> from zope.publisher.browser import FileUpload, TestRequest + +Functional helpers:: + + >>> def timestamp(format="%Y-%m-%d"): + ... return DateTime().strftime(format) + + >>> class TestFile(object): + ... def __init__(self, file, filename='dummy.txt'): + ... self.file = file + ... self.headers = {} + ... self.filename = filename + +Variables:: + + >>> date_now = timestamp() + >>> portal = self.portal + >>> request = self.request + >>> bika_setup = portal.bika_setup + >>> bika_sampletypes = bika_setup.bika_sampletypes + >>> bika_samplepoints = bika_setup.bika_samplepoints + >>> bika_analysiscategories = bika_setup.bika_analysiscategories + >>> bika_analysisservices = bika_setup.bika_analysisservices + >>> bika_calculations = bika_setup.bika_calculations + >>> bika_methods = portal.methods + +We need certain permissions to create and access objects used in this test, +so here we will assume the role of Lab Manager:: + + >>> from plone.app.testing import TEST_USER_ID + >>> from plone.app.testing import setRoles + >>> setRoles(portal, TEST_USER_ID, ['Manager',]) + + +Import test +----------- + +Required steps: Create and receive Analysis Request for import test +................................................................... + +An `AnalysisRequest` can only be created inside a `Client`, and it also requires a `Contact` and +a `SampleType`:: + + >>> clients = self.portal.clients + >>> client = api.create(clients, "Client", Name="NARALABS", ClientID="NLABS") + >>> client + + >>> contact = api.create(client, "Contact", Firstname="Juan", Surname="Gallostra") + >>> contact + + >>> sampletype = api.create(bika_sampletypes, "SampleType", Prefix="H2O", MinimumVolume="100 ml") + >>> sampletype + + +Create an `AnalysisCategory` (which categorizes different `AnalysisServices`), and add to it an `AnalysisService`. +This service matches the service specified in the file from which the import will be performed:: + + >>> analysiscategory = api.create(bika_analysiscategories, "AnalysisCategory", title="Water") + >>> analysiscategory + + >>> analysisservice1 = api.create(bika_analysisservices, + ... "AnalysisService", + ... title="HIV06ml", + ... ShortTitle="hiv06", + ... Category=analysiscategory, + ... Keyword="HIV06ml") + >>> analysisservice1 + + + >>> analysisservice2 = api.create(bika_analysisservices, + ... 'AnalysisService', + ... title='Magnesium', + ... ShortTitle='Mg', + ... Category=analysiscategory, + ... Keyword="Mg") + >>> analysisservice2 + + >>> analysisservice3 = api.create(bika_analysisservices, + ... 'AnalysisService', + ... title='Calcium', + ... ShortTitle='Ca', + ... Category=analysiscategory, + ... Keyword="Ca") + >>> analysisservice3 + + + >>> total_calc = api.create(bika_calculations, 'Calculation', title='TotalMagCal') + >>> total_calc.setFormula('[Mg] + [Ca]') + + >>> a_method = api.create(bika_methods, 'Method', title='A Method') + >>> a_method.setCalculation(total_calc) + + >>> analysisservice4 = api.create(bika_analysisservices, 'AnalysisService', title='THCaCO3', Keyword="THCaCO3") + >>> analysisservice4.setUseDefaultCalculation(False) + >>> analysisservice4.setCalculation(total_calc) + >>> analysisservice4.setMethod(a_method) + >>> analysisservice4 + + + >>> interim_calc = api.create(bika_calculations, 'Calculation', title='Test-Total-Pest') + >>> pest1 = {'keyword': 'pest1', 'title': 'Pesticide 1', 'value': 0, 'type': 'int', 'hidden': False, 'unit': ''} + >>> pest2 = {'keyword': 'pest2', 'title': 'Pesticide 2', 'value': 0, 'type': 'int', 'hidden': False, 'unit': ''} + >>> pest3 = {'keyword': 'pest3', 'title': 'Pesticide 3', 'value': 0, 'type': 'int', 'hidden': False, 'unit': ''} + >>> interims = [pest1, pest2, pest3] + >>> interim_calc.setInterimFields(interims) + >>> self.assertEqual(interim_calc.getInterimFields(), interims) + >>> interim_calc.setFormula('((([pest1] > 0.0) or ([pest2] > .05) or ([pest3] > 10.0) ) and "PASS" or "FAIL" )') + >>> analysisservice5 = api.create(bika_analysisservices, 'AnalysisService', title='Total Terpenes', Keyword="TotalTerpenes") + >>> analysisservice5.setUseDefaultCalculation(False) + >>> analysisservice5.setCalculation(interim_calc) + >>> analysisservice5.setInterimFields(interims) + >>> analysisservice5 + + + >>> service_uids = [ + ... analysisservice1.UID(), + ... analysisservice2.UID(), + ... analysisservice3.UID(), + ... analysisservice4.UID(), + ... analysisservice5.UID() + ... ] + +Create an `AnalysisRequest` with this `AnalysisService` and receive it:: + + >>> values = { + ... 'Client': client.UID(), + ... 'Contact': contact.UID(), + ... 'SamplingDate': date_now, + ... 'DateSampled': date_now, + ... 'SampleType': sampletype.UID() + ... } + >>> ar = create_analysisrequest(client, request, values, service_uids) + >>> ar + + >>> ar.getReceivedBy() + '' + >>> wf = api.get_tool('portal_workflow') + >>> wf.doActionFor(ar, 'receive') + >>> ar.getReceivedBy() + 'test_user_1_' diff --git a/src/bika/extras/tests/layers.py b/src/bika/extras/tests/layers.py new file mode 100644 index 0000000..b6163a9 --- /dev/null +++ b/src/bika/extras/tests/layers.py @@ -0,0 +1,57 @@ +from plone.app.testing import FunctionalTesting +from plone.app.testing import PLONE_FIXTURE +from plone.app.testing import PloneSandboxLayer +from plone.app.testing import applyProfile +from plone.testing import zope + +import transaction + + +class BaseLayer(PloneSandboxLayer): + defaultBases = (PLONE_FIXTURE,) + + def setUpZope(self, app, configurationContext): + super(BaseLayer, self).setUpZope(app, configurationContext) + + import bika.lims + import senaite.core + import senaite.app.listing + import senaite.app.spotlight + import senaite.app.supermodel + import senaite.impress + import senaite.lims + import senaite.instruments + import Products.TextIndexNG3 + import bika.extras + + self.loadZCML(package=bika.lims) + self.loadZCML(package=senaite.core) + self.loadZCML(package=senaite.app.listing) + self.loadZCML(package=senaite.app.spotlight) + self.loadZCML(package=senaite.app.supermodel) + self.loadZCML(package=senaite.impress) + self.loadZCML(package=senaite.lims) + self.loadZCML(package=senaite.instruments) + self.loadZCML(package=Products.TextIndexNG3) + self.loadZCML(package=bika.extras) + + zope.installProduct(app, "bika.lims") + zope.installProduct(app, "senaite.core") + zope.installProduct(app, "senaite.app.listing") + zope.installProduct(app, "senaite.app.spotlight") + zope.installProduct(app, "senaite.app.supermodel") + zope.installProduct(app, "senaite.impress") + zope.installProduct(app, "senaite.lims") + zope.installProduct(app, "senaite.instruments") + zope.installProduct(app, "Products.TextIndexNG3") + zope.installProduct(app, "bika.extras") + + def setUpPloneSite(self, portal): + super(BaseLayer, self).setUpPloneSite(portal) + applyProfile(portal, "senaite.core:default") + transaction.commit() + + +BASE_LAYER_FIXTURE = BaseLayer() +BASE_TESTING = FunctionalTesting( + bases=(BASE_LAYER_FIXTURE,), name="BIKA.EXTRAS:BaseTesting") diff --git a/src/bika/extras/tests/test_add_client.py b/src/bika/extras/tests/test_add_client.py new file mode 100644 index 0000000..2cd184d --- /dev/null +++ b/src/bika/extras/tests/test_add_client.py @@ -0,0 +1,105 @@ +# -*- coding: utf-8 -*- +# +# This file is part of SENAITE.INSTRUMENTS +# +# Copyright 2018 by it's authors. + + +import cStringIO +from datetime import datetime +from os.path import abspath +from os.path import dirname +from os.path import join + +import unittest2 as unittest +from plone.app.testing import TEST_USER_ID +from plone.app.testing import TEST_USER_NAME +from plone.app.testing import login +from plone.app.testing import setRoles + +from bika.lims import api +from senaite.instruments.instruments.bika.software.software import ( + softwareimport) +from senaite.instruments.tests import TestFile +from senaite.instruments.tests.base import BaseTestCase +from zope.publisher.browser import FileUpload +from zope.publisher.browser import TestRequest + + +TITLE = 'BIKA EXTRAS INITIAL TEST' +IFACE = 'senaite.instruments.instruments' \ + '.bika.software.software.softwareimport' + +here = abspath(dirname(__file__)) + + +class TestSoftware(BaseTestCase): + + def setUp(self): + super(TestSoftware, self).setUp() + setRoles(self.portal, TEST_USER_ID, ['Member', 'LabManager']) + login(self.portal, TEST_USER_NAME) + + self.client = self.add_client(title='Happy Hills', ClientID='HH') + + self.contact = self.add_contact( + self.client, Firstname='Rita', Surname='Mohale') + + self.services = [ + self.add_analysisservice( + title='Bromide', + Keyword='Br', + PointOfCapture='lab', + Category=self.add_analysiscategory( + title='Phyisical Properties'), + AllowManualUncertainty='True'), + self.add_analysisservice( + title='Silica', + Keyword='SiO', + PointOfCapture='lab', + Category=self.add_analysiscategory( + title='Phyisical Properties'), + AllowManualUncertainty='True'), + self.add_analysisservice( + title='Sulfate', + Keyword='SO', + PointOfCapture='lab', + Category=self.add_analysiscategory( + title='Phyisical Properties'), + AllowManualUncertainty='True'), + self.add_analysisservice( + title='Calcium', + Keyword='Ca', + PointOfCapture='lab', + Category=self.add_analysiscategory( + title='Phyisical Properties'), + AllowManualUncertainty='True'), + self.add_analysisservice( + title='Magnesium', + Keyword='Mg', + PointOfCapture='lab', + Category=self.add_analysiscategory( + title='Phyisical Properties'), + AllowManualUncertainty='True'), + self.add_analysisservice( + title='Chloride', + Keyword='Cl', + PointOfCapture='lab', + Category=self.add_analysiscategory( + title='Organic'), + AllowManualUncertainty='True') + ] + self.sampletype = self.add_sampletype( + title='Dust', RetentionPeriod=dict(days=1), + MinimumVolume='1 kg', Prefix='DU') + + def test_add_analysis_request(self): + ar = self.add_analysisrequest( + self.client, + dict(Client=self.client.UID(), + Contact=self.contact.UID(), + DateSampled=datetime.now().date().isoformat(), + SampleType=self.sampletype.UID()), + [srv.UID() for srv in self.services]) + + self.assertEqual(ar.getClientTitle(), "Happy Hills") diff --git a/src/bika/extras/tests/test_doctests.py b/src/bika/extras/tests/test_doctests.py new file mode 100644 index 0000000..3e64b8e --- /dev/null +++ b/src/bika/extras/tests/test_doctests.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# +# This file is part of SENAITE.INSTRUMENTS +# +# Copyright 2018 by it's authors. + +import doctest + +import unittest2 as unittest + +from Testing import ZopeTestCase as ztc + +from .base import SimpleTestCase + + +def test_suite(): + suite = unittest.TestSuite() + suite.addTests([ + ztc.ZopeDocFileSuite( + "doctests/EXTRAS.rst", + test_class=SimpleTestCase, + optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE, + ), + ]) + return suite diff --git a/src/bika/extras/tests/test_robot.py b/src/bika/extras/tests/test_robot.py deleted file mode 100644 index b4912f1..0000000 --- a/src/bika/extras/tests/test_robot.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- -from bika.extras.testing import BIKA_EXTRAS_ACCEPTANCE_TESTING # noqa: E501 -from plone.app.testing import ROBOT_TEST_LEVEL -from plone.testing import layered - -import os -import robotsuite -import unittest - - -def test_suite(): - suite = unittest.TestSuite() - current_dir = os.path.abspath(os.path.dirname(__file__)) - robot_dir = os.path.join(current_dir, 'robot') - robot_tests = [ - os.path.join('robot', doc) for doc in os.listdir(robot_dir) - if doc.endswith('.robot') and doc.startswith('test_') - ] - for robot_test in robot_tests: - robottestsuite = robotsuite.RobotTestSuite(robot_test) - robottestsuite.level = ROBOT_TEST_LEVEL - suite.addTests([ - layered( - robottestsuite, - layer=BIKA_EXTRAS_ACCEPTANCE_TESTING, - ), - ]) - return suite diff --git a/src/bika/extras/tests/test_setup.py b/src/bika/extras/tests/test_setup.py index d759297..2696f0e 100644 --- a/src/bika/extras/tests/test_setup.py +++ b/src/bika/extras/tests/test_setup.py @@ -1,71 +1,19 @@ # -*- coding: utf-8 -*- -"""Setup tests for this package.""" -from bika.extras.testing import BIKA_EXTRAS_INTEGRATION_TESTING # noqa: E501 -from plone import api -from plone.app.testing import setRoles, TEST_USER_ID +# +# This file is part of BIKA.EXTRAS +# +# Copyright 2018 by it's authors. -import unittest +from .base import SimpleTestCase -try: - from Products.CMFPlone.utils import get_installer -except ImportError: - get_installer = None +class TestSetup(SimpleTestCase): + """ Test Setup + """ -class TestSetup(unittest.TestCase): - """Test that bika.extras is properly installed.""" - - layer = BIKA_EXTRAS_INTEGRATION_TESTING - - def setUp(self): - """Custom shared utility setup for tests.""" - self.portal = self.layer['portal'] - if get_installer: - self.installer = get_installer(self.portal, self.layer['request']) - else: - self.installer = api.portal.get_tool('portal_quickinstaller') - - def test_product_installed(self): - """Test if bika.extras is installed.""" - self.assertTrue(self.installer.isProductInstalled( - 'bika.extras')) - - def test_browserlayer(self): - """Test that IBikaExtrasLayer is registered.""" - from bika.extras.interfaces import ( - IBikaExtrasLayer) - from plone.browserlayer import utils - self.assertIn( - IBikaExtrasLayer, - utils.registered_layers()) - - -class TestUninstall(unittest.TestCase): - - layer = BIKA_EXTRAS_INTEGRATION_TESTING - - def setUp(self): - self.portal = self.layer['portal'] - if get_installer: - self.installer = get_installer(self.portal, self.layer['request']) - else: - self.installer = api.portal.get_tool('portal_quickinstaller') - roles_before = api.user.get_roles(TEST_USER_ID) - setRoles(self.portal, TEST_USER_ID, ['Manager']) - self.installer.uninstallProducts(['bika.extras']) - setRoles(self.portal, TEST_USER_ID, roles_before) - - def test_product_uninstalled(self): - """Test if bika.extras is cleanly uninstalled.""" - self.assertFalse(self.installer.isProductInstalled( - 'bika.extras')) - - def test_browserlayer_removed(self): - """Test that IBikaExtrasLayer is removed.""" - from bika.extras.interfaces import \ - IBikaExtrasLayer - from plone.browserlayer import utils - self.assertNotIn( - IBikaExtrasLayer, - utils.registered_layers()) +def test_suite(): + from unittest import TestSuite, makeSuite + suite = TestSuite() + suite.addTest(makeSuite(TestSetup)) + return suite