Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import demo data in tests with Generic Setup #2008

Merged
merged 3 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.2.0 (unreleased)
------------------

- #2008 Import demo data in tests with Generic Setup
- #2002 Allow string results for calculation dependencies
- #2004 Added behavior to allow sharing objects across clients users
- #2001 Fix Traceback when rendering UIDReferenceWidget with limited privileges
Expand Down
4 changes: 3 additions & 1 deletion src/senaite/core/exportimport/genericsetup/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,10 @@ def import_xml(context):

qi = api.get_tool("portal_quickinstaller")
installed = qi.isProductInstalled("senaite.core")
request = api.get_request()

if not installed:
# tests call it w/o request
if request and not installed:
logger.debug("Nothing to import.")
return

Expand Down
29 changes: 21 additions & 8 deletions src/senaite/core/tests/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
# Copyright 2018-2021 by it's authors.
# Some rights reserved, see README and LICENSE.

import os

import transaction
from senaite.core.exportimport.load_setup_data import LoadSetupData
from bika.lims import api
from plone.app.testing import PLONE_FIXTURE
from plone.app.testing import SITE_OWNER_NAME
from plone.app.testing import FunctionalTesting
Expand All @@ -28,6 +30,7 @@
from plone.app.testing import login
from plone.app.testing import logout
from plone.testing import zope
from Products.GenericSetup.context import TarballImportContext


class BaseLayer(PloneSandboxLayer):
Expand Down Expand Up @@ -73,20 +76,30 @@ class DataLayer(BaseLayer):
"""

def setup_data_load(self, portal, request):
login(portal.aq_parent, SITE_OWNER_NAME) # again
"""Provision site with demo data
"""
login(portal.aq_parent, SITE_OWNER_NAME)

setup_tool = api.get_tool("portal_setup")
curdir = os.path.dirname(__file__)
path = os.path.join(curdir, "setup_tool-demodata.tar.gz")

with open(path, "rb") as tarball:
context = TarballImportContext(
tool=setup_tool,
archive_bits=tarball.read(),
encoding="UTF-8",
should_purge=True)
setup_tool._doRunImportStep("senaite.core.import", context)

transaction.commit()

# load test data
request.form["setupexisting"] = 1
request.form["existing"] = "bika.lims:test"
lsd = LoadSetupData(portal, request)
lsd()
logout()

def setUpPloneSite(self, portal):
super(DataLayer, self).setUpPloneSite(portal)
# Install Demo Data
self.setup_data_load(portal, portal.REQUEST)
transaction.commit()


BASE_LAYER_FIXTURE = BaseLayer()
Expand Down
Binary file added src/senaite/core/tests/setup_tool-demodata.tar.gz
Binary file not shown.