Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Commit

Permalink
Notifing a site is created + multiple connections on testing
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodbare committed Nov 19, 2016
1 parent ae261f9 commit 1be5cf7
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/plone.server/plone/server/api/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from plone.server.content import createContent
from plone.server.json.interfaces import IResourceSerializeToJson
from zope.component import getMultiAdapter
from zope.lifecycleevent import ObjectAddedEvent
from zope.event import notify


class DefaultGET(Service):
Expand Down Expand Up @@ -61,6 +63,8 @@ async def __call__(self):

site.install()

notify(ObjectAddedEvent(site, self.context, data['id']))

resp = {
'@type': 'Site',
'id': data['id'],
Expand Down
17 changes: 10 additions & 7 deletions src/plone.server/plone/server/catalog/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,21 @@ def add_object(obj, event):
if uid is None:
return
search = queryUtility(ICatalogUtility)
hook.index[uid] = search.get_data(obj)
if search is not None:
hook.index[uid] = search.get_data(obj)


def add_index(obj, event):
search = queryUtility(ICatalogUtility)
loop = asyncio.new_event_loop()
asyncio.run_coroutine_threadsafe(
search.create_index(obj.id), loop)
if search is not None:
loop = asyncio.new_event_loop()
asyncio.run_coroutine_threadsafe(
search.create_index(obj.id), loop)


def remove_index(obj, event):
search = queryUtility(ICatalogUtility)
loop = asyncio.new_event_loop()
asyncio.run_coroutine_threadsafe(
search.remove_index(obj.id), loop)
if search is not None:
loop = asyncio.new_event_loop()
asyncio.run_coroutine_threadsafe(
search.remove_index(obj.id), loop)
3 changes: 3 additions & 0 deletions src/plone.server/plone/server/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def __setattr__(self, name, value):
@implementer(IRegistry)
class Registry(Persistent):

__name__ = '_registry'
portal_type = 'Registry'

def __init__(self):
self._Registry__data = OOBTree()
self.__len = Length()
Expand Down
9 changes: 9 additions & 0 deletions src/plone.server/plone/server/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,13 @@ def testSetUp(cls):
}))
assert resp.status_code in (200, 401) # 401 is if site already exists...
cls.portal = cls.app['plone']['plone']
cls.active_connections = []

@classmethod
def testTearDown(cls):
# Restore the copy of the DB
for conn in cls.active_connections:
conn.close()
try:
resp = cls.requester('DELETE', '/plone/plone/')
except requests.exceptions.ConnectionError:
Expand All @@ -229,6 +232,12 @@ def testTearDown(cls):
# mock = MockView(cls.app['plone'], restore_connection, restore)
# mock()

@classmethod
def new_root(cls):
conn = cls.app._dbs['plone'].open()
cls.active_connections.append(conn)
return conn.root()


class PloneServerBaseTestCase(unittest.TestCase):
""" Only the app created """
Expand Down
3 changes: 2 additions & 1 deletion src/plone.server/plone/server/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def _get_site(self):
sometimes the site does not get updated data from zodb
this seems to make it
"""
return self.layer.app._dbs['plone']['plone']
return self.layer.new_root()['plone']

def test_get_root(self):
"""Get the application root."""
Expand Down Expand Up @@ -153,6 +153,7 @@ def test_file_upload(self):
'PATCH',
'/plone/plone/file1/@upload/file',
data=data)
site = self._get_site()
behavior = IAttachment(site['file1'])
self.assertEqual(behavior.file.data, data)

Expand Down

0 comments on commit 1be5cf7

Please sign in to comment.