diff --git a/.project b/.project
index e77d3ba..4d3d9e8 100644
--- a/.project
+++ b/.project
@@ -1,17 +1,17 @@
-
-
- python.channelfinder.api
-
-
-
-
-
- org.python.pydev.PyDevBuilder
-
-
-
-
-
- org.python.pydev.pythonNature
-
-
+
+
+ python.channelfinder.api
+
+
+
+
+
+ org.python.pydev.PyDevBuilder
+
+
+
+
+
+ org.python.pydev.pythonNature
+
+
diff --git a/Doxyfile b/Doxyfile
index 56ec070..27dca58 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -31,7 +31,7 @@ PROJECT_NAME = "Python ChannelFinder Client Library"
# This could be handy for archiving the generated documentation or
# if some version control system is used.
-PROJECT_NUMBER = "1.1.0"
+PROJECT_NUMBER = "3.0.0"
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
diff --git a/channelfinder/ChannelFinderClient.py b/channelfinder/ChannelFinderClient.py
index 114bec7..bb2d688 100644
--- a/channelfinder/ChannelFinderClient.py
+++ b/channelfinder/ChannelFinderClient.py
@@ -49,8 +49,8 @@ def __init__(self, BaseURL=None, username=None, password=None):
else:
self.__auth = None
self.__session = requests.Session()
- self.__session.mount('https://localhost:8181/ChannelFinder/', Ssl3HttpAdapter())
- self.__session.get(self.__baseURL, verify=False, headers=copy(self.__jsonheader)).raise_for_status()
+ self.__session.mount(self.__baseURL, Ssl3HttpAdapter())
+ #self.__session.get(self.__baseURL, verify=False, headers=copy(self.__jsonheader)).raise_for_status()
except:
raise Exception, 'Failed to create client to ' + self.__baseURL
@@ -67,9 +67,14 @@ def set(self, **kwds):
The operation creates a new entry if none exists and destructively replaces existing entries.
set(channel = Channel)
>>> set(channel={'name':'channelName', 'owner':'channelOwner'})
-
+ >>> set(channel={'name':'channelName',
+ 'owner':'channelOwner',
+ 'tags':[{'name':'tagName1', 'owner':'tagOwner'}, ...],
+ 'properties':[{'name':'propName1', 'owner':'propOwner', 'value':'propValue1'}, ...]})
+
set(channels = [Channel])
>>> set(channels=[{'name':'chName1','owner':'chOwner'},{'name':'chName2','owner':'chOwner'}])
+ >>> set(channels=[{'name':'chName1','owner':'chOwner', 'tags':[...], 'properties':[...]}, {...}])
set(tag = Tag)
>>> set(tag={'name':'tagName','owner':'tagOwner'})
@@ -87,25 +92,20 @@ def set(self, **kwds):
*** if you simply want to append a tag or property use the update operation***
set(tag=Tag, channelName=String)
- >>> set(tag={'name':'tagName','owner':'tagOwner}, channelName='chName')
+ >>> set(tag={'name':'tagName','owner':'tagOwner'}, channelName='chName')
# will create/replace specified Tag
# and add it to the channel with the name = channelName
set(tag=Tag, channelNames=[String])
- >>> set (tag={'name':'tagName','owner':'tagOwner}, channelNames=['ch1','ch2','ch3'])
+ >>> set (tag={'name':'tagName','owner':'tagOwner'}, channelNames=['ch1','ch2','ch3'])
# will create/replace the specified Tag
# and add it to the channels with the names specified in channelNames
# and delete it from all other channels
- set(property=Property, channelName=String)
- >>> set(property={'name':'propName','owner':'propOwner','value':'propValue'}, channelName='channelName')
- # will create/replace the specified Property
- # and add it to the channel with the name = channelName
-
set(property=Property, channelNames=[String])
- >>> set(property={'name':'propName','owner':'propOwner','value':'propValue'}, channelNames=[String])
+ >>> set(property={'name':'propName','owner':'propOwner','value':'propValue'}, channels=[...])
# will create/replace the specified Property
- # and add it to the channels with the names specified in channelNames
+ # and add it to the channels with the names specified in channels
# and delete it from all other channels
'''
@@ -118,62 +118,62 @@ def set(self, **kwds):
def __hadleSingleAddParameter(self, **kwds):
if 'channel' in kwds :
- r = self.__session.put(self.__baseURL + self.__channelsResource + '/' + kwds['channel'][u'name'], \
- data=JSONEncoder().encode(kwds['channel']), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ r = self.__session.put(self.__baseURL + self.__channelsResource + '/' + kwds['channel'][u'name'],
+ data=JSONEncoder().encode(kwds['channel']),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth)
r.raise_for_status()
elif 'channels' in kwds :
- r = self.__session.put(self.__baseURL + self.__channelsResource, \
- data=JSONEncoder().encode(kwds['channels']), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ r = self.__session.put(self.__baseURL + self.__channelsResource,
+ data=JSONEncoder().encode(kwds['channels']),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth)
r.raise_for_status()
elif 'tag' in kwds:
- r = self.__session.put(self.__baseURL + self.__tagsResource + '/' + kwds['tag'][u'name'], \
- data=JSONEncoder().encode(kwds['tag']), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ r = self.__session.put(self.__baseURL + self.__tagsResource + '/' + kwds['tag'][u'name'],
+ data=JSONEncoder().encode(kwds['tag']),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth)
r.raise_for_status()
elif 'tags' in kwds:
data = JSONEncoder().encode(kwds['tags'])
- r = self.__session.put(self.__baseURL + self.__tagsResource, \
- data=data, \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ r = self.__session.put(self.__baseURL + self.__tagsResource,
+ data=data,
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth)
r.raise_for_status()
elif 'property' in kwds:
- r = self.__session.put(self.__baseURL + self.__propertiesResource + '/' + kwds['property'][u'name'], \
- data=JSONEncoder().encode(kwds['property']) , \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ r = self.__session.put(self.__baseURL + self.__propertiesResource + '/' + kwds['property'][u'name'],
+ data=JSONEncoder().encode(kwds['property']) ,
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth)
r.raise_for_status()
elif 'properties' in kwds: ############################ u'property' may be incorrect
data = JSONEncoder().encode(kwds['properties'])
- r = self.__session.put(self.__baseURL + self.__propertiesResource, \
- data=data, \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ r = self.__session.put(self.__baseURL + self.__propertiesResource,
+ data=data,
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth)
r.raise_for_status()
else:
- raise Exception, 'Incorrect Usage: unknown key'
-
+ raise Exception, 'Incorrect Usage: unknown key'
+
def __handleMultipleAddParameters(self, **kwds):
# set a tag to a channel
if 'tag' in kwds and 'channelName' in kwds:
channels = [{u'name':kwds['channelName'].strip(), u'owner':self.__userName}]
kwds['tag']['channels'] = channels
data = kwds['tag']
- self.__session.put(self.__baseURL + self.__tagsResource + '/' + kwds['tag'][u'name'], \
- data=JSONEncoder().encode(data), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ self.__session.put(self.__baseURL + self.__tagsResource + '/' + kwds['tag'][u'name'],
+ data=JSONEncoder().encode(data),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth).raise_for_status()
elif 'tag' in kwds and 'channelNames' in kwds:
channels = []
@@ -181,22 +181,22 @@ def __handleMultipleAddParameters(self, **kwds):
channels.append({u'name':eachChannel, u'owner':self.__userName})
kwds['tag']['channels'] = channels
data = kwds['tag']
- self.__session.put(self.__baseURL + self.__tagsResource + '/' + kwds['tag'][u'name'], \
- data=JSONEncoder().encode(data), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ self.__session.put(self.__baseURL + self.__tagsResource + '/' + kwds['tag'][u'name'],
+ data=JSONEncoder().encode(data),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth).raise_for_status()
elif 'property' in kwds and 'channels' in kwds:
data = kwds['property']
data['property']['channels'] = kwds['channels']
- self.__session.put(self.__baseURL + self.__propertiesResource + '/' + kwds['property'][u'name'], \
- data=JSONEncoder().encode(data), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ self.__session.put(self.__baseURL + self.__propertiesResource + '/' + kwds['property'][u'name'],
+ data=JSONEncoder().encode(data),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth).raise_for_status()
else:
raise Exception, 'Incorrect Usage: unknown keys'
-
+
def __checkResponseState(self, r):
'''
simply checks the return status of the http response
@@ -207,48 +207,48 @@ def __checkResponseState(self, r):
raise Exception, 'HTTP Error status: ' + r[u'headers']['status'] + \
' Cause: ' + msg
return r
-
+
def find(self, **kwds):
'''
Method allows you to query for a channel/s based on name, properties, tags
find(name = channelNamePattern)
>>> find(name='*')
>>> find(name='SR:C01*')
-
+
find(tagName = tagNamePattern)
>>> find(tagName = 'myTag')
-
+
find(property = [(propertyName,propertyValuePattern)])
>>> find(property=[('position','*')])
>>> find(property=[('position','*'),('cell','')])
-
+
returns a _list_ of matching Channels
- special pattern matching char
+ special pattern matching char
* for multiple char
? for single char
-
+
Searching with multiple parameters
>>> find(name='SR:C01*', tagName = 'myTag', property=[('position','pattern1')])
- return all channels with name matching 'SR:C01*' AND
- with tagName = 'mytag' AND
+ return all channels with name matching 'SR:C01*' AND
+ with tagName = 'mytag' AND
with property 'position' with value matching 'pattern1'
-
-
+
+
For multiValued searches
>>> find(name='pattern1,pattern2')
will return all the channels which match either pattern1 OR pattern2
-
+
>>> find(property=[('propA','pattern1,pattern2')])
- will return all the channels which have the property propA and
+ will return all the channels which have the property propA and
whose values match pattern1 OR pattern2
-
+
>>> find(property=[('propA', 'pattern1'),('propB', 'pattern2')])
will return all the channels which have properties
_propA_ with value matching _pattern1_ AND _propB_ with value matching _pattern2_
-
+
>>> find(tagName='pattern1,pattern2')
will return all the channels which have the tags matching pattern1 AND pattern2
-
+
To query for the existance of a tag or property use findTag and findProperty.
'''
if not self.__baseURL:
@@ -273,13 +273,13 @@ def find(self, **kwds):
else:
raise Exception, 'unknown find argument ' + key
return self.findByArgs(args)
-
+
def findByArgs(self, args):
url = self.__baseURL + self.__channelsResource
- r = self.__session.get(url, \
- params=args, \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ r = self.__session.get(url,
+ params=args,
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth)
try:
r.raise_for_status()
@@ -288,8 +288,8 @@ def findByArgs(self, args):
if r.status_code == 404:
return None
else:
- r.raise_for_status()
-
+ r.raise_for_status()
+
def findTag(self, tagName):
'''
Searches for the _exact_ tagName and returns a single Tag object if found
@@ -307,7 +307,7 @@ def findTag(self, tagName):
return None
else:
r.raise_for_status()
-
+
def findProperty(self, propertyName):
'''
Searches for the _exact_ propertyName and return a single Property object if found
@@ -322,7 +322,7 @@ def findProperty(self, propertyName):
return None
else:
r.raise_for_status()
-
+
def getAllTags(self):
'''
return a list of all the Tags present - even the ones not associated w/t any channel
@@ -337,7 +337,7 @@ def getAllTags(self):
return None
else:
r.raise_for_status()
-
+
def getAllProperties(self):
'''
return a list of all the Properties present - even the ones not associated w/t any channel
@@ -352,33 +352,33 @@ def getAllProperties(self):
return None
else:
r.raise_for_status()
-
+
def delete(self, **kwds):
'''
Method to delete a channel, property, tag
delete(channelName = String)
>>> delete(channelName = 'ch1')
-
+
delete(tagName = String)
>>> delete(tagName = 'myTag')
# tagName = tag name of the tag to be removed from all channels
-
+
delete(propertyName = String)
>>> delete(propertyName = 'position')
# propertyName = property name of property to be removed from all channels
-
+
delete(tag = Tag ,channelName = String)
- >>> delete(tag={'name':'myTag','owner':'tagOwner'}, channelName = 'chName')
+ >>> delete(tag={'name':'myTag','owner':'tagOwner'}, channelName = 'chName')
# delete the tag from the specified channel _chName_
-
+
delete(tag = Tag ,channelNames = [String])
>>> delete(tag={'name':'myTag', 'owner':'tagOwner'}, channelNames=['ch1','ch2','ch3'])
# delete the tag from all the channels specified in the channelNames list
-
+
delete(property = Property ,channelName = String)
>>> delete(property = {'name':'propName','propOwner':'propOwner'} ,channelName = 'chName')
# delete the property from the specified channel
-
+
delete(property = Property ,channelNames = [String])
>>> delete(property = {'name':'propName','owner':'propOwner'} ,channelNames = ['ch1','ch2','ch3'])
# delete the property from all the channels in the channelNames list
@@ -389,54 +389,54 @@ def delete(self, **kwds):
self.__handleMultipleDeleteParameters(**kwds)
else:
raise Exception, 'incorrect usage: Delete a single Channel/tag/property'
-
+
def __handleSingleDeleteParameter(self, **kwds):
if 'channelName' in kwds:
url = self.__baseURL + self.__channelsResource + '/' + kwds['channelName'].strip()
- self.__session.delete(url, \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ self.__session.delete(url,
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth).raise_for_status()
pass
elif 'tagName' in kwds:
url = self.__baseURL + self.__tagsResource + '/' + kwds['tagName'].strip()
- self.__session.delete(url, \
- verify=False, \
- headers=copy(self.__jsonheader), \
+ self.__session.delete(url,
+ verify=False,
+ headers=copy(self.__jsonheader),
auth=self.__auth).raise_for_status()
pass
elif 'propertyName' in kwds:
url = self.__baseURL + self.__propertiesResource + '/' + kwds['propertyName'].strip()
- self.__session.delete(url, \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ self.__session.delete(url,
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth).raise_for_status()
pass
else:
raise Exception, ' unkown key use channelName, tagName or proprtyName'
-
+
def __handleMultipleDeleteParameters(self, **kwds):
if 'tag' in kwds and 'channelName' in kwds:
- self.__session.delete(self.__baseURL + self.__tagsResource + '/' + kwds['tag'][u'name'] + '/' + kwds['channelName'].strip(), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ self.__session.delete(self.__baseURL + self.__tagsResource + '/' + kwds['tag'][u'name'] + '/' + kwds['channelName'].strip(),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth).raise_for_status()
elif 'tag' in kwds and 'channelNames' in kwds:
# find channels with the tag
channelsWithTag = self.find(tagName=kwds['tag'][u'name'])
# delete channels from which tag is to be removed
-
+
channelNames = [channel[u'name'] for channel in channelsWithTag if channel[u'name'] not in kwds['channelNames']]
self.set(tag=kwds['tag'], channelNames=channelNames)
elif 'property' in kwds and 'channelName' in kwds:
- self.__session.delete(self.__baseURL + self.__propertiesResource + '/' + kwds['property'][u'name'] + '/' + kwds['channelName'], \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ self.__session.delete(self.__baseURL + self.__propertiesResource + '/' + kwds['property'][u'name'] + '/' + kwds['channelName'],
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth).raise_for_status()
elif 'property' in kwds and 'channelNames' in kwds:
channelsWithProp = self.find(property=[(kwds['property'][u'name'], '*')])
channels = [channel for channel in channelsWithProp if channel[u'name'] not in kwds['channelNames']]
- self.set(property=kwds['property'], channels=channels)
+ self.set(property=kwds['property'], channels=channels)
else:
raise Exception, ' unkown keys'
@@ -452,51 +452,51 @@ def update(self, **kwds):
{'name':'newProp','owner':'propOwner','value':'Val'},
{'name':'existingProp','owner':'propOwner','value':'newVal'}],
tags=[{'name':'mytag','owner':'tagOwner'}]})
- # updates the channel 'existingCh' with the new provided properties and tags
- # without affecting the other tags and properties of this channel
-
+ # updates the channel 'existingCh' with the new provided properties and tags
+ # without affecting the other tags and properties of this channel
+
update(property = Property, channelName = String)
- >>> update(property={'name':'propName', 'owner':'propOwner', 'value':'propValue'},
+ >>> update(property={'name':'propName', 'owner':'propOwner', 'value':'propValue'},
channelName='ch1')
# Add Property to the channel with the name 'ch1'
- # without affecting the other channels using this property
-
- >>>update(property={'name':'propName', 'owner':'propOwner', 'value':'propValue'},
+ # without affecting the other channels using this property
+
+ >>>update(property={'name':'propName', 'owner':'propOwner', 'value':'propValue'},
channelNames=['ch1','ch2','ch3'])
# Add Property to the channels with the names in the list channelNames
- # without affecting the other channels using this property
-
+ # without affecting the other channels using this property
+
update(tag = Tag, channelName = String)
>>> update(tag = {'name':'myTag', 'owner':'tagOwner'}, channelName='chName')
# Add tag to channel with name chName
# without affecting the other channels using this tag
-
+
update(tag = Tag, channelNames = [String])
>>> update(tag = {'name':'tagName'}, channelNames=['ch1','ch2','ch3'])
# Add tag to channels with names in the list channeNames
- # without affecting the other channels using this tag
+ # without affecting the other channels using this tag
update(property = Property)
update(tag = Tag)
-
- ## RENAME OPERATIONS ##
+
+ ## RENAME OPERATIONS ##
update(channel = Channel, originalChannelName = String)
- >>> update(channel = {'name':'newChannelName','owner':'channelOwner},
+ >>> update(channel = {'name':'newChannelName','owner':'channelOwner'},
originalChannelName = 'oldChannelName')
# rename the channel 'oldChannelName' to 'newChannelName'
-
+
update(property = Property, originalPropertyName = String)
- >>> update(property = {'name':'newPropertyName','owner':'propOwner'},
+ >>> update(property = {'name':'newPropertyName','owner':'propOwner'},
originalPropertyName = 'oldPropertyName')
# rename the property 'oldPropertyName' to 'newPropertyName'
# the channels with the old property are also updated
-
+
update(tag = Tag, originalTagName = String)
>>> update(tab = {'name':'newTagName','owner':'tagOwner'}, originalTagName = 'oldTagName')
# rename the tag 'oldTagName' to 'newTagName'
# the channel with the old tag are also updated
'''
-
+
if not self.__baseURL:
raise Exception, 'Olog client not configured correctly'
if len(kwds) == 1:
@@ -505,105 +505,117 @@ def update(self, **kwds):
self.__handleMultipleUpdateParameters(**kwds)
else:
raise Exception, 'incorrect usage: '
-
+
def __handleSingleUpdateParameter(self, **kwds):
if 'channel' in kwds:
ch = kwds['channel']
- r = self.__session.post(self.__baseURL + self.__channelsResource + '/' + ch[u'name'], \
- data=JSONEncoder().encode(ch), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ r = self.__session.post(self.__baseURL + self.__channelsResource + '/' + ch[u'name'],
+ data=JSONEncoder().encode(ch),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth)
r.raise_for_status()
elif 'property' in kwds:
property = kwds['property']
- r = self.__session.post(self.__baseURL + self.__propertiesResource + '/' + property[u'name'], \
- data=JSONEncoder().encode(property), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ r = self.__session.post(self.__baseURL + self.__propertiesResource + '/' + property[u'name'],
+ data=JSONEncoder().encode(property),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth)
r.raise_for_status()
elif 'tag' in kwds:
tag = kwds['tag']
- r = self.__session.post(self.__baseURL + self.__tagsResource + '/' + tag[u'name'], \
- data=JSONEncoder().encode(tag), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ r = self.__session.post(self.__baseURL + self.__tagsResource + '/' + tag[u'name'],
+ data=JSONEncoder().encode(tag),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth)
r.raise_for_status()
elif 'tags' in kwds:
- r = self.__session.post(self.__baseURL + self.__tagsResource, \
- data=JSONEncoder().encode(kwds['tags']), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ r = self.__session.post(self.__baseURL + self.__tagsResource,
+ data=JSONEncoder().encode(kwds['tags']),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth)
r.raise_for_status()
else:
raise Exception, ' unkown key '
-
+
def __handleMultipleUpdateParameters(self, **kwds):
if 'tag' in kwds and 'channelName' in kwds:
- tag = kwds['tag']
- channels = [{u'name':kwds['channelName'].strip(), u'owner':self.__userName}]
- self.__session.post(self.__baseURL + self.__tagsResource + '/' + tag[u'name'], \
- data=JSONEncoder().encode(self.__encodeTag(tag, withChannels=channels)), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ # identity operation performed to prevent side-effects
+ tag = dict(kwds['tag'])
+ channels = [{u'name': kwds['channelName'].strip(), u'owner': self.__userName, u'tags': [tag]}]
+ tag = dict(tag)
+ tag[u'channels'] = channels
+ self.__session.post(self.__baseURL + self.__tagsResource + '/' + tag[u'name'],
+ data=JSONEncoder().encode(tag),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth).raise_for_status()
elif 'tag' in kwds and 'channelNames' in kwds:
- tag = kwds['tag']
+ # identity operation performed to prevent side-effects
+ tag = dict(kwds['tag'])
channels = []
for eachChannel in kwds['channelNames']:
- channels.append({u'name':eachChannel, u'owner':self.__userName})
- self.__session.post(self.__baseURL + self.__tagsResource + '/' + tag['name'], \
- data=JSONEncoder().encode(self.__encodeTag(tag, withChannels=channels)), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ channels.append({u'name': eachChannel, u'owner': self.__userName, u'tags': [tag]})
+ tag = dict(tag)
+ tag[u'channels'] = channels
+ self.__session.post(self.__baseURL + self.__tagsResource + '/' + tag[u'name'],
+ data=JSONEncoder().encode(tag),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth).raise_for_status()
elif 'property' in kwds and 'channelName' in kwds:
- property = kwds['property']
- channels = [{u'name':kwds['channelName'].strip(), u'owner':self.__userName, u'properties':[property]}]
- self.__session.post(self.__baseURL + self.__propertiesResource + '/' + property[u'name'], \
- data=JSONEncoder().encode(self.__encodeProperty(property, withChannels=channels)), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ # identity operation performed to prevent side-effects
+ property = dict(kwds['property'])
+ channels = [{u'name': kwds['channelName'].strip(), u'owner': self.__userName, u'properties': [property]}]
+ property = dict(property)
+ property[u'channels'] = channels
+ self.__session.post(self.__baseURL + self.__propertiesResource + '/' + property[u'name'],
+ data=JSONEncoder().encode(property),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth).raise_for_status()
elif 'property' in kwds and 'channelNames' in kwds:
- property = kwds['property']
+ # identity operation performed to prevent side-effects
+ property = dict(kwds['property'])
channels = []
for eachChannel in kwds['channelNames']:
- channels.append({u'name':eachChannel, u'owner':self.__userName, u'properties':[property]})
- self.__session.post(self.__baseURL + self.__propertiesResource + '/' + property[u'name'], \
- data=JSONEncoder().encode(self.__encodeProperty(property, withChannels=channels)), \
- headers=copy(self.__jsonheader), \
- verify=False, \
- auth=self.__auth).raise_for_status()
+ channels.append({u'name': eachChannel.strip(), u'owner': self.__userName, u'properties': [property]})
+ property = dict(property)
+ property[u'channels'] = channels
+ self.__session.post(self.__baseURL + self.__propertiesResource + '/' + property[u'name'],
+ data=JSONEncoder().encode(property),
+ headers=copy(self.__jsonheader),
+ verify=False,
+ auth=self.__auth).raise_for_status()
elif 'originalChannelName' in kwds and 'channel' in kwds:
ch = kwds['channel']
channelName = kwds['originalChannelName'].strip()
- self.__session.post(self.__baseURL + self.__channelsResource + '/' + channelName, \
- data=JSONEncoder().encode(self.__encodeChannel(ch)) , \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ self.__session.post(self.__baseURL + self.__channelsResource + '/' + channelName,
+ data=JSONEncoder().encode(ch),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth).raise_for_status()
elif 'originalPropertyName' in kwds and 'property' in kwds:
prop = kwds['property']
propName = kwds['originalPropertyName'].strip()
- self.__session.post(self.__baseURL + self.__propertiesResource + '/' + propName, \
- data=JSONEncoder().encode(self.__encodeProperty(prop)), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ self.__session.post(self.__baseURL + self.__propertiesResource + '/' + propName,
+ data=JSONEncoder().encode(prop),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth).raise_for_status()
- elif 'originalTagName' in kwds and 'tag' in kwds:
+ elif 'originalTagName' in kwds and 'tag' in kwds:
tag = kwds['tag']
tagName = kwds['originalTagName'].strip()
- self.__session.post(self.__baseURL + self.__tagsResource + '/' + tagName, \
- data=JSONEncoder().encode(tag), \
- headers=copy(self.__jsonheader), \
- verify=False, \
+ self.__session.post(self.__baseURL + self.__tagsResource + '/' + tagName,
+ data=JSONEncoder().encode(tag),
+ headers=copy(self.__jsonheader),
+ verify=False,
auth=self.__auth).raise_for_status()
else:
- raise Exception, ' unkown keys'
+ raise Exception, ' unknown keys'
@@ -614,6 +626,5 @@ def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(num_pools=connections,
maxsize=maxsize,
block=block,
- ssl_version=ssl.PROTOCOL_SSLv3)
+ ssl_version=ssl.PROTOCOL_SSLv23)
-
diff --git a/channelfinder/cfPropertyManager/CFPropertyManager.py b/channelfinder/cfPropertyManager/CFPropertyManager.py
index 3439005..dc3ab7d 100755
--- a/channelfinder/cfPropertyManager/CFPropertyManager.py
+++ b/channelfinder/cfPropertyManager/CFPropertyManager.py
@@ -2,12 +2,10 @@
SEE cf-property-manager.cfg for example configuration file
'''
from channelfinder import ChannelFinderClient
-from channelfinder.util import ChannelUtil
from optparse import OptionParser
from getpass import getpass
import re
-import time
-import sys
+from channelfinder._conf import _conf
global username, client, exclusion_expression, password, SERVICE_URL, quiet, verbose
@@ -104,7 +102,7 @@ def applyExpression():
if value != "":
prop_list.append({u'name' : expression[1], u'owner' : username, u'value' : value})
else:
- if(verbose): print "MISSING IN " + line
+ if(verbose): print "MISSING " + expression[1] + "IN " + channel_name
if verbose: print "UPDATE "+channel_name
try:
client.update(channel = {u'name' : channel_name, u'owner':username,u'properties':prop_list })
diff --git a/channelfinder/cfPropertyManager/__init__.py b/channelfinder/cfPropertyManager/__init__.py
index e69de29..789b1f7 100644
--- a/channelfinder/cfPropertyManager/__init__.py
+++ b/channelfinder/cfPropertyManager/__init__.py
@@ -0,0 +1 @@
+from CFPropertyManager import *
\ No newline at end of file
diff --git a/channelfinder/cfUpdate/CFUpdateIOC.py b/channelfinder/cfUpdate/CFUpdateIOC.py
index fa6c507..03c9d00 100644
--- a/channelfinder/cfUpdate/CFUpdateIOC.py
+++ b/channelfinder/cfUpdate/CFUpdateIOC.py
@@ -37,10 +37,10 @@ def getPVNames(completeFilePath, pattern=None):
try:
f = open(completeFilePath)
pvNames = f.read().splitlines()
- pvNames=map(lambda x: x.strip(), pvNames)
- pvNames=filter(lambda x: len(x)>0, pvNames)
+ pvNames = map(lambda x: x.strip(), pvNames)
+ pvNames = filter(lambda x: len(x)>0, pvNames)
if pattern:
- pvNames=[ re.match(pattern,pvName).group() for pvName in pvNames if re.match(pattern, pvName) ]
+ pvNames = [re.match(pattern, pvName).group() for pvName in pvNames if re.match(pattern, pvName)]
return pvNames
except IOError:
return None
@@ -48,7 +48,7 @@ def getPVNames(completeFilePath, pattern=None):
if f:
f.close()
-def updateChannelFinder(pvNames, hostName, iocName, time, owner, \
+def updateChannelFinder(pvNames, hostName, iocName, time, owner,
service=None, username=None, password=None):
'''
pvNames = list of pvNames
@@ -75,52 +75,54 @@ def updateChannelFinder(pvNames, hostName, iocName, time, owner, \
previousChannelsList = client.findByArgs([(u'hostName', hostName), (u'iocName', iocName)])
if previousChannelsList != None:
for ch in previousChannelsList:
- if pvNames != None and ch.Name in pvNames:
+ if pvNames != None and ch['name'] in pvNames:
''''''
- channels.append(updateChannel(ch,\
- owner=owner, \
- hostName=hostName, \
- iocName=iocName, \
- pvStatus=u'Active', \
+ channels.append(updateChannel(ch,
+ owner=owner,
+ hostName=hostName,
+ iocName=iocName,
+ pvStatus=u'Active',
time=time))
- pvNames.remove(ch.Name)
- elif pvNames == None or ch.Name not in pvNames:
+ pvNames.remove(ch['name'])
+ elif pvNames == None or ch['name'] not in pvNames:
'''Orphan the channel : mark as inactive, keep the old hostName and iocName'''
- channels.append(updateChannel(ch, \
- owner=owner, \
- hostName=ch.getProperties()[u'hostName'], \
- iocName=ch.getProperties()[u'iocName'], \
- pvStatus=u'InActive', \
- time=ch.getProperties()[u'time']))
+ oldHostName = [ prop[u'value'] for prop in ch[u'properties'] if prop[u'name'] == u'hostName'][0]
+ oldIocName = [ prop[u'value'] for prop in ch[u'properties'] if prop[u'name'] == u'iocName'][0]
+ channels.append(updateChannel(ch,
+ owner=owner,
+ hostName=oldHostName,
+ iocName=oldIocName,
+ pvStatus=u'Inactive',
+ time=time))
# now pvNames contains a list of pv's new on this host/ioc
for pv in pvNames:
ch = client.findByArgs([('~name',pv)])
- if ch == None:
+ if not ch:
'''New channel'''
- channels.append(createChannel(pv, \
- chOwner=owner, \
- hostName=hostName, \
- iocName=iocName, \
- pvStatus=u'Active', \
+ channels.append(createChannel(pv,
+ chOwner=owner,
+ hostName=hostName,
+ iocName=iocName,
+ pvStatus=u'Active',
time=time))
elif ch[0] != None:
'''update existing channel: exists but with a different hostName and/or iocName'''
- channels.append(updateChannel(ch[0], \
- owner=owner, \
- hostName=hostName, \
- iocName=iocName, \
- pvStatus=u'Active', \
+ channels.append(updateChannel(ch[0],
+ owner=owner,
+ hostName=hostName,
+ iocName=iocName,
+ pvStatus=u'Active',
time=time))
client.set(channels=channels)
-def updateChannel(channel, owner, hostName=None, iocName=None, pvStatus='InActive', time=None):
+def updateChannel(channel, owner, hostName=None, iocName=None, pvStatus='Inactive', time=None):
'''
Helper to update a channel object so as to not affect the existing properties
'''
# properties list devoid of hostName and iocName properties
if channel[u'properties']:
- properties = [property for property in channel[u'properties'] \
+ properties = [property for property in channel[u'properties']
if property[u'name'] != u'hostName' and property[u'name'] != u'iocName' and property[u'name'] != u'pvStatus']
else:
properties = []
@@ -135,7 +137,7 @@ def updateChannel(channel, owner, hostName=None, iocName=None, pvStatus='InActiv
channel[u'properties'] = properties
return channel
-def createChannel(chName, chOwner, hostName=None, iocName=None, pvStatus=u'InActive', time=None):
+def createChannel(chName, chOwner, hostName=None, iocName=None, pvStatus=u'Inactive', time=None):
'''
Helper to create a channel object with the required properties
'''
@@ -184,26 +186,26 @@ def mainRun(opts, args):
fHostName, fIocName = getArgsFromFilename(completeFilePath)
ftime = os.path.getctime(completeFilePath)
pattern = __getDefaultConfig('pattern', opts.pattern)
- updateChannelFinder(getPVNames(completeFilePath, pattern=pattern), \
- ifNoneReturnDefault(opts.hostName, fHostName), \
- ifNoneReturnDefault(opts.iocName, fIocName), \
- ifNoneReturnDefault(opts.time, ftime), \
- ifNoneReturnDefault(opts.owner,__getDefaultConfig('username', opts.username)), \
- service=__getDefaultConfig('BaseURL',opts.serviceURL), \
- username=__getDefaultConfig('username',opts.username), \
+ updateChannelFinder(getPVNames(completeFilePath, pattern=pattern),
+ ifNoneReturnDefault(opts.hostName, fHostName),
+ ifNoneReturnDefault(opts.iocName, fIocName),
+ ifNoneReturnDefault(opts.time, ftime),
+ ifNoneReturnDefault(opts.owner,__getDefaultConfig('username', opts.username)),
+ service=__getDefaultConfig('BaseURL',opts.serviceURL),
+ username=__getDefaultConfig('username',opts.username),
password=__getDefaultConfig('password',opts.password))
else:
completeFilePath = os.path.abspath(filename)
fHostName, fIocName = getArgsFromFilename(completeFilePath)
ftime = os.path.getctime(completeFilePath)
pattern = __getDefaultConfig('pattern', opts.pattern)
- updateChannelFinder(getPVNames(completeFilePath, pattern=pattern), \
- ifNoneReturnDefault(opts.hostName, fHostName), \
- ifNoneReturnDefault(opts.iocName, fIocName), \
- ifNoneReturnDefault(opts.time, ftime), \
- ifNoneReturnDefault(opts.owner,__getDefaultConfig('username', opts.username)), \
- service=__getDefaultConfig('BaseURL',opts.serviceURL), \
- username=__getDefaultConfig('username',opts.username), \
+ updateChannelFinder(getPVNames(completeFilePath, pattern=pattern),
+ ifNoneReturnDefault(opts.hostName, fHostName),
+ ifNoneReturnDefault(opts.iocName, fIocName),
+ ifNoneReturnDefault(opts.time, ftime),
+ ifNoneReturnDefault(opts.owner,__getDefaultConfig('username', opts.username)),
+ service=__getDefaultConfig('BaseURL',opts.serviceURL),
+ username=__getDefaultConfig('username',opts.username),
password=__getDefaultConfig('password',opts.password))
def __getDefaultConfig(arg, value):
@@ -218,30 +220,30 @@ def __getDefaultConfig(arg, value):
def main():
usage = "usage: %prog [options] filename"
parser = OptionParser(usage=usage)
- parser.add_option('-H', '--hostname', \
- action='store', type='string', dest='hostName', \
+ parser.add_option('-H', '--hostname',
+ action='store', type='string', dest='hostName',
help='the hostname')
- parser.add_option('-i', '--iocname', \
- action='store', type='string', dest='iocName', \
+ parser.add_option('-i', '--iocname',
+ action='store', type='string', dest='iocName',
help='the iocname')
- parser.add_option('-s', '--service', \
- action='store', type='string', dest='serviceURL', \
+ parser.add_option('-s', '--service',
+ action='store', type='string', dest='serviceURL',
help='the service URL')
- parser.add_option('-o', '--owner', \
- action='store', type='string', dest='owner', \
+ parser.add_option('-o', '--owner',
+ action='store', type='string', dest='owner',
help='owner if not specified username will default as owner')
- parser.add_option('-r', '--pattern', \
- action='store', type='string', dest='pattern', \
+ parser.add_option('-r', '--pattern',
+ action='store', type='string', dest='pattern',
help='pattern to match valid channel names')
- parser.add_option('-u', '--username', \
- action='store', type='string', dest='username', \
+ parser.add_option('-u', '--username',
+ action='store', type='string', dest='username',
help='username')
- parser.add_option('-t', '--time', \
- action='store', type='string', dest='time', \
+ parser.add_option('-t', '--time',
+ action='store', type='string', dest='time',
help='time')
- parser.add_option('-p', '--password', \
- action='callback', callback=getPassword, \
- dest='password', \
+ parser.add_option('-p', '--password',
+ action='callback', callback=getPassword,
+ dest='password',
help='prompt user for password')
opts, args = parser.parse_args()
if len(args) == 0 or args == None:
diff --git a/test/CFUpdateIOCTest.py b/test/CFUpdateIOCTest.py
index 35f8b92..124ab10 100644
--- a/test/CFUpdateIOCTest.py
+++ b/test/CFUpdateIOCTest.py
@@ -1,411 +1,426 @@
-'''
-Copyright (c) 2010 Brookhaven National Laboratory
-All rights reserved. Use is subject to license terms and conditions.
-
-Created on Apr 5, 2011
-
-@author: shroffk
-'''
-import unittest
-import os
-from channelfinder import Channel, Property, Tag
-from channelfinder import ChannelFinderClient
-from _testConf import _testConf
-from channelfinder.cfUpdate.CFUpdateIOC import getPVNames, getArgsFromFilename, updateChannelFinder, ifNoneReturnDefault
-from time import time
-from tempfile import NamedTemporaryFile
-from copy import copy
-
-class Test(unittest.TestCase):
-
- def setUp(self):
- if _testConf.has_option('DEFAULT', 'BaseURL'):
- self.baseURL = _testConf.get('DEFAULT', 'BaseURL')
- if _testConf.has_option('DEFAULT', 'username'):
- self.username = _testConf.get('DEFAULT', 'username')
- if _testConf.has_option('DEFAULT', 'password'):
- self.password = _testConf.get('DEFAULT', 'password')
- if _testConf.has_option('DEFAULT', 'owner'):
- self.owner = _testConf.get('DEFAULT', 'owner')
- pass
-
-
- def tearDown(self):
- pass
-
- def testParameterParsing(self):
-# scrap.mainRun(mockOpt('mockhostname', 'mockiocname'), [])
- pass
-
- def testGetArgsFromFilename(self):
- #parse just file name
- hostname, iocname = getArgsFromFilename('aaa.bbb.ccc')
- self.assertTrue(hostname == 'aaa' and iocname == 'bbb', 'failed to parse the file name correctly')
- # parse file name from complete path
- hostname, iocname = getArgsFromFilename('complete/path/to/file/aaa.bbb.ccc')
- self.assertTrue(hostname == 'aaa' and iocname == 'bbb', 'failed to parse the file path correctly')
- # parse file which does not fit the format
- hostname, iocname = getArgsFromFilename('complete/path/to/file/somefilename')
- self.assertTrue(hostname == None and iocname == None, 'failed to parse the file path correctly')
- # file with only hostName
- hostname, iocname = getArgsFromFilename('complete/path/to/file/aaa.somefilename')
- self.assertTrue(hostname == 'aaa' and iocname == None, 'failed to parse the file correctly')
- # parse the hostname/iocname from 1st and 2nd positions seperated by .
- hostname, iocname = getArgsFromFilename('complete/path/to/file/aaa.bbb.ccc.ddd')
- self.assertTrue(hostname == 'aaa' and iocname == 'bbb', 'failed to parse the file correctly')
- pass
-
- def testAddUpdateChannels(self):
- # Check the method finds the error conditions and raises exceptions
- self.assertRaises(Exception, updateChannelFinder, [[], None, None])
- self.assertRaises(Exception, updateChannelFinder, [[], None, 'iocname'])
- self.assertRaises(Exception, updateChannelFinder, [[], 'hostName', None])
- # create default client
- client = ChannelFinderClient()
-
- # add new pv's
- t1 = str(time())
- hostName1 = 'update-test-hostname' + t1
- iocName1 = 'update-test-iocName' + t1
- channels = client.find(property=[('hostName', hostName1), ('iocName', iocName1)])
- self.assertTrue(channels == None or len(channels) == 0, 'channels already present')
- # New Channels added
- updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
- hostName1, \
- iocName1, \
- owner=self.owner, \
- time=t1, \
- service=self.baseURL , \
- username=self.username, \
- password=self.password)
- channels = client.find(property=[('hostName', hostName1), ('iocName', iocName1), ('time', t1)])
- self.assertTrue(len(channels) == 2, 'failed to create the channels with appropriate properties')
- t2 = str(time())
- hostName2 = 'update-test-hostname' + t2
- iocName2 = 'update-test-iocName' + t2
- # Existing channels are updated
- updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
- hostName2, \
- iocName2, \
- owner=self.owner, \
- time=t2, \
- service=self.baseURL , \
- username=self.username, \
- password=self.password)
- # no channels should have the old proerty values
- self.assertTrue(client.find(property=[('hostName', hostName1), ('iocName', iocName1), ('time', t1)]) == None, \
- 'failed to update the channels with appropriate properties, old values found')
- # channels should be updated to the new values
- self.assertTrue(len(client.find(property=[('hostName', hostName2), ('iocName', iocName2), ('time', t2)])) == 2, \
- 'failed to update the channels with appropriate properties')
- # Cleanup
- client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
- client.delete(channelName='cf-update-pv1')
- client.delete(channelName='cf-update-pv2')
- pass
-
- def testAddUpdateChannelsWithProperties(self):
- '''
- This is to check that existing properties of channels are not affected.
- '''
- unaffectedProperty = Property('unaffectedProperty', self.owner, 'unchanged')
- # create default client
- client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
- client.set(property=unaffectedProperty)
-
- # add new pv's
- t1 = str(time())
- hostName1 = 'update-test-hostname' + t1
- iocName1 = 'update-test-iocName' + t1
- # New Channels added
- client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password);
- client.set(channel=Channel('cf-update-pv1', 'cf-update', properties=[unaffectedProperty]))
- updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
- hostName1, \
- iocName1, \
- owner=self.owner, \
- time=t1, \
- service=self.baseURL , \
- username=self.username, \
- password=self.password)
- channels = client.find(property=[('hostName', hostName1), ('iocName', iocName1), ('time', t1)])
- self.assertTrue(len(channels) == 2, 'failed to create the channels with appropriate properties')
- channels = client.find(name='cf-update-pv1')
- self.assertTrue(len(channels) == 1)
- self.assertTrue(len(channels[0].Properties) == 5)
- # Cleanup
- client.delete(channelName='cf-update-pv1')
- client.delete(channelName='cf-update-pv2')
- client.delete(propertyName=unaffectedProperty.Name)
-
-
- def testPreservingOfAttributes(self):
- '''
- This test is to ensure that existing properties and tags are left untouched.
- Case1:
- first time the cf-update comes across these channels and adds hostName and iocName
- Case2:
- the hostName is changed
- Case3:
- the iocName is changed
- Case4:
- both hostName and iocName are changed
- Case5:
- the channel is removed
- in all cases the existing unaffected* property and tag should remain with the channel
- '''
- unaffectedProperty = Property('unaffectedProperty', self.owner, 'unchanged')
- unaffectedTag = Tag('unaffectedTag', self.owner)
- # create default client
- client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
- client.set(property=unaffectedProperty)
- client.set(tag=unaffectedTag)
-
- client.set(channel=Channel('cf-update-pv1', 'cf-update', properties=[unaffectedProperty], tags=[unaffectedTag]))
- client.set(channel=Channel('cf-update-pv2', 'cf-update', properties=[unaffectedProperty], tags=[unaffectedTag]))
-
- # Case1:
- hostName = 'initialHost'
- iocName = 'initialIoc'
- updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
- hostName, \
- iocName, \
- owner=self.owner, \
- time=time(), \
- service=self.baseURL , \
- username=self.username, \
- password=self.password)
- channels = client.find(name='cf-update-pv*')
- for channel in channels:
- self.assertTrue(unaffectedProperty in channel.Properties and unaffectedTag in channel.Tags)
- self.assertTrue(channel.getProperties()['hostName'] == hostName and \
- channel.getProperties()['iocName'] == iocName and \
- channel.getProperties()['pvStatus'] == 'Active', \
- 'Failed to update channels with the correct hostName and/or iocName')
- # Case2:
- hostName = 'newHost'
- updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
- hostName, \
- iocName, \
- owner=self.owner, \
- time=time(), \
- service=self.baseURL , \
- username=self.username, \
- password=self.password)
- channels = client.find(name='cf-update-pv*')
- for channel in channels:
- self.assertTrue(unaffectedProperty in channel.Properties and unaffectedTag in channel.Tags)
- self.assertTrue(channel.getProperties()['hostName'] == hostName and \
- channel.getProperties()['iocName'] == iocName and \
- channel.getProperties()['pvStatus'] == 'Active', \
- 'Failed to update channels with the correct hostName and/or iocName')
- self.assertTrue(client.find(property=[('hostName', 'initialHost')]) == None, 'Failed to cleanup old property')
- # Case 3:
- iocName = 'newIoc'
- updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
- hostName, \
- iocName, \
- owner=self.owner, \
- time=time(), \
- service=self.baseURL , \
- username=self.username, \
- password=self.password)
- channels = client.find(name='cf-update-pv*')
- for channel in channels:
- self.assertTrue(unaffectedProperty in channel.Properties and unaffectedTag in channel.Tags)
- self.assertTrue(channel.getProperties()['hostName'] == hostName and \
- channel.getProperties()['iocName'] == iocName and \
- channel.getProperties()['pvStatus'] == 'Active', 'Failed to update channels with the correct hostName and/or iocName')
- self.assertTrue(client.find(property=[('hostName', 'initialHost')]) == None, 'Failed to cleanup old property')
- self.assertTrue(client.find(property=[('iocName', 'initialIoc')]) == None, 'Failed to cleanup old property')
- # Case 4:
- updateChannelFinder([], \
- hostName, \
- iocName, \
- owner=self.owner, \
- time=time(), \
- service=self.baseURL , \
- username=self.username, \
- password=self.password)
- channels = client.find(name='cf-update-pv*')
- for channel in channels:
- self.assertTrue(unaffectedProperty in channel.Properties and unaffectedTag in channel.Tags)
- self.assertTrue(channel.getProperties()['hostName'] == hostName and \
- channel.getProperties()['iocName'] == iocName and \
- channel.getProperties()['pvStatus'] == 'InActive', \
- 'Failed to update channels with the correct hostName and/or iocName')
- self.assertTrue(client.find(property=[('hostName', 'initialHost')]) == None, 'Failed to cleanup old property')
- self.assertTrue(client.find(property=[('iocName', 'initialIoc')]) == None, 'Failed to cleanup old property')
-
- # Cleanup
- client.delete(channelName='cf-update-pv1')
- client.delete(channelName='cf-update-pv2')
- client.delete(propertyName=unaffectedProperty.Name)
- client.delete(tagName=unaffectedTag.Name)
-
- def testNoneCheck(self):
- self.assertTrue(ifNoneReturnDefault('Value', 'default') == 'Value')
- self.assertTrue(ifNoneReturnDefault(None, 'default') == 'default')
- self.assertTrue(ifNoneReturnDefault(None, None) == None)
- self.assertTrue(ifNoneReturnDefault('', 'default') == '')
-
- def testPVUpdate(self):
- '''
- Test condition
- IOC turned on with ch1, ch2
- IOC turned on with ch1 only
- IOC turned on with ch1, ch2
- '''
- try:
- updateChannelFinder(['ch1', 'ch2'], \
- 'testHost', \
- 'testIOC', \
- owner=self.owner, \
- time=time(), \
- service=self.baseURL, \
- username=self.username, password=self.password)
- client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
- chs = client.find(property=[('hostName', 'testHost'), ('iocName', 'testIOC'), ('pvStatus', 'Active')])
- self.assertEqual(len(chs), 2, 'Expected 2 positive matches but found ' + str(len(chs)))
- updateChannelFinder(['ch1'], \
- 'testHost', \
- 'testIOC', \
- owner=self.owner, \
- time=time(), \
- service=self.baseURL, \
- username=self.username, password=self.password)
- chs = client.find(property=[('hostName', 'testHost'), ('iocName', 'testIOC'), ('pvStatus', 'Active')])
- self.assertEqual(len(chs), 1, 'Expected 1 positive matches but found ' + str(len(chs)))
- self.assertTrue(chs[0].Name == 'ch1', 'channel with name ch1 not found')
- chs = client.find(property=[('hostName', 'testHost'), ('iocName', 'testIOC'), ('pvStatus', 'InActive')])
- self.assertEqual(len(chs), 1, 'Expected 1 positive matches but found ' + str(len(chs)))
- self.assertTrue(chs[0].Name == 'ch2', 'channel with name ch2 not found')
- updateChannelFinder(['ch1', 'ch2'], \
- 'testHost', \
- 'testIOC', \
- owner=self.owner, \
- time=time(), \
- service=self.baseURL, \
- username=self.username, password=self.password)
- chs = client.find(property=[('hostName', 'testHost'), ('iocName', 'testIOC'), ('pvStatus', 'Active')])
- self.assertEqual(len(chs), 2, 'Expected 2 positive matches but found ' + str(len(chs)))
- finally:
- client.delete(channelName='ch1')
- client.delete(channelName='ch2')
-
- def testPVMove(self):
- '''
- ch1, ch2 on host1, ioc1
- ch1 on host1, ioc1; ch2 on host1, ioc2 (case1)
- ch1, ch2 on host1, ioc1 (reset)
- ch1 on host1, ioc1; ch2 on host2, ioc2 (case2)
- ch1, ch2 on host1, ioc1 (reset)
- '''
- try:
- updateChannelFinder(['ch1', 'ch2'], \
- 'host1', \
- 'ioc1', \
- owner=self.owner, \
- time=time(),\
- service=self.baseURL, \
- username=self.username, password=self.password)
- client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
- chs = client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])
- self.assertEqual(len(chs), 2, 'Expected 2 positive matches but found ' + str(len(chs)))
- '''CASE1'''
- updateChannelFinder(['ch1'], \
- 'host1', \
- 'ioc1', \
- time=time(), \
- owner=self.owner, service=self.baseURL, \
- username=self.username, password=self.password)
- updateChannelFinder(['ch2'], \
- 'host1', \
- 'ioc2', \
- time=time(), \
- owner=self.owner, service=self.baseURL, \
- username=self.username, password=self.password)
- chs = client.find(property=[('hostName', 'host1')])
- self.assertEqual(len(chs), 2, 'Expected 1 positive matches but found ' + str(len(chs)))
- self.assertEqual(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])[0].Name, 'ch1', \
- 'Failed to find the expected channel _ch1_ with prop host1, ioc1')
- self.assertEqual(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc2')])[0].Name, 'ch2', \
- 'Failed to find the expected channel _ch2_ with prop host1, ioc2')
- '''RESET'''
- updateChannelFinder(['ch1', 'ch2'], \
- 'host1', \
- 'ioc1', \
- time=time(), \
- owner=self.owner, service=self.baseURL, \
- username=self.username, password=self.password)
- self.assertEqual(len(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])), 2, \
- 'Failed to reset the channels')
- '''CASE2'''
- updateChannelFinder(['ch1'], \
- 'host1', \
- 'ioc1', \
- owner=self.owner, \
- time=time(), \
- service=self.baseURL, username=self.username, \
- password=self.password)
- updateChannelFinder(['ch2'], \
- 'host2', \
- 'ioc2', \
- owner=self.owner, service=self.baseURL, \
- time=time(), \
- username=self.username, password=self.password)
- self.assertEqual(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])[0].Name, 'ch1', \
- 'Failed to find the expected channel _ch1_ with prop host1, ioc1')
- self.assertEqual(client.find(property=[('hostName', 'host2'), ('iocName', 'ioc2')])[0].Name, 'ch2', \
- 'Failed to find the expected channel _ch2_ with prop host1, ioc2')
- '''RESET'''
- updateChannelFinder(['ch1', 'ch2'], \
- 'host1', \
- 'ioc1', \
- owner=self.owner, \
- time=time(), \
- service=self.baseURL, \
- username=self.username, password=self.password)
- self.assertEqual(len(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])), 2, \
- 'Failed to reset the channels')
- finally:
- client.delete(channelName='ch1')
- client.delete(channelName='ch2')
-
- def testRegularExperssion(self):
- tempFile = NamedTemporaryFile(delete=False)
- publicPVs = ['publicPV1', 'publicPV2', 'publicPV3']
- privatePVS = ['_privatePV1', '_privatePV2']
- allPVs = copy(publicPVs);
- allPVs.extend(privatePVS)
- for pv in allPVs:
- tempFile.write(pv + '\n')
- tempFile.close();
- try:
- pvNames = getPVNames(tempFile.name)
- self.assertEqual(len(pvNames), len(allPVs), \
- 'expected ' + str(len(allPVs)) + ' but got ' + str(len(pvNames)))
- pvNames = getPVNames(tempFile.name, pattern='[^_]+')
- self.assertEqual(len(pvNames), len(publicPVs), \
- 'expected ' + str(len(allPVs)) + ' but got ' + str(len(publicPVs)))
- self.assertTrue(frozenset(pvNames).issuperset(frozenset(publicPVs)), \
- 'resulting pvNames contains invalid non public pvs')
- self.assertTrue(frozenset(pvNames).isdisjoint(frozenset(privatePVS)), \
- 'result pvNames contains invalid private pvs')
- pass
- finally:
- os.remove(tempFile.name)
- pass
-
-
-if __name__ == "__main__":
- #import sys;sys.argv = ['', 'Test.testName']
- unittest.main()
-
-
-class mockOpt():
- def __init__(self, hostname, iocname, service=None):
- self.hostname = hostname
- self.iocname = iocname
- self.service = service
-
+'''
+Copyright (c) 2010 Brookhaven National Laboratory
+All rights reserved. Use is subject to license terms and conditions.
+
+Created on Apr 5, 2011
+
+@author: shroffk
+'''
+import unittest
+import os
+from channelfinder import ChannelFinderClient
+from _testConf import _testConf
+from channelfinder.cfUpdate.CFUpdateIOC import getPVNames, getArgsFromFilename, updateChannelFinder, ifNoneReturnDefault
+from time import time
+from tempfile import NamedTemporaryFile
+from copy import copy
+
+class Test(unittest.TestCase):
+
+ def setUp(self):
+ if _testConf.has_option('DEFAULT', 'BaseURL'):
+ self.baseURL = _testConf.get('DEFAULT', 'BaseURL')
+ if _testConf.has_option('DEFAULT', 'username'):
+ self.username = _testConf.get('DEFAULT', 'username')
+ if _testConf.has_option('DEFAULT', 'password'):
+ self.password = _testConf.get('DEFAULT', 'password')
+ if _testConf.has_option('DEFAULT', 'owner'):
+ self.owner = _testConf.get('DEFAULT', 'owner')
+
+ pass
+
+
+ def tearDown(self):
+ pass
+
+ def testParameterParsing(self):
+# scrap.mainRun(mockOpt('mockhostname', 'mockiocname'), [])
+ pass
+
+ def testGetArgsFromFilename(self):
+ #parse just file name
+ hostname, iocname = getArgsFromFilename('aaa.bbb.ccc')
+ self.assertTrue(hostname == 'aaa' and iocname == 'bbb', 'failed to parse the file name correctly')
+ # parse file name from complete path
+ hostname, iocname = getArgsFromFilename('complete/path/to/file/aaa.bbb.ccc')
+ self.assertTrue(hostname == 'aaa' and iocname == 'bbb', 'failed to parse the file path correctly')
+ # parse file which does not fit the format
+ hostname, iocname = getArgsFromFilename('complete/path/to/file/somefilename')
+ self.assertTrue(hostname == None and iocname == None, 'failed to parse the file path correctly')
+ # file with only hostName
+ hostname, iocname = getArgsFromFilename('complete/path/to/file/aaa.somefilename')
+ self.assertTrue(hostname == 'aaa' and iocname == None, 'failed to parse the file correctly')
+ # parse the hostname/iocname from 1st and 2nd positions seperated by .
+ hostname, iocname = getArgsFromFilename('complete/path/to/file/aaa.bbb.ccc.ddd')
+ self.assertTrue(hostname == 'aaa' and iocname == 'bbb', 'failed to parse the file correctly')
+ pass
+
+ def testAddUpdateChannels(self):
+ # Check the method finds the error conditions and raises exceptions
+ self.assertRaises(Exception, updateChannelFinder, [[], None, None])
+ self.assertRaises(Exception, updateChannelFinder, [[], None, 'iocname'])
+ self.assertRaises(Exception, updateChannelFinder, [[], 'hostName', None])
+ # create default client
+ client = ChannelFinderClient()
+
+ # add new pv's
+ t1 = str(time())
+ hostName1 = 'update-test-hostname' + t1
+ iocName1 = 'update-test-iocName' + t1
+ channels = client.find(property=[('hostName', hostName1), ('iocName', iocName1)])
+ self.assertTrue(channels == None or len(channels) == 0, 'channels already present')
+ # New Channels added
+ updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
+ hostName1, \
+ iocName1, \
+ owner=self.owner, \
+ time=t1, \
+ service=self.baseURL , \
+ username=self.username, \
+ password=self.password)
+ channels = client.find(property=[('hostName', hostName1), ('iocName', iocName1), ('time', t1)])
+ self.assertTrue(len(channels) == 2, 'failed to create the channels with appropriate properties')
+ t2 = str(time())
+ hostName2 = 'update-test-hostname' + t2
+ iocName2 = 'update-test-iocName' + t2
+ # Existing channels are updated
+ updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
+ hostName2, \
+ iocName2, \
+ owner=self.owner, \
+ time=t2, \
+ service=self.baseURL , \
+ username=self.username, \
+ password=self.password)
+ # no channels should have the old proerty values
+ self.assertTrue(not client.find(property=[('hostName', hostName1), ('iocName', iocName1), ('time', t1)]), \
+ 'failed to update the channels with appropriate properties, old values found')
+ # channels should be updated to the new values
+ self.assertTrue(len(client.find(property=[('hostName', hostName2), ('iocName', iocName2), ('time', t2)])) == 2, \
+ 'failed to update the channels with appropriate properties')
+ # Cleanup
+ client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
+ client.delete(channelName='cf-update-pv1')
+ client.delete(channelName='cf-update-pv2')
+ pass
+
+ def testAddUpdateChannelsWithProperties(self):
+ '''
+ This is to check that existing properties of channels are not affected.
+ '''
+ unaffectedProperty = {u'name':u'unaffectedProperty', u'owner':self.owner, u'value':u'unchanged'}
+ # create default client
+ client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
+ client.set(property=unaffectedProperty)
+
+ # add new pv's
+ t1 = str(time())
+ hostName1 = 'update-test-hostname' + t1
+ iocName1 = 'update-test-iocName' + t1
+ # New Channels added
+ client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password);
+ client.set(channel={u'name':u'cf-update-pv1', u'owner':u'cf-update', u'properties':[unaffectedProperty]})
+ updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
+ hostName1, \
+ iocName1, \
+ owner=self.owner, \
+ time=t1, \
+ service=self.baseURL , \
+ username=self.username, \
+ password=self.password)
+ channels = client.find(property=[('hostName', hostName1), ('iocName', iocName1), ('time', t1)])
+ self.assertTrue(len(channels) == 2, 'failed to create the channels with appropriate properties')
+ channels = client.find(name='cf-update-pv1')
+ self.assertTrue(len(channels) == 1)
+ self.assertTrue(len(channels[0][u'properties']) == 5)
+ # Cleanup
+ client.delete(channelName='cf-update-pv1')
+ client.delete(channelName='cf-update-pv2')
+ client.delete(propertyName=unaffectedProperty[u'name'])
+
+ def testPreservingOfAttributes(self):
+ '''
+ This test is to ensure that existing properties and tags are left untouched.
+ Case1:
+ first time the cf-update comes across these channels and adds hostName and iocName
+ Case2:
+ the hostName is changed
+ Case3:
+ the iocName is changed
+ Case4:
+ both hostName and iocName are changed
+ Case5:
+ the channel is removed
+ in all cases the existing unaffected* property and tag should remain with the channel
+ '''
+ unaffectedProperty = {u'name':u'unaffectedProperty', u'owner':self.owner, u'value':u'unchanged'}
+ unaffectedTag = {u'name':u'unaffectedTag', u'owner':self.owner}
+ # create default client
+ client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
+ client.set(property=unaffectedProperty)
+ client.set(tag=unaffectedTag)
+
+ client.set(channel={u'name':u'cf-update-pv1', u'owner':u'cf-update', u'properties':[unaffectedProperty], u'tags':[unaffectedTag]})
+ client.set(channel={u'name':u'cf-update-pv2', u'owner':u'cf-update', u'properties':[unaffectedProperty], u'tags':[unaffectedTag]})
+
+ # Case1:
+ hostName = 'initialHost'
+ iocName = 'initialIoc'
+ updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
+ hostName, \
+ iocName, \
+ owner=self.owner, \
+ time=time(), \
+ service=self.baseURL , \
+ username=self.username, \
+ password=self.password)
+ channels = client.find(name='cf-update-pv*')
+ for channel in channels:
+ self.assertTrue(unaffectedProperty in channel['properties'] and unaffectedTag in channel['tags'])
+ self.assertTrue(self.__check4properties({u'name':u'hostName', u'value':hostName}, channel['properties']) and
+ self.__check4properties({u'name':u'iocName', u'value':iocName}, channel['properties']) and
+ self.__check4properties({u'name':u'pvStatus', u'value':u'Active'}, channel['properties']),
+ 'Failed to update channels with the correct hostName and/or iocName')
+ # Case2:
+ hostName = 'newHost'
+ updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
+ hostName, \
+ iocName, \
+ owner=self.owner, \
+ time=time(), \
+ service=self.baseURL , \
+ username=self.username, \
+ password=self.password)
+ channels = client.find(name='cf-update-pv*')
+ for channel in channels:
+ self.assertTrue(unaffectedProperty in channel['properties'] and unaffectedTag in channel['tags'])
+ self.assertTrue(self.__check4properties({u'name':u'hostName', u'value':hostName}, channel['properties']) and
+ self.__check4properties({u'name':u'iocName', u'value':iocName}, channel['properties']) and
+ self.__check4properties({u'name':u'pvStatus', u'value':u'Active'}, channel['properties']),
+ 'Failed to update channels with the correct hostName and/or iocName')
+ self.assertTrue(not client.find(property=[('hostName', 'initialHost')]), 'Failed to cleanup old property')
+ # Case 3:
+ iocName = 'newIoc'
+ updateChannelFinder(['cf-update-pv1', 'cf-update-pv2'], \
+ hostName, \
+ iocName, \
+ owner=self.owner, \
+ time=time(), \
+ service=self.baseURL , \
+ username=self.username, \
+ password=self.password)
+ channels = client.find(name='cf-update-pv*')
+ for channel in channels:
+ self.assertTrue(unaffectedProperty in channel['properties'] and unaffectedTag in channel['tags'])
+ self.assertTrue(self.__check4properties({u'name':u'hostName', u'value':hostName}, channel['properties']) and
+ self.__check4properties({u'name':u'iocName', u'value':iocName}, channel['properties']) and
+ self.__check4properties({u'name':u'pvStatus', u'value':u'Active'}, channel['properties']),
+ 'Failed to update channels with the correct hostName and/or iocName')
+ self.assertTrue(not client.find(property=[('hostName', 'initialHost')]), 'Failed to cleanup old property')
+ self.assertTrue(not client.find(property=[('iocName', 'initialIoc')]), 'Failed to cleanup old property')
+ # Case 4:
+ updateChannelFinder([], \
+ hostName, \
+ iocName, \
+ owner=self.owner, \
+ time=time(), \
+ service=self.baseURL , \
+ username=self.username, \
+ password=self.password)
+ channels = client.find(name='cf-update-pv*')
+ for channel in channels:
+ self.assertTrue(unaffectedProperty in channel['properties'] and unaffectedTag in channel['tags'])
+ self.assertTrue(self.__check4properties({u'name':u'hostName', u'value':hostName}, channel['properties']) and
+ self.__check4properties({u'name':u'iocName', u'value':iocName}, channel['properties']) and
+ self.__check4properties({u'name':u'pvStatus', u'value':u'Inactive'}, channel['properties']),
+ 'Failed to update channels with the correct hostName and/or iocName')
+ self.assertTrue(not client.find(property=[('hostName', 'initialHost')]), 'Failed to cleanup old property')
+ self.assertTrue(not client.find(property=[('iocName', 'initialIoc')]), 'Failed to cleanup old property')
+
+ # Cleanup
+ '''
+ TODO this cleanup code should not be contingent to the successful completion of all checks...
+ This could pollute CF
+ '''
+ client.delete(channelName='cf-update-pv1')
+ client.delete(channelName='cf-update-pv2')
+ client.delete(propertyName=unaffectedProperty[u'name'])
+ client.delete(tagName=unaffectedTag[u'name'])
+
+ def __check4properties(self, prop, properties):
+ '''
+ check if property existing in a list of properties
+ The equality test will be based on the name and the value while ignoring the owner
+ '''
+ foundProp = [ p for p in properties if p[u'name'] == prop[u'name'] ]
+ if len(foundProp) == 1 and foundProp[0][u'value'] == prop[u'value']:
+ return True
+ else:
+ return False
+
+ def testNoneCheck(self):
+ self.assertTrue(ifNoneReturnDefault('Value', 'default') == 'Value')
+ self.assertTrue(ifNoneReturnDefault(None, 'default') == 'default')
+ self.assertTrue(ifNoneReturnDefault(None, None) == None)
+ self.assertTrue(ifNoneReturnDefault('', 'default') == '')
+
+ def testPVUpdate(self):
+ '''
+ Test condition
+ IOC turned on with ch1, ch2
+ IOC turned on with ch1 only
+ IOC turned on with ch1, ch2
+ '''
+ client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
+ try:
+ updateChannelFinder(['ch1', 'ch2'], \
+ 'testHost', \
+ 'testIOC', \
+ owner=self.owner, \
+ time=time(), \
+ service=self.baseURL, \
+ username=self.username, password=self.password)
+ chs = client.find(property=[('hostName', 'testHost'), ('iocName', 'testIOC'), ('pvStatus', 'Active')])
+ self.assertEqual(len(chs), 2, 'Expected 2 positive matches but found ' + str(len(chs)))
+ updateChannelFinder(['ch1'], \
+ 'testHost', \
+ 'testIOC', \
+ owner=self.owner, \
+ time=time(), \
+ service=self.baseURL, \
+ username=self.username, password=self.password)
+ chs = client.find(property=[('hostName', 'testHost'), ('iocName', 'testIOC'), ('pvStatus', 'Active')])
+ self.assertEqual(len(chs), 1, 'Expected 1 positive matches but found ' + str(len(chs)))
+ self.assertTrue(chs[0][u'name'] == 'ch1', 'channel with name ch1 not found')
+ chs = client.find(property=[('hostName', 'testHost'), ('iocName', 'testIOC'), ('pvStatus', 'Inactive')])
+ self.assertEqual(len(chs), 1, 'Expected 1 positive matches but found ' + str(len(chs)))
+ self.assertTrue(chs[0][u'name'] == 'ch2', 'channel with name ch2 not found')
+ updateChannelFinder(['ch1', 'ch2'], \
+ 'testHost', \
+ 'testIOC', \
+ owner=self.owner, \
+ time=time(), \
+ service=self.baseURL, \
+ username=self.username, password=self.password)
+ chs = client.find(property=[('hostName', 'testHost'), ('iocName', 'testIOC'), ('pvStatus', 'Active')])
+ self.assertEqual(len(chs), 2, 'Expected 2 positive matches but found ' + str(len(chs)))
+ finally:
+ client.delete(channelName='ch1')
+ client.delete(channelName='ch2')
+
+ def testPVMove(self):
+ '''
+ ch1, ch2 on host1, ioc1
+ ch1 on host1, ioc1; ch2 on host1, ioc2 (case1)
+ ch1, ch2 on host1, ioc1 (reset)
+ ch1 on host1, ioc1; ch2 on host2, ioc2 (case2)
+ ch1, ch2 on host1, ioc1 (reset)
+ '''
+ client = ChannelFinderClient(BaseURL=self.baseURL, username=self.username, password=self.password)
+ try:
+ updateChannelFinder(['ch1', 'ch2'], \
+ 'host1', \
+ 'ioc1', \
+ owner=self.owner, \
+ time=time(),\
+ service=self.baseURL, \
+ username=self.username, password=self.password)
+ chs = client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])
+ self.assertEqual(len(chs), 2, 'Expected 2 positive matches but found ' + str(len(chs)))
+ '''CASE1'''
+ updateChannelFinder(['ch1'], \
+ 'host1', \
+ 'ioc1', \
+ time=time(), \
+ owner=self.owner, service=self.baseURL, \
+ username=self.username, password=self.password)
+ updateChannelFinder(['ch2'], \
+ 'host1', \
+ 'ioc2', \
+ time=time(), \
+ owner=self.owner, service=self.baseURL, \
+ username=self.username, password=self.password)
+ chs = client.find(property=[('hostName', 'host1')])
+ self.assertEqual(len(chs), 2, 'Expected 1 positive matches but found ' + str(len(chs)))
+ self.assertEqual(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])[0][u'name'], 'ch1', \
+ 'Failed to find the expected channel _ch1_ with prop host1, ioc1')
+ self.assertEqual(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc2')])[0][u'name'], 'ch2', \
+ 'Failed to find the expected channel _ch2_ with prop host1, ioc2')
+ '''RESET'''
+ updateChannelFinder(['ch1', 'ch2'], \
+ 'host1', \
+ 'ioc1', \
+ time=time(), \
+ owner=self.owner, service=self.baseURL, \
+ username=self.username, password=self.password)
+ self.assertEqual(len(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])), 2, \
+ 'Failed to reset the channels')
+ '''CASE2'''
+ updateChannelFinder(['ch1'], \
+ 'host1', \
+ 'ioc1', \
+ owner=self.owner, \
+ time=time(), \
+ service=self.baseURL, username=self.username, \
+ password=self.password)
+ updateChannelFinder(['ch2'], \
+ 'host2', \
+ 'ioc2', \
+ owner=self.owner, service=self.baseURL, \
+ time=time(), \
+ username=self.username, password=self.password)
+ self.assertEqual(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])[0][u'name'], 'ch1', \
+ 'Failed to find the expected channel _ch1_ with prop host1, ioc1')
+ self.assertEqual(client.find(property=[('hostName', 'host2'), ('iocName', 'ioc2')])[0][u'name'], 'ch2', \
+ 'Failed to find the expected channel _ch2_ with prop host1, ioc2')
+ '''RESET'''
+ updateChannelFinder(['ch1', 'ch2'], \
+ 'host1', \
+ 'ioc1', \
+ owner=self.owner, \
+ time=time(), \
+ service=self.baseURL, \
+ username=self.username, password=self.password)
+ self.assertEqual(len(client.find(property=[('hostName', 'host1'), ('iocName', 'ioc1')])), 2, \
+ 'Failed to reset the channels')
+ finally:
+ client.delete(channelName='ch1')
+ client.delete(channelName='ch2')
+
+ def testRegularExperssion(self):
+ tempFile = NamedTemporaryFile(delete=False)
+ publicPVs = ['publicPV1', 'publicPV2', 'publicPV3']
+ privatePVS = ['_privatePV1', '_privatePV2']
+ allPVs = copy(publicPVs);
+ allPVs.extend(privatePVS)
+ for pv in allPVs:
+ tempFile.write(pv + '\n')
+ tempFile.close();
+ try:
+ pvNames = getPVNames(tempFile.name)
+ self.assertEqual(len(pvNames), len(allPVs), \
+ 'expected ' + str(len(allPVs)) + ' but got ' + str(len(pvNames)))
+ pvNames = getPVNames(tempFile.name, pattern='[^_]+')
+ self.assertEqual(len(pvNames), len(publicPVs), \
+ 'expected ' + str(len(allPVs)) + ' but got ' + str(len(publicPVs)))
+ self.assertTrue(frozenset(pvNames).issuperset(frozenset(publicPVs)), \
+ 'resulting pvNames contains invalid non public pvs')
+ self.assertTrue(frozenset(pvNames).isdisjoint(frozenset(privatePVS)), \
+ 'result pvNames contains invalid private pvs')
+ pass
+ finally:
+ os.remove(tempFile.name)
+ pass
+
+
+if __name__ == "__main__":
+ #import sys;sys.argv = ['', 'Test.testName']
+ unittest.main()
+
+
+class mockOpt():
+ def __init__(self, hostname, iocname, service=None):
+ self.hostname = hostname
+ self.iocname = iocname
+ self.service = service
+
diff --git a/test/ChannelFinderClientTest.py b/test/ChannelFinderClientTest.py
index 90b0894..2d993fe 100644
--- a/test/ChannelFinderClientTest.py
+++ b/test/ChannelFinderClientTest.py
@@ -77,7 +77,7 @@ def testEncodeChannel(self):
# print encodedChannel[u'channels'][u'channel']
print "TEST "+ str(encodedChannel[u'channels'][u'channel']) + " == " + str(self.channel)
self.assertTrue(encodedChannel[u'channels'][u'channel'] == self.channel)
-
+
def testEncodeChannels(self):
self.assertTrue(self.multiChannels == \
ChannelFinderClient()._ChannelFinderClient__encodeChannels(ChannelFinderClient()._ChannelFinderClient__decodeChannels(self.multiChannels)))
@@ -168,24 +168,24 @@ def testSetRemoveTag2Channel(self):
try:
self.client.set(tag=testTag)
self.client.set(tag=testTag, channelName=self.testChannels[0][u'name'])
-
+
self.assertTrue(checkTagOnChannel(self.client, 'pyTestChannel1', testTag) , \
'Error: Tag-pySetTag not added to the channel-pyTestChannel1')
-
+
self.client.set(tag=testTag, channelName=self.testChannels[1][u'name'])
# check if the tag has been added to the new channel and removed from the old channel
- self.assertTrue(checkTagOnChannel(self.client, self.testChannels[1][u'name'], testTag) and
+ self.assertTrue(checkTagOnChannel(self.client, self.testChannels[1][u'name'], testTag) and
not checkTagOnChannel(self.client, self.testChannels[0][u'name'], testTag), \
'Error: Tag-pySetTag not added to the channel-pyTestChannel2')
-
+
self.client.delete(tag=testTag, channelName=self.testChannels[1][u'name'])
self.assertTrue(not checkTagOnChannel(self.client, self.testChannels[1][u'name'], testTag), \
'Error: Failed to delete the tag-pySetTag from channel-pyTestChannel1')
finally:
self.client.delete(tagName=testTag[u'name'])
-
+
# TODO set a check for removing the tag from a subset of channels which have that tag
-
+
def testSetRemoveTag2Channels(self):
'''
Set tags to a set of channels and remove it from all other channels
@@ -220,7 +220,7 @@ def testUpdateTag(self):
'''Update tag with new channels'''
tag['channels'] = [self.testChannels[1], self.testChannels[2]]
self.clientTag.update(tag=tag)
-
+
for channel in self.testChannels:
self.assertTrue(checkTagOnChannel(self.client, channel['name'], tag), 'Failed to updated tag')
finally:
@@ -236,7 +236,7 @@ def testUpdateTags(self):
tag1['channels'] = [self.testChannels[0]]
tag2 = {'name':'pyTestTag2', 'owner':self.tagOwner}
tag2['channels'] = [self.testChannels[0]]
-
+
try:
'''Create initial tags which are set on the pyTestChannel1'''
self.clientTag.set(tags=[tag1,tag2])
@@ -252,7 +252,7 @@ def testUpdateTags(self):
checkTagOnChannel(self.client, channel['name'], tag2), \
'Failed to updated tags')
finally:
- '''cleanup'''
+ '''cleanup'''
self.client.delete(tagName=tag1['name'])
self.client.delete(tagName=tag2['name'])
self.assertIsNone(self.client.findTag(tag1['name']), 'failed to delete the test tag:'+tag1['name'])
@@ -282,7 +282,7 @@ def testGetAllTags(self):
#===============================================================================
class OperationPropertyTest(unittest.TestCase):
-
+
def setUp(self):
'''Default Owners'''
self.channelOwner = _testConf.get('DEFAULT', 'channelOwner')
@@ -395,22 +395,21 @@ def testSetRemoveProperty2Channel(self):
self.client.set(property=testProperty)
self.assertTrue(checkPropertyOnChannel(self.client, ch0[u'name'], testProperty) , \
'Error: Property - setTestProp not added to the channel-pyTestChannel1')
-
+
ch1 = self.testChannels[1]
ch1['properties'] = [ {'name':'setTestProp', 'owner':self.propOwner, 'value':'testValue2'} ]
testProperty['channels'] = [ch1]
self.client.set(property=testProperty)
'''check if the property has been added to the new channel and removed from the old channel'''
- self.assertTrue(checkPropertyOnChannel(self.client, ch1[u'name'], testProperty) and
+ self.assertTrue(checkPropertyOnChannel(self.client, ch1[u'name'], testProperty) and
not checkPropertyOnChannel(self.client, ch0[u'name'], testProperty), \
'Error: Tag-pySetTag not added to the channel-pyTestChannel2')
+ finally: # Delete operation causes an error if performed twice, IE: the first delete succeeded
'''delete the property and ensure it is removed from the associated channel'''
- self.client.delete(propertyName=testProperty['name'])
+ self.client.delete(propertyName=testProperty[u'name'])
self.assertTrue(not checkPropertyOnChannel(self.client, ch0[u'name'], testProperty) and \
- not checkPropertyOnChannel(self.client, ch1[u'name'], testProperty) , \
- 'Error: Failed to delete the tag-pySetTag from channel-pyTestChannel1')
- finally:
- self.client.delete(tagName=testProperty[u'name'])
+ not checkPropertyOnChannel(self.client, ch1[u'name'], testProperty), \
+ 'Error: Failed to delete the tag-pySetTag from channel-pyTestChannel1')
def testGetAllPropperties(self):
'''Test setting multiple properties and listing all tags'''
@@ -431,10 +430,10 @@ def testGetAllPropperties(self):
self.assertEqual(self.client.findProperty(propertyName=prop[u'name']), None, \
'Error: property ' + prop[u'name'] + ' was not removed')
#===============================================================================
-#
+#
#===============================================================================
class OperationChannelTest(unittest.TestCase):
-
+
def setUp(self):
'''Default Owners'''
self.channelOwner = _testConf.get('DEFAULT', 'channelOwner')
@@ -465,7 +464,7 @@ def testSetDeleteChannel(self):
self.assertTrue(len(result) == 1, 'incorrect number of channels returned')
self.assertTrue(result[0][u'name'] == u'pyTestChannelName', 'incorrect channel returned')
finally:
- self.clientCh.delete(channelName=testChannel[u'name'])
+ self.clientCh.delete(channelName=testChannel[u'name'])
result = self.client.find(name=u'pyTestChannelName')
self.assertFalse(result, 'incorrect number of channels returned')
@@ -509,7 +508,7 @@ def testSetRemoveChannels(self):
# delete each individually
for ch in testChannels:
self.clientCh.delete(channelName=str(ch[u'name']))
-
+
def testSetChannelsWithProperties(self):
'''
This method creates a set of channels and then updates the property values
@@ -521,10 +520,10 @@ def testSetChannelsWithProperties(self):
ch2 = {u'name':u'orgChannel2', u'owner':self.channelOwner, u'properties':[prop1, prop2]}
ch3 = {u'name':u'orgChannel3', u'owner':self.channelOwner, u'properties':[prop1]}
channels = [ch1, ch2, ch3]
-
+
self.client.set(property=prop1)
self.client.set(property=prop2)
-
+
self.client.set(channels=channels)
chs = self.client.find(property=[(u'originalProp1', u'originalVal'), \
(u'originalProp2', u'originalVal')])
@@ -541,20 +540,20 @@ def testSetChannelsWithProperties(self):
self.client.delete(propertyName=prop1[u'name'])
self.client.delete(propertyName=prop2[u'name'])
pass
-
+
def testDestructiveSetRemoveChannels(self):
'''
This test will check that a POST in the channels resources is destructive
'''
testProp = {u'name':u'testProp', u'owner' : self.propOwner}
- try:
+ try:
self.clientProp.set(property=testProp)
testProp[u'value'] = 'original'
testChannels = [{u'name':u'pyChannel1', u'owner':self.channelOwner, u'properties':[testProp]}, \
{u'name':u'pyChannel2', u'owner':self.channelOwner}, \
- {u'name':u'pyChannel3', u'owner':self.channelOwner}]
+ {u'name':u'pyChannel3', u'owner':self.channelOwner}]
self.clientCh.set(channel=testChannels[0])
-
+
self.assertEqual(len(self.client.find(name=u'pyChannel*')), 1, \
'Failed to set a single channel correctly')
result = self.client.find(name=u'pyChannel1')[0]
@@ -578,7 +577,7 @@ def testSetRemoveSpecialChar(self):
spTag = {u'name':u'special{}*', u'owner':self.tagOwner}
spChannel[u'properties'] = [spProperty]
spChannel[u'tags'] = [spTag]
-
+
try:
self.client.set(tag=spTag)
self.assertNotEqual(self.client.findTag(spTag[u'name']), None, 'failed to set Tag with special chars')
@@ -628,7 +627,7 @@ def testUpdateChannel(self):
self.client.set(tag=testTag2)
testChannel = {u'name':u'pyTestChannelName1', u'owner': self.channelOwner, u'properties':[testProp2], u'tags':[testTag2]}
self.clientCh.update(channel=testChannel)
-
+
result = self.client.find(name=u'pyTestChannelName1')
self.assertTrue(len(result) == 1, 'incorrect number of channels returned')
self.assertTrue(result[0][u'name'] == u'pyTestChannelName1', 'incorrect channel returned')
@@ -646,14 +645,14 @@ def testUpdateChannel(self):
#===============================================================================
# Update Opertation Tests
#===============================================================================
-'''
+
class UpdateOperationTest(unittest.TestCase):
def setUp(self):
- ''''''Default set of Owners''''''
+ '''Default set of Owners'''
self.channelOwner = _testConf.get('DEFAULT', 'channelOwner')
self.propOwner = _testConf.get('DEFAULT', 'propOwner')
self.tagOwner = _testConf.get('DEFAULT', 'tagOwner')
- ''''''Default set of clients''''''
+ '''Default set of clients'''
self.client = ChannelFinderClient()
self.clientCh = ChannelFinderClient(BaseURL=_testConf.get('DEFAULT', 'BaseURL'), \
username=_testConf.get('DEFAULT', 'channelUsername'), \
@@ -664,23 +663,23 @@ def setUp(self):
self.clientTag = ChannelFinderClient(BaseURL=_testConf.get('DEFAULT', 'BaseURL'), \
username=_testConf.get('DEFAULT', 'tagUsername'), \
password=_testConf.get('DEFAULT', 'tagPassword'))
- '''''' Test Properties and Tags ''''''
+ ''' Test Properties and Tags '''
self.orgTag = {u'name':u'originalTag', u'owner': self.tagOwner}
self.orgProp = {u'name':u'originalProp', u'owner':self.propOwner, u'value':u'originalValue'}
-
+
self.clientTag.set(tag=self.orgTag)
self.clientProp.set(property=self.orgProp)
-
+
self.clientCh.set(channel={u'name':u'originalChannelName', \
u'owner':self.channelOwner, \
u'properties':[self.orgProp], \
u'tags':[self.orgTag]})
ch = self.client.find(name=u'originalChannelName')
- self.assertTrue(len(ch) == 1 and
+ self.assertTrue(len(ch) == 1 and
self.orgProp in ch[0][u'properties'] and \
self.orgTag in ch[0][u'tags']);
pass
-
+
def UpdateTagName(self):
newTagName = 'updatedTag'
self.assertTrue(self.client.findTag(self.orgTag[u'name']) != None)
@@ -693,10 +692,11 @@ def UpdateTagName(self):
self.assertTrue(self.orgTag not in channelTags and \
{u'name':newTagName, u'owner':self.tagOwner} in channelTags)
self.clientTag.update(tag=self.orgTag, originalTagName=newTagName)
-
+
def testUpdateTagOwner(self):
+ '''Test implemented in testUpdateTag'''
pass
-
+
# removed test till bug in the sevice is fixed - channelfinder needs to check for the existance of oldname not name
def UpdatePropName(self):
newPropName = u'updatedProperty'
@@ -710,42 +710,42 @@ def UpdatePropName(self):
self.assertTrue(self.orgProp[u'name'] not in channelProperties.keys() and \
newPropName in channelProperties.keys())
self.clientProp.update(property=self.orgProp, originalPropertyName=newPropName)
-
-
+
+
def testUpdatePropOwner(self):
pass
-
+
def testUpdateChannelName(self):
ch = self.client.find(name=u'originalChannelName')[0]
- newChannel = {u'name':u'updatedChannelName', u'owner':ch.Owner, u'properties': ch[u'properties'], u'tags':ch[u'tags']}
+ newChannel = {u'name':u'updatedChannelName', u'owner': ch[u'owner'], u'properties': ch[u'properties'], u'tags': ch[u'tags']}
self.clientCh.update(originalChannelName=u'originalChannelName', \
channel=newChannel)
- self.assertTrue(self.client.find(name=u'originalChannelName') == None)
+ self.assertTrue(self.client.find(name=u'originalChannelName') == [])
self.assertTrue(len(self.client.find(name=u'updatedChannelName')) == 1)
# reset the channel back
self.clientCh.update(originalChannelName=u'updatedChannelName', \
channel=ch)
self.assertTrue(len(self.client.find(name=u'originalChannelName')) == 1)
- self.assertTrue(self.client.find(name=u'updatedChannelName') == None)
-
+ self.assertTrue(self.client.find(name=u'updatedChannelName') == [])
+
def UpdateChannelOwner(self):
ch = self.client.find(name='originalChannelName')[0]
newChannel = {u'name':ch[u'name'], u'owner':self.tagOwner, u'properties': ch[u'properties'], u'tags':ch[u'tags']}
self.clientCh.update(originalChannelName=u'originalChannelName', \
channel=newChannel)
- self.assertTrue(self.client.find(name=u'originalChannelName')[0].Owner == self.tagOwner)
+ self.assertTrue(self.client.find(name=u'originalChannelName')[0][u'owner'] == self.tagOwner)
pass
-
+
def testUpdateChannel(self):
- ''''''
+ '''
the test updates the channel name and owner
it also updates an existing property
and adds a new property and tag
leaving an existing tag untouched
-
+
TODO
using the lowest lever _tagOwner_ as the newOwner
- ''''''
+ '''
ch = self.client.find(name=u'originalChannelName')[0]
updatedProp = {u'name':u'originalProp', u'owner':self.propOwner, u'value':u'updatedValue'}
newTag = {u'name':u'updatedTag', u'owner':self.tagOwner}
@@ -760,12 +760,12 @@ def testUpdateChannel(self):
channel=newChannel)
foundChannel = self.client.find(name=u'updatedChannelName')[0]
self.assertTrue(foundChannel[u'name'] == u'updatedChannelName' and
- foundChannel.Owner == self.channelOwner and \
+ foundChannel[u'owner'] == self.channelOwner and \
updatedProp in foundChannel[u'properties'] and\
newProp in foundChannel[u'properties'] and \
newTag in foundChannel[u'tags'] and \
self.orgTag in foundChannel[u'tags'])
-
+
finally:
#reset
self.clientCh.update(originalChannelName='updatedChannelName', \
@@ -776,26 +776,74 @@ def testUpdateChannel(self):
self.clientTag.delete(tagName=newTag[u'name'])
if self.clientProp.findProperty(newProp[u'name']):
self.clientProp.delete(propertyName=newProp[u'name'])
-
+
def testUpdateChannel2(self):
- ''''''
+ '''
Update a channels using update(channel=updatedChannel)
- ''''''
- pass
-
+ '''
+ ch = self.client.find(name=u'originalChannelName')
+ self.assertTrue(len(ch) == 1 and
+ self.orgProp in ch[0][u'properties'] and
+ self.orgTag in ch[0][u'tags'])
+ updated_prop = {u'name': u'originalProp',
+ u'owner': self.propOwner,
+ u'value': u'newPropValue'}
+ self.clientCh.update(channel={u'name': u'originalChannelName',
+ u'owner': u'newOwner',
+ u'properties': [updated_prop],
+ u'tags': []})
+ ch = self.client.find(name=u'originalChannelName')
+ self.assertTrue(len(ch) == 1 and
+ updated_prop in ch[0][u'properties'] and
+ self.orgTag in ch[0][u'tags'] and
+ ch[0][u'owner'] == u'newOwner')
+
+
def testUpdateProperty(self):
- ''''''
+ '''
Update a single property using update(property=updatedProperty)
- ''''''
- pass
-
+ Updates existing channels with new property owner, without altering original value.
+ '''
+ prop = self.client.findProperty(propertyName=u'originalProp')
+ self.assertDictEqual(prop, {u'owner': self.propOwner,
+ u'channels': [],
+ u'name': u'originalProp',
+ u'value': None})
+
+ updatedProperty = dict(prop)
+ updatedProperty[u'owner'] = u'newOwner'
+ self.clientProp.update(property=updatedProperty)
+ '''Check property owner'''
+ prop = self.client.findProperty(propertyName=u'originalProp')
+ self.assertDictEqual(prop, {u'owner': u'newOwner',
+ u'channels': [],
+ u'name': u'originalProp',
+ u'value': None})
+ '''Check existing channel'''
+ ch = self.client.find(name=u'originalChannelName')
+ self.assertTrue({u'owner': u'newOwner',
+ u'name': u'originalProp',
+ u'value': u'originalValue'} in ch[0][u'properties'])
+
def testUpdateTag(self):
- ''''''
+ '''
Update a single tag using update(tag=updatedTag)
- ''''''
- pass
-
-
+ Updates owner in all associated channels.
+ '''
+ tag = self.client.findTag(tagName=u'originalTag')
+ self.assertDictEqual(tag, {u'owner': self.tagOwner, u'channels': [], u'name': u'originalTag'})
+
+ updatedTag = dict(tag)
+ updatedTag[u'owner'] = u'newOwner'
+ self.clientTag.update(tag=updatedTag)
+ '''Check tag owner'''
+ tag = self.client.findTag(tagName=u'originalTag')
+ self.assertDictEqual(tag, {u'owner': u'newOwner', u'channels': [], u'name': u'originalTag'})
+ '''Checks existing channel'''
+ ch = self.client.find(name=u'originalChannelName')
+ self.assertTrue({u'owner': u'newOwner',
+ u'name': u'originalTag'} in ch[0][u'tags'])
+
def tearDown(self):
self.clientCh.delete(channelName=u'originalChannelName')
self.clientTag.delete(tagName=u'originalTag')
@@ -807,13 +855,13 @@ def tearDown(self):
#===============================================================================
'''
class UpdateAppendTest(unittest.TestCase):
-
+
def setUp(self):
- ''''''Default Owners''''''
+ '''Default Owners'''
self.ChannelOwner = _testConf.get('DEFAULT', 'channelOwner')
self.propOwner = _testConf.get('DEFAULT', 'propOwner')
self.tagOwner = _testConf.get('DEFAULT', 'tagOwner')
- ''''''Default Client''''''
+ '''Default Client'''
self.client = ChannelFinderClient(BaseURL=_testConf.get('DEFAULT', 'BaseURL'), \
username=_testConf.get('DEFAULT', 'username'), \
password=_testConf.get('DEFAULT', 'password'))
@@ -823,7 +871,7 @@ def setUp(self):
self.clientTag = ChannelFinderClient(BaseURL=_testConf.get('DEFAULT', 'BaseURL'), \
username=_testConf.get('DEFAULT', 'tagUsername'), \
password=_testConf.get('DEFAULT', 'tagPassword'))
-
+
self.Tag1 = {u'name':u'tag1', u'owner':self.tagOwner}
self.Tag2 = {u'name':u'tag2', u'owner':self.tagOwner}
self.Prop1 = {u'name':u'prop1', u'owner':self.propOwner, u'value':u'initialVal'}
@@ -837,9 +885,9 @@ def setUp(self):
self.client.set(channels=self.channels)
# originally 1 channel has tag Tag1 and 2 channels have tag Tag2
self.assertTrue(len(self.client.find(tagName=self.Tag1[u'name'])) == 1)
- self.assertTrue(len(self.client.find(tagName=self.Tag2[u'name'])) == 2)
+ self.assertTrue(len(self.client.find(tagName=self.Tag2[u'name'])) == 2)
pass
-
+
def tearDown(self):
self.clientTag.delete(tagName=self.Tag1[u'name'])
self.clientTag.delete(tagName=self.Tag2[u'name'])
@@ -847,86 +895,87 @@ def tearDown(self):
self.clientProp.delete(propertyName=self.Prop2[u'name'])
for channel in self.channels:
self.client.delete(channelName=channel[u'name'])
- self.assertTrue(self.client.find(name=u'orgChannel?') == None)
+ self.assertTrue(self.client.find(name=u'orgChannel?') == [])
pass
-
+
def testUpdateAppendTag2Channel(self):
- ''''''
+ '''
Add tag to channel3 without removing it from the first 2 channels
- ''''''
+ '''
self.clientTag.update(tag=self.Tag2, channelName=self.ch3[u'name'])
self.assertTrue(len(self.client.find(tagName=self.Tag2[u'name'])) == 3)
-
+
def testUpdateAppendTag2Channels(self):
- ''''''
+ '''
Add tag to channels 2-3 without removing it from channel 1
- ''''''
- channelNames = [ channel[u'name'] for channel in self.channels]
+ '''
+ channelNames = [channel[u'name'] for channel in self.channels]
self.clientTag.update(tag=self.Tag1, channelNames=channelNames)
self.assertTrue(len(self.client.find(tagName=self.Tag1[u'name'])) == 3)
def testUpdateAppendProperty2Channel(self):
- ''''''
- Test to update a channel with a property
- ''''''
- self.assertTrue(len(self.client.find(name=self.ch3[u'name'])) == 1 and \
- self.client.find(name=self.ch3[u'name'])[0][u'properties'] == None, \
+ '''
+ Test to update a channel with a property
+ '''
+ self.assertTrue(len(self.client.find(name=self.ch3[u'name'])) == 1 and
+ self.client.find(name=self.ch3[u'name'])[0][u'properties'] == [],
'the channel already has properties')
self.clientProp.update(property=self.Prop1, channelName=self.ch3[u'name'])
- self.assertTrue(len(self.client.find(name=self.ch3[u'name'])) == 1 and \
- self.Prop1 in self.client.find(name=self.ch3[u'name'])[0][u'properties'], \
+ self.assertTrue(len(self.client.find(name=self.ch3[u'name'])) == 1 and
+ self.Prop1 in self.client.find(name=self.ch3[u'name'])[0][u'properties'],
'failed to update the channel with a new property')
- ''''''Check that Value of the property is correctly added''''''
+ '''Check that Value of the property is correctly added'''
self.Prop2[u'value'] = 'val'
self.clientProp.update(property=self.Prop2, channelName=self.ch3[u'name'])
chs = self.client.find(name=self.ch3[u'name'])
- self.assertTrue(len(chs) == 1 and \
- self.Prop1 in chs[0][u'properties'] and \
- self.Prop2 in chs[0][u'properties'] , \
+ self.assertTrue(len(chs) == 1 and
+ self.Prop1 in chs[0][u'properties'] and
+ self.Prop2 in chs[0][u'properties'],
'Failed to update the channel with a new property without disturbing the old one')
self.client.set(channel=self.ch3)
-
+
def testUpdateAppendProperty2Channels(self):
- ''''''
+ '''
Update a channels with a property
- ''''''
- self.assertTrue(len(self.client.find(name=self.ch2[u'name'])) == 1 and \
- self.client.find(name=self.ch2[u'name'])[0][u'properties'] == None, \
+ '''
+ self.assertTrue(len(self.client.find(name=self.ch2[u'name'])) == 1 and
+ self.client.find(name=self.ch2[u'name'])[0][u'properties'] == [],
'the channel already has properties')
- self.assertTrue(len(self.client.find(name=self.ch3[u'name'])) == 1 and \
- self.client.find(name=self.ch3[u'name'])[0][u'properties'] == None, \
+ self.assertTrue(len(self.client.find(name=self.ch3[u'name'])) == 1 and
+ self.client.find(name=self.ch3[u'name'])[0][u'properties'] == [],
'the channel already has properties')
- self.Prop1[u'value'] = 'testVal'
+ self.Prop1[u'value'] = 'testVal'
self.clientProp.update(property=self.Prop1, channelNames=[self.ch2[u'name'], self.ch3[u'name']])
- self.assertTrue(len(self.client.find(name=self.ch2[u'name'])) == 1 and \
- self.Prop1 in self.client.find(name=self.ch2[u'name'])[0][u'properties'], \
+ self.assertTrue(len(self.client.find(name=self.ch2[u'name'])) == 1 and
+ self.Prop1 in self.client.find(name=self.ch2[u'name'])[0][u'properties'],
'failed to update the channel with a new property')
- self.assertTrue(len(self.client.find(name=self.ch3[u'name'])) == 1 and \
- self.Prop1 in self.client.find(name=self.ch3[u'name'])[0][u'properties'], \
+ self.assertTrue(len(self.client.find(name=self.ch3[u'name'])) == 1 and
+ self.Prop1 in self.client.find(name=self.ch3[u'name'])[0][u'properties'],
'failed to update the channel with a new property')
-
+
+ @unittest.skip("Skipping test for unimplemented functionality.")
def testUpdateRemoveProperty2Channel(self):
- ''''''
+ '''
Updating a single channel with a property value = empty string is interpreted as a delete property
- ''''''
+ '''
try:
self.client.set(channel={u'name':u'testChannel', u'owner':self.ChannelOwner, u'properties':[self.Prop1]})
channel = self.client.find(name=u'testChannel')
- self.assertTrue(len(channel) == 1 and self.Prop1[u'name'] in channel[0][u'properties'], \
+ self.assertTrue(len(channel) == 1 and self.Prop1 in channel[0][u'properties'],
'Failed to create a test channel with property prop1')
self.Prop1[u'value'] = ''
channel[0][u'properties'] = [self.Prop1]
self.client.update(channel=channel[0])
- self.assertFalse(self.client.find(name=u'testChannel')[0][u'properties'], \
+ self.assertFalse(self.client.find(name=u'testChannel')[0][u'properties'],
'Failed to deleted property prop1 form channel testChannel')
finally:
self.client.delete(channelName=u'testChannel')
-
+
def UserOwnerCheck(self):
- ''''''
+ '''
the _user_ belonging to cf-properties and another group(cf-asd) sets the owner = group
but should still be able to update the property
- ''''''
+ '''
try:
self.clientProp.set(property={u'name':u'testProperty', u'owner':'cf-asd'})
self.assertTrue({u'name':u'testProperty', u'owner':u'cf-asd'} in self.client.getAllProperties(), \
@@ -939,14 +988,14 @@ def UserOwnerCheck(self):
self.clientProp.delete(propertyName=u'testProperty')
self.client.delete(channelName=u'testChannel')
- '''
+
#===========================================================================
# Query Tests
#===========================================================================
class QueryTest(unittest.TestCase):
-
- def setUp(self):
+
+ def setUp(self):
'''Default Owners'''
self.ChannelOwner = _testConf.get('DEFAULT', 'channelOwner')
self.propOwner = _testConf.get('DEFAULT', 'propOwner')
@@ -960,27 +1009,27 @@ def setUp(self):
def tearDown(self):
pass
-
+
def testQueryChannel(self):
pass
-
+
def testEmptyReturn(self):
'''
find for non existing entities should return None instead of a 404
'''
self.assertEquals(len(self.client.find(name=u'NonExistingChannelName')), 0,\
'Failed to return None when searching for a non existing channel')
-
+
def MultiValueQuery(self):
'''
add multiple search values for the same parameter
Expected behaviour
-
+
Logically OR'ed
name=pattern1,pattern2 => return channels with name matching pattern1 OR pattern2
- propName=valPattern1, valPattern2 => return channels with property 'propName'
+ propName=valPattern1, valPattern2 => return channels with property 'propName'
with values matching valPattern1 OR valPattern2
-
+
Logically AND'ed
tagName=pattern1, pattern2 => return channels with tags matching pattern1 AND pattern2
'''
@@ -1029,7 +1078,7 @@ def MultiValueQuery(self):
chs = self.client.find(property=[(u'propA', '1'), (u'propA', 'a')])
self.assertEqual(len(chs), 2, \
'Failed of query propA expected 2 found ' + str(len(chs)))
-
+
''' Check Find with multiple parameters '''
chs = self.client.find(name=u'pyTestChannel*', \
tagName=tagA[u'name'], \
@@ -1038,24 +1087,24 @@ def MultiValueQuery(self):
chs = self.client.find(name=u'pyTestChannel*', \
tagName=tagA[u'name'], \
property=[('propA', 'a')])
- self.assertEqual(len(chs), 1, u'expected 1 found ' + str(len(chs)))
-
+ self.assertEqual(len(chs), 1, u'expected 1 found ' + str(len(chs)))
+
self.client.delete(channelName=u'pyTestChannelA')
self.client.delete(channelName=u'pyTestChannelB')
self.client.delete(channelName=u'pyTestChannelAB')
-
+
self.client.delete(tagName=tagA[u'name'])
self.client.delete(tagName=tagB[u'name'])
self.client.delete(propertyName=propA[u'name'])
self.client.delete(propertyName=propB[u'name'])
-
-
-
+
+
+
#===============================================================================
# ERROR tests
#===============================================================================
class ErrorTest(unittest.TestCase):
-
+
def setUp(self):
'''Default Owners'''
self.ChannelOwner = _testConf.get('DEFAULT', 'channelOwner')
@@ -1065,49 +1114,49 @@ def setUp(self):
self.client = ChannelFinderClient(BaseURL=_testConf.get('DEFAULT', 'BaseURL'), \
username=_testConf.get('DEFAULT', 'username'), \
password=_testConf.get('DEFAULT', 'password'))
-
+
self.client.set(property={u'name':'existingProperty',u'owner': self.propOwner})
-
+
def tearDown(self):
self.client.delete(propertyName='existingProperty')
-
+
def testSetChannelWithNonExistingProp(self):
self.assertRaises(Exception, \
self.client.set, \
channel={u'name':u'channelName', \
u'owner':self.ChannelOwner, \
u'properties':[{u'name':u'nonExisitngProperty', u'owner':u'owner'}]})
-
+
def testSetChannelWithNonExistingTag(self):
self.assertRaises(Exception, \
self.client.set, \
channel={u'name':'channelName', \
u'owner':self.ChannelOwner, \
u'tags':[{u'name':u'nonExisitngTag', u'owner':u'owner'}]})
-
+
def testUpdateChannelWithNonExistingProp(self):
self.assertRaises(Exception, \
self.client.update, \
channel={u'name':u'channelName', \
u'owner':self.ChannelOwner, \
u'properties':[{u'name':u'nonExisitngProperty', u'owner':u'owner'}]})
-
+
def testUpdateChannelWithNonExistingTag(self):
self.assertRaises(Exception,
self.client.update,
channel={u'name':u'channelName', \
u'owner':self.ChannelOwner, \
u'tags':[{u'name':'nonExisitngTag', u'owner':u'owner'}]})
-
+
def testUpdateNonExistingChannel(self):
pass
-
+
def testUpdateNonExistingProperty(self):
pass
-
+
def testUpdateNoneExistingTag(self):
pass
-
+
def testIncorrectFindArguments(self):
self.assertRaises(Exception, \
self.client.find, \
@@ -1118,7 +1167,7 @@ def testIncorrectFindArguments(self):
self.assertRaises(Exception, \
self.client.find, \
tag='zzz')
-
+
def testCreateChannelWithNullPropertyValue(self):
self.assertRaises(Exception, \
self.client.set, \
@@ -1127,7 +1176,7 @@ def testCreateChannelWithNullPropertyValue(self):
u'properties':[{u'name':u'existingProperty', u'owner':self.propOwner}]})
self.assertFalse(self.client.find(name=u'channelName'), \
'Failed: should not be able to create a channel with a property with value null')
-
+
def testUpdateChannelWithNullPropertyValue(self):
self.client.set(channel={u'name':u'channelName', \
u'owner':self.ChannelOwner})
@@ -1143,7 +1192,7 @@ def testUpdateChannelWithNullPropertyValue(self):
'Failed: should not be able to update a channel with a property with value null')
finally:
self.client.delete(channelName=u'channelName')
-
+
def testCreateChannelWithEmptyPropertyValue(self):
self.assertRaises(Exception, \
self.client.set, \
@@ -1152,7 +1201,7 @@ def testCreateChannelWithEmptyPropertyValue(self):
u'properties':[{u'name':u'existingProperty', u'owner':self.propOwner, u'value':''}]})
self.assertFalse(self.client.find(name=u'channelName'), \
'Failed: should not be able to create a channel with a property with empty value string')
-
+
def UpdateChannelWithEmptyPropertyValue(self):
self.client.set(channel={u'name':u'channelName', \
u'owner':self.ChannelOwner})
diff --git a/test/_testConf.py b/test/_testConf.py
index 9248170..4424e1e 100644
--- a/test/_testConf.py
+++ b/test/_testConf.py
@@ -15,7 +15,7 @@
def __loadConfig():
import os.path
import ConfigParser
- dflt={'BaseURL':'https://localhost:9191/ChannelFinder',
+ dflt={'BaseURL':'https://localhost:8181/ChannelFinder',
'username' : 'cf-update',
'password' : '1234',
'owner' : 'cf-update',
diff --git a/test/cf-property-manager-unittest.py b/test/cf-property-manager-unittest.py
index 4849561..ad46d83 100644
--- a/test/cf-property-manager-unittest.py
+++ b/test/cf-property-manager-unittest.py
@@ -1,7 +1,9 @@
import unittest
-import CFPropertyManager
+from channelfinder.cfPropertyManager import CFPropertyManager
import re
import os
+from _testConf import _testConf
+
class CFPropertyManagerTest(unittest.TestCase):
cfglines = []
@@ -21,6 +23,9 @@ def test_dbl_read(self):
'''
Tests accessibility of cfg file, does not check format
'''
+ CFPropertyManager.SERVICE_URL=_testConf.get('DEFAULT', 'BaseURL')
+ CFPropertyManager.username=_testConf.get('DEFAULT', 'username')
+ CFPropertyManager.password=_testConf.get('DEFAULT', 'password')
CFPropertyManager.startClient()
fo = open("cf-property-manager-test-dbl", "w+")
fo.write("UT:RF-Cu:1{LD}Time:ShtDwn-I");
@@ -54,6 +59,10 @@ def test_regex(self):
'''
Tests validity of regular expression.
'''
+ fo = open("cf-property-manager-test-cfg", "w+")
+ fo.write("devName=[{][^:}][^:}]*\ndevType=[:][^{]*?[:}](?!.*[{])\nIGNORE=.*WtrSkid.*");
+ fo.close()
+ cfglines = CFPropertyManager.readConfiguration("cf-property-manager-test-cfg")
for properties in cfglines:
expression=None
print properties[0] + " = " + properties[1]
@@ -71,6 +80,9 @@ def test_cfg_read(self):
Tests accessibility of cfg file, does not check format
'''
global cfglines
+ CFPropertyManager.SERVICE_URL=_testConf.get('DEFAULT', 'BaseURL')
+ CFPropertyManager.username=_testConf.get('DEFAULT', 'username')
+ CFPropertyManager.password=_testConf.get('DEFAULT', 'password')
CFPropertyManager.startClient()
fo = open("cf-property-manager-test-cfg", "w+")
fo.write("devName=[{][^:}][^:}]*\ndevType=[:][^{]*?[:}](?!.*[{])\nIGNORE=.*WtrSkid.*");