Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boulch committed May 20, 2021
1 parent fc1f5d0 commit aabc3f9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 11 deletions.
23 changes: 13 additions & 10 deletions src/imio/directory/core/tests/test_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ def setUp(self):
self.request = self.layer["request"]
self.portal = self.layer["portal"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.entity = api.content.create(
container=self.portal,
type="imio.directory.Entity",
title="Entity",
)

def test_ct_contact_schema(self):
fti = queryUtility(IDexterityFTI, name="imio.directory.Contact")
Expand All @@ -55,7 +60,7 @@ def test_ct_contact_factory(self):
def test_ct_contact_adding(self):
setRoles(self.portal, TEST_USER_ID, ["Contributor"])
contact = api.content.create(
container=self.portal,
container=self.entity,
type="imio.directory.Contact",
title="contact",
)
Expand All @@ -73,17 +78,15 @@ def test_ct_contact_adding(self):
api.content.delete(obj=contact)
self.assertNotIn("contact", parent.objectIds())

def test_ct_contact_globally_addable(self):
def test_ct_contact_not_globally_addable(self):
setRoles(self.portal, TEST_USER_ID, ["Contributor"])
fti = queryUtility(IDexterityFTI, name="imio.directory.Contact")
self.assertTrue(
fti.global_allow, u"{0} is not globally addable!".format(fti.id)
)
self.assertFalse(fti.global_allow, u"{0} is globally addable!".format(fti.id))

def test_ct_contact_filter_content_type_true(self):
def test_ct_contact_filter_content_type(self):
setRoles(self.portal, TEST_USER_ID, ["Contributor"])
contact = api.content.create(
container=self.portal,
container=self.entity,
type="imio.directory.Contact",
title="contact",
)
Expand Down Expand Up @@ -116,7 +119,7 @@ def test_phone_constraint(self):

def test_name_chooser(self):
contact = api.content.create(
container=self.portal,
container=self.entity,
type="imio.directory.Contact",
title="contact",
)
Expand All @@ -132,7 +135,7 @@ def test_name_chooser(self):

def test_gallery_in_contact_view(self):
contact = api.content.create(
container=self.portal,
container=self.entity,
type="imio.directory.Contact",
title="contact",
)
Expand All @@ -148,7 +151,7 @@ def test_gallery_in_contact_view(self):

def test_files_in_contact_view(self):
contact = api.content.create(
container=self.portal,
container=self.entity,
type="imio.directory.Contact",
title="contact",
)
Expand Down
68 changes: 68 additions & 0 deletions src/imio/directory/core/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-

from bs4 import BeautifulSoup
from imio.directory.core.testing import IMIO_DIRECTORY_CORE_FUNCTIONAL_TESTING
from plone import api
from plone.app.testing import setRoles
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.testing.z2 import Browser
import transaction
import unittest


class FormsFunctionalTest(unittest.TestCase):

layer = IMIO_DIRECTORY_CORE_FUNCTIONAL_TESTING

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

def test_leadimage_caption_field(self):
entity = api.content.create(
container=self.portal,
type="imio.directory.Entity",
title="Entity",
)
self.check_leadimage_caption_field(entity, container=self.portal)
contact = api.content.create(
container=entity,
type="imio.directory.Contact",
title="Contact",
)
self.check_leadimage_caption_field(contact, container=entity)

def check_leadimage_caption_field(self, obj, container):
transaction.commit()
browser = Browser(self.layer["app"])
browser.addHeader(
"Authorization",
"Basic %s:%s"
% (
TEST_USER_NAME,
TEST_USER_PASSWORD,
),
)
browser.open("{}/edit".format(obj.absolute_url()))
content = browser.contents
soup = BeautifulSoup(content)
lead_image_caption_widget = soup.find(
id="form-widgets-ILeadImageBehavior-image_caption"
)
self.assertIsNotNone(lead_image_caption_widget)
self.assertEqual(len(lead_image_caption_widget), 0)
self.assertEqual(lead_image_caption_widget["type"], "hidden")

browser.open("{}/++add++{}".format(container.absolute_url(), obj.portal_type))
content = browser.contents
soup = BeautifulSoup(content)
lead_image_caption_widget = soup.find(
id="form-widgets-ILeadImageBehavior-image_caption"
)
self.assertIsNotNone(lead_image_caption_widget)
self.assertEqual(len(lead_image_caption_widget), 0)
self.assertEqual(lead_image_caption_widget["type"], "hidden")
11 changes: 10 additions & 1 deletion src/imio/directory/core/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ def setUp(self):
self.request = self.layer["request"]
self.portal = self.layer["portal"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])
self.entity = api.content.create(
container=self.portal,
type="imio.directory.Entity",
title="Entity",
)

def test_export_to_vcard(self):
contact = api.content.create(
container=self.portal,
container=self.entity,
type="imio.directory.Contact",
title="contact",
)
Expand Down Expand Up @@ -62,3 +67,7 @@ def test_export_to_vcard(self):
view = getMultiAdapter((self.portal, self.request), name="utils")
self.assertFalse(view.can_export_contact_to_vcard())
self.assertIsNone(view.export_contact_to_vcard())

view = getMultiAdapter((self.entity, self.request), name="utils")
self.assertFalse(view.can_export_contact_to_vcard())
self.assertIsNone(view.export_contact_to_vcard())

0 comments on commit aabc3f9

Please sign in to comment.