Skip to content

Commit ed0eb20

Browse files
authored
Import demo data in tests with Generic Setup (#2008)
* Import demo data in tests with Generic Setup * Chagelog updated * Added demo data
1 parent e86af72 commit ed0eb20

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

CHANGES.rst

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
2.2.0 (unreleased)
55
------------------
66

7+
- #2008 Import demo data in tests with Generic Setup
78
- #2002 Allow string results for calculation dependencies
89
- #2004 Added behavior to allow sharing objects across clients users
910
- #2001 Fix Traceback when rendering UIDReferenceWidget with limited privileges

src/senaite/core/exportimport/genericsetup/structure.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,10 @@ def import_xml(context):
582582

583583
qi = api.get_tool("portal_quickinstaller")
584584
installed = qi.isProductInstalled("senaite.core")
585+
request = api.get_request()
585586

586-
if not installed:
587+
# tests call it w/o request
588+
if request and not installed:
587589
logger.debug("Nothing to import.")
588590
return
589591

src/senaite/core/tests/layers.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
# Copyright 2018-2021 by it's authors.
1919
# Some rights reserved, see README and LICENSE.
2020

21+
import os
22+
2123
import transaction
22-
from senaite.core.exportimport.load_setup_data import LoadSetupData
24+
from bika.lims import api
2325
from plone.app.testing import PLONE_FIXTURE
2426
from plone.app.testing import SITE_OWNER_NAME
2527
from plone.app.testing import FunctionalTesting
@@ -28,6 +30,7 @@
2830
from plone.app.testing import login
2931
from plone.app.testing import logout
3032
from plone.testing import zope
33+
from Products.GenericSetup.context import TarballImportContext
3134

3235

3336
class BaseLayer(PloneSandboxLayer):
@@ -73,20 +76,30 @@ class DataLayer(BaseLayer):
7376
"""
7477

7578
def setup_data_load(self, portal, request):
76-
login(portal.aq_parent, SITE_OWNER_NAME) # again
79+
"""Provision site with demo data
80+
"""
81+
login(portal.aq_parent, SITE_OWNER_NAME)
82+
83+
setup_tool = api.get_tool("portal_setup")
84+
curdir = os.path.dirname(__file__)
85+
path = os.path.join(curdir, "setup_tool-demodata.tar.gz")
86+
87+
with open(path, "rb") as tarball:
88+
context = TarballImportContext(
89+
tool=setup_tool,
90+
archive_bits=tarball.read(),
91+
encoding="UTF-8",
92+
should_purge=True)
93+
setup_tool._doRunImportStep("senaite.core.import", context)
94+
95+
transaction.commit()
7796

78-
# load test data
79-
request.form["setupexisting"] = 1
80-
request.form["existing"] = "bika.lims:test"
81-
lsd = LoadSetupData(portal, request)
82-
lsd()
8397
logout()
8498

8599
def setUpPloneSite(self, portal):
86100
super(DataLayer, self).setUpPloneSite(portal)
87101
# Install Demo Data
88102
self.setup_data_load(portal, portal.REQUEST)
89-
transaction.commit()
90103

91104

92105
BASE_LAYER_FIXTURE = BaseLayer()
Binary file not shown.

0 commit comments

Comments
 (0)