Commit 10e3542e authored by Grégory Wisniewski's avatar Grégory Wisniewski

Fix test with decorators imports.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@674 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent a26e93f6
...@@ -19,12 +19,11 @@ import unittest, os ...@@ -19,12 +19,11 @@ import unittest, os
from mock import Mock, ReturnValues from mock import Mock, ReturnValues
from neo.tests.base import NeoTestBase from neo.tests.base import NeoTestBase
from neo.handler import EventHandler from neo.handler import EventHandler
from neo.handler import identification_required, restrict_node_types, \
client_connection_required, server_connection_required
from neo.protocol import UnexpectedPacketError, MASTER_NODE_TYPE, \ from neo.protocol import UnexpectedPacketError, MASTER_NODE_TYPE, \
CLIENT_NODE_TYPE, STORAGE_NODE_TYPE, ADMIN_NODE_TYPE CLIENT_NODE_TYPE, STORAGE_NODE_TYPE, ADMIN_NODE_TYPE
from neo.protocol import PacketMalformedError, UnexpectedPacketError, \ from neo.protocol import PacketMalformedError, UnexpectedPacketError, \
BrokenNodeDisallowedError, NotReadyError, ProtocolError BrokenNodeDisallowedError, NotReadyError, ProtocolError
from neo import decorators
class HandlerDecoratorsTests(NeoTestBase): class HandlerDecoratorsTests(NeoTestBase):
...@@ -49,7 +48,7 @@ class HandlerDecoratorsTests(NeoTestBase): ...@@ -49,7 +48,7 @@ class HandlerDecoratorsTests(NeoTestBase):
def test_identification_required(self): def test_identification_required(self):
packet = Mock({}) packet = Mock({})
handler = Mock({}) handler = Mock({})
wrapped = identification_required(handler) wrapped = decorators.identification_required(handler)
# no UUID -> fail # no UUID -> fail
conn = Mock({ 'getUUID': None, }) conn = Mock({ 'getUUID': None, })
self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet) self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet)
...@@ -69,17 +68,17 @@ class HandlerDecoratorsTests(NeoTestBase): ...@@ -69,17 +68,17 @@ class HandlerDecoratorsTests(NeoTestBase):
admin = Mock({'getNodeType': ADMIN_NODE_TYPE}) admin = Mock({'getNodeType': ADMIN_NODE_TYPE})
nodes = (storage, master, client, admin) nodes = (storage, master, client, admin)
# no uuid -> fail # no uuid -> fail
wrapped = restrict_node_types()(handler) wrapped = decorators.restrict_node_types()(handler)
conn = Mock({ 'getUUID': None, }) conn = Mock({ 'getUUID': None, })
self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet) self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet)
self.checkHandlerNotCalled(handler) self.checkHandlerNotCalled(handler)
# unknown node -> fail # unknown node -> fail
wrapped = restrict_node_types()(handler) wrapped = decorators.restrict_node_types()(handler)
self.app.nm = Mock({'getNodeByUUID': uuid, }) self.app.nm = Mock({'getNodeByUUID': uuid, })
self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet) self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet)
self.checkHandlerNotCalled(handler) self.checkHandlerNotCalled(handler)
# no node allowed at all -> all fail # no node allowed at all -> all fail
wrapped = restrict_node_types()(handler) wrapped = decorators.restrict_node_types()(handler)
conn = Mock({ 'getUUID': uuid, }) conn = Mock({ 'getUUID': uuid, })
self.app.nm = Mock({'getNodeByUUID': ReturnValues(*nodes)}) self.app.nm = Mock({'getNodeByUUID': ReturnValues(*nodes)})
self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet) self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet)
...@@ -88,7 +87,7 @@ class HandlerDecoratorsTests(NeoTestBase): ...@@ -88,7 +87,7 @@ class HandlerDecoratorsTests(NeoTestBase):
self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet) self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet)
# Only master nodes allowed # Only master nodes allowed
handler = Mock() handler = Mock()
wrapped = restrict_node_types(MASTER_NODE_TYPE)(handler) wrapped = decorators.restrict_node_types(MASTER_NODE_TYPE)(handler)
conn = Mock({ 'getUUID': uuid, }) conn = Mock({ 'getUUID': uuid, })
self.app.nm = Mock({'getNodeByUUID': ReturnValues(*nodes)}) self.app.nm = Mock({'getNodeByUUID': ReturnValues(*nodes)})
self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet) self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet)
...@@ -100,7 +99,7 @@ class HandlerDecoratorsTests(NeoTestBase): ...@@ -100,7 +99,7 @@ class HandlerDecoratorsTests(NeoTestBase):
self.checkHandlerCalled(handler) # fail if re-called self.checkHandlerCalled(handler) # fail if re-called
# storage or client nodes # storage or client nodes
handler = Mock() handler = Mock()
wrapped = restrict_node_types(STORAGE_NODE_TYPE, CLIENT_NODE_TYPE)(handler) wrapped = decorators.restrict_node_types(STORAGE_NODE_TYPE, CLIENT_NODE_TYPE)(handler)
conn = Mock({ 'getUUID': uuid, }) conn = Mock({ 'getUUID': uuid, })
self.app.nm = Mock({'getNodeByUUID': ReturnValues(*nodes)}) self.app.nm = Mock({'getNodeByUUID': ReturnValues(*nodes)})
wrapped(self, conn, packet) # storage wrapped(self, conn, packet) # storage
...@@ -117,7 +116,7 @@ class HandlerDecoratorsTests(NeoTestBase): ...@@ -117,7 +116,7 @@ class HandlerDecoratorsTests(NeoTestBase):
def test_client_connection_required(self): def test_client_connection_required(self):
packet = Mock({}) packet = Mock({})
handler = Mock({}) handler = Mock({})
wrapped = client_connection_required(handler) wrapped = decorators.client_connection_required(handler)
# server connection -> fail # server connection -> fail
conn = Mock({ 'isServerConnection': True, }) conn = Mock({ 'isServerConnection': True, })
self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet) self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet)
...@@ -130,7 +129,7 @@ class HandlerDecoratorsTests(NeoTestBase): ...@@ -130,7 +129,7 @@ class HandlerDecoratorsTests(NeoTestBase):
def test_server_connection_required(self): def test_server_connection_required(self):
packet = Mock({}) packet = Mock({})
handler = Mock({}) handler = Mock({})
wrapped = server_connection_required(handler) wrapped = decorators.server_connection_required(handler)
# client connection -> fail # client connection -> fail
conn = Mock({ 'isServerConnection': False, }) conn = Mock({ 'isServerConnection': False, })
self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet) self.assertRaises(UnexpectedPacketError, wrapped, self, conn, packet)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment