Skip to content

Commit

Permalink
Added the QA validations and units tests #33
Browse files Browse the repository at this point in the history
  • Loading branch information
alfadestroyer committed Jul 23, 2023
1 parent f697fa4 commit 0a158d8
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 27 deletions.
1 change: 1 addition & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-c constraints.txt
-e src/slc_web
-e src/slc_web[test]

zope.testrunner
Expand Down
9 changes: 6 additions & 3 deletions backend/src/slc_web/setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Installer for the slc_web package."""

from pathlib import Path
from setuptools import find_packages
from setuptools import setup
Expand All @@ -9,13 +10,15 @@
{Path("CONTRIBUTORS.md").read_text()}\n
{Path("CHANGES.md").read_text()}\n
"""
source_url = "https://github.com/ScrumLATAMComunidad/scrumlatamcomunidad.com"


setup(
name="slc_web",
version="1.0.0a1",
description="SCRUM LATAM Comunidad Web portal configuration package.",
long_description=long_description,
# Get more from https://pypi.org/classifiers/
classifiers=[
"Environment :: Web Environment",
"Framework :: Plone",
Expand All @@ -32,11 +35,11 @@
keywords="Python Plone CMS",
author="Leonardo J. Caballero G.",
author_email="leonardoc@plone.org",
url="https://github.com/ScrumLATAMComunidad/scrumlatamcomunidad.com",
url=source_url,
project_urls={
"PyPI": "https://pypi.python.org/pypi/slc_web",
"Source": "https://github.com/ScrumLATAMComunidad/scrumlatamcomunidad.com",
"Tracker": "https://github.com/ScrumLATAMComunidad/slc-sitioweb/issues",
"Source": source_url,
"Tracker": f"{source_url}/issues",
},
license="GPL version 2",
packages=find_packages("src", exclude=["ez_setup"]),
Expand Down
2 changes: 2 additions & 0 deletions backend/src/slc_web/src/slc_web/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import logging


PACKAGE_NAME = "slc_web"

_ = MessageFactory("slc_web")

logger = logging.getLogger("slc_web")
8 changes: 7 additions & 1 deletion backend/src/slc_web/src/slc_web/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@


class ISLC_WEBLayer(IDefaultBrowserLayer):
"""Marker interface that defines a browser layer."""
"""Marker interface that defines a browser layer.
Args:
IDefaultBrowserLayer (class): The default layer
"""

pass
57 changes: 52 additions & 5 deletions backend/src/slc_web/src/slc_web/setuphandlers/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,54 @@


def delete_content(portal):
"""Delete default content."""
"""Delete default content.
Args:
portal (class): Plone portal object
"""
o_ids = [o_id for o_id in TO_DELETE if o_id in portal.objectIds()]
for o_id in o_ids:
api.content.delete(obj=portal[o_id])


def _get_image(image: str) -> NamedBlobImage:
"""Get Image path for load to ZODB as BLOB
Args:
image (str): Image path to load
Returns:
NamedBlobImage: An image stored in a ZODB BLOB with a filename
"""
filepath = os.path.join(__location__, f"{image}")
with open(filepath, "rb") as f_in:
data = f_in.read()
return NamedBlobImage(data)


def date_from_string(value: str) -> DateTime:
"""Convert DateTime from String value
Args:
value (str): DateTime as String
Returns:
DateTime: DateTime object
"""
return DateTime(parse(value))


def _create_content(portal, item: dict, creators: list):
"""Create a content."""
"""Create a content.
Args:
portal (class): Plone portal object
item (dict): dict item
creators (list): creators list
Returns:
class: return a content created
"""
container = portal.restrictedTraverse(item.get("_parent"))
o_id = item["id"]

Expand Down Expand Up @@ -76,7 +105,12 @@ def _create_content(portal, item: dict, creators: list):


def populate_portal(portal, creators):
"""Create content structure."""
"""Create content structure.
Args:
portal (class): Plone portal object
creators (list): creators list
"""
with open(os.path.join(__location__, "contents.json"), "r") as f_in:
contents = json.load(f_in)

Expand All @@ -91,14 +125,27 @@ def populate_portal(portal, creators):


def _update_home(portal, item: dict):
"""Update front page."""
"""Update front page.
Args:
portal (class): Plone portal object
item (dict): dict item
Returns:
class: Plone portal object
"""
for key, value in item.items():
setattr(portal, key, value)
return portal


def update_home(portal, creators):
"""Create content structure."""
"""Create content structure.
Args:
portal (class): Plone portal object
creators (list): creators list
"""
with open(os.path.join(__location__, "home.json"), "r") as f_in:
content = json.load(f_in)

Expand Down
15 changes: 13 additions & 2 deletions backend/src/slc_web/src/slc_web/setuphandlers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@


def _users_info() -> dict:
"""Return users info."""
"""Return users info.
Returns:
dict: Return users info as a dict
"""
with open(os.path.join(__location__, "users.json"), "r") as f_in:
users = json.load(f_in)
return users
Expand All @@ -26,7 +30,14 @@ def create_default_user():


def create_accounts(accounts: list) -> list:
"""Create user accounts."""
"""Create user accounts.
Args:
accounts (list): new users list
Returns:
list: user accounts list
"""
new_users = []
for user_info in accounts:
username = user_info.get("username", "")
Expand Down
23 changes: 19 additions & 4 deletions backend/src/slc_web/src/slc_web/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,34 @@


class SLC_WEBLayer(PloneSandboxLayer):
"""The Plone Sandbox Layer for slc_web package
Args:
PloneSandboxLayer (class): Plone Sandbox Layer class
"""

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.
"""Load any other ZCML that is required for your tests.
The z3c.autoinclude feature is disabled in the Plone fixture base layer.
Args:
app (class): Zope App Class
configurationContext (class): ZCML Context loaded
"""
import plone.restapi

self.loadZCML(package=plone.restapi)
self.loadZCML(package=slc_web)

def setUpPloneSite(self, portal):
"""To configure the actual Plone site, for example installing
the addon that we are going to test.
Args:
portal (class): Plone portal object
"""
applyProfile(portal, "slc_web:default")
applyProfile(portal, "slc_web:initial")

Expand All @@ -42,7 +57,7 @@ def setUpPloneSite(self, portal):
)


SLC_WEBACCEPTANCE_TESTING = FunctionalTesting(
SLC_WEB_ACCEPTANCE_TESTING = FunctionalTesting(
bases=(
SLC_WEB_FIXTURE,
REMOTE_LIBRARY_BUNDLE_FIXTURE,
Expand Down
28 changes: 28 additions & 0 deletions backend/src/slc_web/src/slc_web/tests/test_ct_community_sponsor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Content Types tests for this package."""
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.dexterity.interfaces import IDexterityFTI
from slc_web.testing import SLC_WEB_INTEGRATION_TESTING
from zope.component import queryUtility

import unittest


class ContentTypesTest(unittest.TestCase):
"""The Community Sponsor Content Type Test class
Args:
unittest (class): unittest TestCase
"""

layer = SLC_WEB_INTEGRATION_TESTING

def setUp(self):
"""Custom shared utility setup for tests."""
self.portal = self.layer["portal"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])

def test_fti_community_sponsor(self):
fti = queryUtility(IDexterityFTI, name="CommunitySponsor")
self.assertTrue(fti)
# self.assertNotEqual(None, fti)
21 changes: 16 additions & 5 deletions backend/src/slc_web/src/slc_web/tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from Products.CMFPlone.utils import get_installer
from slc_web import PACKAGE_NAME
from slc_web.testing import SLC_WEB_INTEGRATION_TESTING

import unittest


class TestSetup(unittest.TestCase):
"""Test that slc_web is properly installed."""
"""Test that slc_web is properly installed.
Args:
unittest (class): unittest TestCase
"""

layer = SLC_WEB_INTEGRATION_TESTING

Expand All @@ -21,7 +26,7 @@ def setUp(self):

def test_product_installed(self):
"""Test if slc_web is installed."""
self.assertTrue(self.installer.is_product_installed("slc_web"))
self.assertTrue(self.installer.is_product_installed(PACKAGE_NAME))

def test_browserlayer(self):
"""Test that ISLC_WEBLayer is registered."""
Expand All @@ -33,26 +38,32 @@ def test_browserlayer(self):
def test_latest_version(self):
"""Test latest version of default profile."""
self.assertEqual(
self.setup.getLastVersionForProfile("slc_web:default")[0],
self.setup.getLastVersionForProfile(f"{PACKAGE_NAME}:default")[0],
"20230511001",
)


class TestUninstall(unittest.TestCase):
"""Test that slc_web is properly uninstalled.
Args:
unittest (class): unittest TestCase
"""

layer = SLC_WEB_INTEGRATION_TESTING

def setUp(self):
"""Custom shared utility setup for tests."""
self.portal = self.layer["portal"]
self.installer = get_installer(self.portal, self.layer["request"])
roles_before = api.user.get_roles(TEST_USER_ID)
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.installer.uninstall_product("slc_web")
self.installer.uninstall_product(PACKAGE_NAME)
setRoles(self.portal, TEST_USER_ID, roles_before)

def test_product_uninstalled(self):
"""Test if slc_web is cleanly uninstalled."""
self.assertFalse(self.installer.is_product_installed("slc_web"))
self.assertFalse(self.installer.is_product_installed(PACKAGE_NAME))

def test_browserlayer_removed(self):
"""Test that ISLC_WEBLayer is removed."""
Expand Down
9 changes: 6 additions & 3 deletions backend/src/slc_web/src/slc_web/tests/test_upgrades.py_tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
from parameterized import parameterized
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from slc_web.testing import SLC_WEB_INTEGRATION_TESTING # noqa: E501
from Products.GenericSetup.upgrade import listUpgradeSteps
from slc_web import PACKAGE_NAME
from slc_web.testing import SLC_WEB_INTEGRATION_TESTING # noqa: E501

import unittest


class UpgradeStepIntegrationTest(unittest.TestCase):

layer = SLC_WEB_INTEGRATION_TESTING
profile = "slc_web:default"
profile = f"{PACKAGE_NAME}:default"

def setUp(self):
"""Custom shared utility setup for tests."""
self.portal = self.layer["portal"]
self.setup = self.portal["portal_setup"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])
Expand All @@ -28,10 +30,11 @@ class UpgradeStepIntegrationTest(unittest.TestCase):
steps = [s for s in steps if self._match(s[0], self.src, self.dst)]
return steps

# Example of upgrade step test
# Upgrade steps test
@parameterized.expand(
[
("20230511001", "20230229001", 1),
("20230229001", "20230726001", 1),
]
)
def test_available(self, src, dst, expected):
Expand Down
8 changes: 4 additions & 4 deletions backend/src/slc_web/src/slc_web/upgrades/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@


def upgrade_plone(context):
"""_Upgrade Plone to latest version._
"""Upgrade Plone to latest version.
Args:
context (object): _context object_
context (object): context object
"""
mt = api.portal.get_tool("portal_migration")
if mt.needUpgrading():
Expand All @@ -15,10 +15,10 @@ def upgrade_plone(context):


def upgrade_pas_plugins_authomatic(portal_setup):
"""_Upgrade pas.plugins.authomatic to latest version._
"""Upgrade pas.plugins.authomatic to latest version.
Args:
portal_setup (object): _portal_setup object_
portal_setup (object): portal_setup object
"""
portal_setup.upgradeProfile("profile-pas.plugins.authomatic:default")
logger.info("Upgraded pas.plugins.authomatic")

0 comments on commit 0a158d8

Please sign in to comment.