Commit 9071da4e authored by Grégory Wisniewski's avatar Grégory Wisniewski

Remove duplicate and useless getNewUUID() definitions in test cases and inherit

from NeoTestBase.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@1179 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 16a02de6
...@@ -49,14 +49,6 @@ DB_ADMIN = 'root' ...@@ -49,14 +49,6 @@ DB_ADMIN = 'root'
DB_PASSWD = None DB_PASSWD = None
DB_USER = 'test' DB_USER = 'test'
def getNewUUID():
""" Return a valid UUID """
uuid = protocol.INVALID_UUID
while uuid == protocol.INVALID_UUID:
uuid = os.urandom(16)
self.uuid = uuid
return uuid
class NeoTestBase(unittest.TestCase): class NeoTestBase(unittest.TestCase):
""" Base class for neo tests, implements common checks """ """ Base class for neo tests, implements common checks """
...@@ -116,7 +108,12 @@ class NeoTestBase(unittest.TestCase): ...@@ -116,7 +108,12 @@ class NeoTestBase(unittest.TestCase):
# XXX: according to changes with namespaced UUIDs, it would be better to # XXX: according to changes with namespaced UUIDs, it would be better to
# implement get<NodeType>UUID() methods # implement get<NodeType>UUID() methods
def getNewUUID(self): def getNewUUID(self):
return getNewUUID() """ Return a valid UUID """
uuid = protocol.INVALID_UUID
while uuid == protocol.INVALID_UUID:
uuid = os.urandom(16)
self.uuid = uuid
return uuid
def getTwoIDs(self): def getTwoIDs(self):
""" Return a tuple of two sorted UUIDs """ """ Return a tuple of two sorted UUIDs """
...@@ -333,20 +330,6 @@ class NeoTestBase(unittest.TestCase): ...@@ -333,20 +330,6 @@ class NeoTestBase(unittest.TestCase):
connector_cpt = 0 connector_cpt = 0
# XXX This function is specific to a primary master test, I think.
# It should not be here (as it shadows a more generic getNewUUID above).
# master node with the highest uuid will be declared as PMN
previous_uuid = None
def getNewUUID():
global previous_uuid
uuid = protocol.INVALID_UUID
while uuid == protocol.INVALID_UUID or (previous_uuid is \
not None and uuid > previous_uuid):
uuid = os.urandom(16)
logging.info("previous_uuid > uuid %s"%(previous_uuid > uuid))
previous_uuid = uuid
return uuid
class DoNothingConnector(Mock): class DoNothingConnector(Mock):
def __init__(self, s=None): def __init__(self, s=None):
logging.info("initializing connector") logging.info("initializing connector")
......
...@@ -162,17 +162,6 @@ class MasterServerElectionTests(NeoTestBase): ...@@ -162,17 +162,6 @@ class MasterServerElectionTests(NeoTestBase):
ClientConnection._addPacket = self._addPacket ClientConnection._addPacket = self._addPacket
ClientConnection.expectMessage = self.expectMessage ClientConnection.expectMessage = self.expectMessage
# Common methods
def getNewUUID(self):
uuid = INVALID_UUID
while uuid == INVALID_UUID:
uuid = os.urandom(16)
self.uuid = uuid
return uuid
def getLastUUID(self):
return self.uuid
def identifyToMasterNode(self, node_type=STORAGE_NODE_TYPE, ip="127.0.0.1", def identifyToMasterNode(self, node_type=STORAGE_NODE_TYPE, ip="127.0.0.1",
port=10021): port=10021):
"""Do first step of identification to MN """Do first step of identification to MN
......
...@@ -38,13 +38,6 @@ class StorageAppTests(NeoTestBase): ...@@ -38,13 +38,6 @@ class StorageAppTests(NeoTestBase):
def tearDown(self): def tearDown(self):
NeoTestBase.tearDown(self) NeoTestBase.tearDown(self)
def getNewUUID(self):
uuid = INVALID_UUID
while uuid == INVALID_UUID:
uuid = os.urandom(16)
self.uuid = uuid
return uuid
def test_01_loadPartitionTable(self): def test_01_loadPartitionTable(self):
self.assertEqual(len(self.app.dm.getPartitionTable()), 0) self.assertEqual(len(self.app.dm.getPartitionTable()), 0)
self.assertEqual(self.app.pt, None) self.assertEqual(self.app.pt, None)
......
...@@ -20,23 +20,17 @@ from mock import Mock ...@@ -20,23 +20,17 @@ from mock import Mock
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \ from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, INVALID_UUID MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, INVALID_UUID
from neo.config import ConfigurationManager from neo.config import ConfigurationManager
from neo.tests import NeoTestBase
from tempfile import mkstemp from tempfile import mkstemp
class ConfigurationManagerTests(unittest.TestCase): class ConfigurationManagerTests(NeoTestBase):
def setUp(self): def setUp(self):
pass pass
def tearDown(self): def tearDown(self):
pass pass
def getNewUUID(self):
uuid = INVALID_UUID
while uuid == INVALID_UUID:
uuid = os.urandom(16)
self.uuid = uuid
return uuid
def test_01_configuration_manager(self): def test_01_configuration_manager(self):
# initialisation # initialisation
#create a fake configuration file #create a fake configuration file
......
...@@ -31,14 +31,9 @@ from neo.connector import ConnectorException, ConnectorTryAgainException, \ ...@@ -31,14 +31,9 @@ from neo.connector import ConnectorException, ConnectorTryAgainException, \
from neo.protocol import Packet, ProtocolError, PROTOCOL_ERROR_CODE, ERROR,INTERNAL_ERROR_CODE, \ from neo.protocol import Packet, ProtocolError, PROTOCOL_ERROR_CODE, ERROR,INTERNAL_ERROR_CODE, \
ANSWER_PRIMARY_MASTER ANSWER_PRIMARY_MASTER
from neo import protocol from neo import protocol
from neo.tests import NeoTestBase
def getNewUUID(): class ConnectionTests(NeoTestBase):
uuid = INVALID_UUID
while uuid == INVALID_UUID:
uuid = os.urandom(16)
return uuid
class ConnectionTests(unittest.TestCase):
def setUp(self): def setUp(self):
pass pass
......
...@@ -20,22 +20,17 @@ from mock import Mock ...@@ -20,22 +20,17 @@ from mock import Mock
from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \ from neo.protocol import RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, BROKEN_STATE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, INVALID_UUID MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, INVALID_UUID
from neo.node import Node, MasterNode, StorageNode, ClientNode, NodeManager from neo.node import Node, MasterNode, StorageNode, ClientNode, NodeManager
from neo.tests import NeoTestBase
from time import time from time import time
class NodesTests(unittest.TestCase): class NodesTests(NeoTestBase):
def setUp(self): def setUp(self):
pass pass
def tearDown(self): def tearDown(self):
pass pass
def getNewUUID(self):
uuid = INVALID_UUID
while uuid == INVALID_UUID:
uuid = os.urandom(16)
self.uuid = uuid
return uuid
def test_01_node(self): def test_01_node(self):
# initialisation # initialisation
server = ("127.0.0.1", 10000) server = ("127.0.0.1", 10000)
......
...@@ -19,9 +19,10 @@ import unittest, os ...@@ -19,9 +19,10 @@ import unittest, os
from mock import Mock from mock import Mock
from neo import protocol from neo import protocol
from neo.protocol import * from neo.protocol import *
from neo.tests import NeoTestBase
from time import time, gmtime from time import time, gmtime
class ProtocolTests(unittest.TestCase): class ProtocolTests(NeoTestBase):
def setUp(self): def setUp(self):
self.ltid = INVALID_TID self.ltid = INVALID_TID
...@@ -53,13 +54,6 @@ class ProtocolTests(unittest.TestCase): ...@@ -53,13 +54,6 @@ class ProtocolTests(unittest.TestCase):
self.ltid = tid self.ltid = tid
return tid return tid
def getNewUUID(self):
uuid = INVALID_UUID
while uuid == INVALID_UUID:
uuid = os.urandom(16)
self.uuid = uuid
return uuid
def test_01_Packet_init(self): def test_01_Packet_init(self):
p = Packet(msg_type=ASK_PRIMARY_MASTER, body=None) p = Packet(msg_type=ASK_PRIMARY_MASTER, body=None)
self.assertEqual(p.getType(), ASK_PRIMARY_MASTER) self.assertEqual(p.getType(), ASK_PRIMARY_MASTER)
......
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