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

Compatibility with core#2471 and core#2567 #37

Merged
merged 10 commits into from
Jun 16, 2024
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
30 changes: 30 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: build and test senaite.ast
on:
- push
- pull_request
env:
PLONE_VERSION: "5.2"
jobs:
build-and-test:
runs-on: 'ubuntu-20.04'
container:
image: python:2.7.18-buster
steps:
- uses: actions/checkout@v3
- name: cache eggs
uses: actions/cache@v3
with:
key: eggs-cache-${{ hashFiles('buildout.cfg', 'requirements.txt') }}
path: |
eggs/
- name: install
run: |
pip install virtualenv
virtualenv -p `which python` .
bin/pip install --upgrade pip
bin/pip install -r requirements.txt
bin/buildout -N -t 3 annotate
bin/buildout -N -t 3
- name: test
run: |
bin/test -s senaite.ast.tests
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Antibiotic Sensitivity Testing (AST) for SENAITE
.. image:: https://img.shields.io/pypi/v/senaite.ast.svg?style=flat-square
:target: https://pypi.python.org/pypi/senaite.ast

.. image:: https://img.shields.io/travis/com/senaite/senaite.ast/master.svg?style=flat-square
:target: https://app.travis-ci.com/github/senaite/senaite.ast
.. image:: https://img.shields.io/github/actions/workflow/status/senaite/senaite.ast/build-and-test.yml?branch=2.x
:target: https://github.com/senaite/senaite.ast/actions/workflows/build-and-test.yml?query=branch:2.x

.. image:: https://readthedocs.org/projects/pip/badge/
:target: https://senaiteast.readthedocs.org
Expand Down
100 changes: 1 addition & 99 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,105 +1,7 @@
[buildout]
index = https://pypi.org/simple/
extends = https://dist.plone.org/release/5.2-latest/versions.cfg
find-links =
https://dist.plone.org/release/5.2-latest/
https://dist.plone.org/thirdparty/

parts =
instance
test
omelette
i18ndude
zopepy
update_translations
write_code_headers

eggs =
senaite.core
senaite.app.listing
senaite.app.spotlight
senaite.app.supermodel
senaite.impress
senaite.jsonapi
senaite.lims
senaite.abx
senaite.microorganism
senaite.ast
plone.reload
Products.PrintingMailHost

extensions = mr.developer

extends = https://raw.githubusercontent.com/senaite/senaite.core/2.x/buildout.base.cfg
package-name = senaite.ast

versions = versions
show-picked-versions = true

plone-user = admin:admin

develop = .
sources = sources
auto-checkout = *

[sources]
senaite.core = git https://github.com/senaite/senaite.core.git branch=2.x
senaite.app.listing = git https://github.com/senaite/senaite.app.listing.git branch=2.x
senaite.app.spotlight = git https://github.com/senaite/senaite.app.spotlight.git branch=2.x
senaite.app.supermodel = git https://github.com/senaite/senaite.app.supermodel.git branch=2.x
senaite.impress = git https://github.com/senaite/senaite.impress.git branch=2.x
senaite.jsonapi = git https://github.com/senaite/senaite.jsonapi.git branch=2.x
senaite.lims = git https://github.com/senaite/senaite.lims.git branch=2.x
senaite.abx = git https://github.com/senaite/senaite.abx.git
senaite.microorganism = git https://github.com/senaite/senaite.microorganism.git

[instance]
recipe = plone.recipe.zope2instance
http-address = 127.0.0.1:8080
user = ${buildout:plone-user}
wsgi = on
eggs =
Plone
plone.app.upgrade
${buildout:package-name}
${buildout:eggs}
deprecation-warnings = on
environment-vars =
zope_i18n_compile_mo_files true
zcml =

[i18ndude]
unzip = true
recipe = zc.recipe.egg
eggs = i18ndude

[update_translations]
recipe = collective.recipe.template
output = ${buildout:directory}/bin/update_translations
input = ${buildout:directory}/templates/update_translations.in
mode = 755

[write_code_headers]
recipe = collective.recipe.template
output = ${buildout:directory}/bin/write_code_headers
input = ${buildout:directory}/templates/write_code_headers.py.in
mode = 755

[test]
recipe = zc.recipe.testrunner
defaults = ['--auto-color', '--auto-progress']
eggs =
senaite.ast [test]

[omelette]
recipe = collective.recipe.omelette
eggs = ${buildout:eggs}

[zopepy]
recipe = zc.recipe.egg
eggs = ${instance:eggs}
interpreter = zopepy
scripts = zopepy

[versions]
setuptools =
zc.buildout =
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
1.2.0 (unreleased)
------------------

- #37 Compatibility with core#2567 (AnalysisCategory to DX)
- #37 Compatibility with core#2471 (Department to DX)
- #36 Fix user can edit ast built-in services after upgrades
- #35 Compatibility with core#2521 - AT2DX ARTemplate/SampleTemplate
- #34 Add transition "Reject antibiotics"
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
setuptools==42.0.2
setuptools==44.1.1
zc.buildout==2.13.3
wheel
17 changes: 9 additions & 8 deletions src/senaite/ast/setuphandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ def setup_ast_category(portal):
"""
name = SERVICE_CATEGORY
logger.info("Setup category '{}' ...".format(name))
folder = api.get_setup().bika_analysiscategories
exists = filter(lambda c: api.get_title(c) == name, folder.objectValues())
if exists:
setup = api.get_senaite_setup()
folder = setup.analysiscategories
categories = search_by_title(folder, name)
if categories:
logger.info("Category '{}' exists already [SKIP]".format(name))
return

Expand Down Expand Up @@ -199,15 +200,15 @@ def setup_ast_services(portal, update_existing=True):
selective reporting
"""
logger.info("Setup AST services ...")

# Get the category to apply to all AST services
cats_folder = api.get_senaite_setup().analysiscategories
category = search_by_title(cats_folder, SERVICE_CATEGORY)[0]

setup = api.get_setup()
for key, settings in SERVICES_SETTINGS.items():
logger.info("Setup template service '{}' ...".format(key))

# Get the category
cat_name = SERVICE_CATEGORY
categories = setup.bika_analysiscategories.objectValues()
category = filter(lambda c: api.get_title(c) == cat_name, categories)[0]

title = settings["title"]
if "{}" in title:
title = title.format(_("Antibiotic Sensitivity"))
Expand Down
64 changes: 39 additions & 25 deletions src/senaite/ast/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,45 @@
# Copyright 2020-2024 by it's authors.
# Some rights reserved, see README and LICENSE.

from plone.app.testing import TEST_USER_ID
from plone.app.testing import setRoles
from plone.app.testing.bbb_at import PloneTestCase
from plone.protect.authenticator import createToken
from senaite.ast.tests.layers import BASE_TESTING
import transaction
from plone.app.testing import applyProfile
from plone.app.testing import FunctionalTesting
from plone.testing import zope
from senaite.core.tests.base import BaseTestCase
from senaite.core.tests.layers import BaseLayer


class BaseTestCase(PloneTestCase):
"""Use for test cases which do not rely on the demo data
class SimpleTestLayer(BaseLayer):

def setUpZope(self, app, configurationContext):
super(SimpleTestLayer, self).setUpZope(app, configurationContext)

# Load ZCML
import senaite.abx
import senaite.microorganism
self.loadZCML(package=senaite.abx)
self.loadZCML(package=senaite.microorganism)
self.loadZCML(package=senaite.ast)

# Install product and call its initialize() function
zope.installProduct(app, "senaite.abx")
zope.installProduct(app, "senaite.microorganism")
zope.installProduct(app, "senaite.ast")

def setUpPloneSite(self, portal):
super(SimpleTestLayer, self).setUpPloneSite(portal)
applyProfile(portal, "senaite.ast:default")
transaction.commit()


SIMPLE_TEST_LAYER_FIXTURE = SimpleTestLayer()
SIMPLE_TESTING = FunctionalTesting(
bases=(SIMPLE_TEST_LAYER_FIXTURE, ),
name="senaite.ast:SimpleTesting"
)


class SimpleTestCase(BaseTestCase):
"""Use for test cases which do not rely on demo data
"""
layer = BASE_TESTING

def setUp(self):
super(BaseTestCase, self).setUp()
# Fixing CSRF protection
# https://github.com/plone/plone.protect/#fixing-csrf-protection-failures-in-tests
self.request = self.layer["request"]
# Disable plone.protect for these tests
self.request.form["_authenticator"] = createToken()
# Eventuelly you find this also useful
self.request.environ["REQUEST_METHOD"] = "POST"

setRoles(self.portal, TEST_USER_ID, ["LabManager", "Manager"])

# Default skin is set to "Sunburst Theme"!
# => This causes an `AttributeError` when we want to access
# e.g. 'guard_handler' FSPythonScript
self.portal.changeSkin("Plone Default")
layer = SIMPLE_TESTING
4 changes: 2 additions & 2 deletions src/senaite/ast/tests/doctests/AST.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ We need to create some basic objects for the test:
>>> contact = api.create(client, "Contact", Firstname="Rita", Lastname="Mohale")
>>> sampletype = api.create(setup.bika_sampletypes, "SampleType", title="Blood", Prefix="B")
>>> labcontact = api.create(setup.bika_labcontacts, "LabContact", Firstname="Lab", Lastname="Manager")
>>> department = api.create(setup.bika_departments, "Department", title="Microbiology", Manager=labcontact)
>>> category = api.create(setup.bika_analysiscategories, "AnalysisCategory", title="Microbiology", Department=department)
>>> department = api.create(portal.setup.departments, "Department", title="Microbiology", Manager=labcontact)
>>> category = api.create(portal.setup.analysiscategories, "AnalysisCategory", title="Microbiology", Department=department)
>>> g = api.create(setup.bika_analysisservices, "AnalysisService", title="GRAM Test", Keyword="G", Price="15", Category=category.UID(), Accredited=True)


Expand Down
75 changes: 0 additions & 75 deletions src/senaite/ast/tests/layers.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/senaite/ast/tests/test_doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import unittest2 as unittest
from senaite.ast import PRODUCT_NAME
from senaite.ast.tests.base import BaseTestCase
from senaite.ast.tests.base import SimpleTestCase
from Testing import ZopeTestCase as ztc

# Option flags for doctests
Expand All @@ -38,7 +38,7 @@ def test_suite():
suite.addTests([
ztc.ZopeDocFileSuite(
doctestfile,
test_class=BaseTestCase,
test_class=SimpleTestCase,
optionflags=flags
)
])
Expand Down
Loading
Loading