Advertisement
praveen97uma

test_tags.py

Mar 26th, 2011
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.18 KB | None | 0 0
  1. #!/usr/bin/env python2.5
  2.  
  3.  
  4. from soc.logic import tags
  5. from tests.test_utils import DjangoTestCase
  6.  
  7. class TagsServiceTest(DjangoTestCase):
  8.   """Test for tags service
  9.  """
  10.   def setUp(self):
  11.     self.init()
  12.     self.tags_service=tags.TagsService({
  13.       'test_tag1':0,
  14.       'test_tag2':0,
  15.       'test_tag3':0
  16.       })
  17.     self.fields = {
  18.       'test_tag1':1,
  19.       'test_tag4':4,
  20.       'test_tag3':3,
  21.       'test_tag2':2
  22.       }
  23.     self.entity=self.org
  24.      
  25.   def testPrepareTagsForStoring(self):
  26.     """asserts that the tags to be stored are generated as expected
  27.    """
  28.     actualFields=self.fields.copy()
  29.     expectedFields={
  30.       'test_tag1':{'tags':1,'scope':'soc'},
  31.       'test_tag3':{'tags':3,'scope':'soc'},
  32.       'test_tag4':4
  33.       }
  34.     self.tags_service.prepareTagsForStoring(actualFields,'soc')
  35.     self.assertNotEqual(actualFields,expectedFields)
  36.     expectedFields.update({'test_tag2':{'tags':2,'scope':'soc'}})
  37.     self.assertEqual(actualFields,expectedFields)
  38.  
  39.   def testSetTagValuesForEntity(self):
  40.     """Asserts if the tags for the entity is set"""
  41.     self.tags_service.setTagValuesForEntity(self.entity,self.fields)
  42.     actualTagFields={'test_tag1': 1,'test_tag3':3,'test_tag2':2}
  43.     expectedEntityTags=dict([(attr,getattr(self.entity,attr)) for attr in actualTagFields ])
  44.     self.assertNotEqual(self.fields,expectedEntityTags)
  45.     self.assertEqual(actualTagFields,expectedEntityTags)
  46.    
  47.   def testRemoveTagsForEntity(self):
  48.     """Asserts if the given tags are removed from the entity attributes"""
  49.     self.tags_service.setTagValuesForEntity(self.entity,self.fields)
  50.     TagsToRemove=['test_tag1','test_tag2']
  51.     self.tags_service.removeTagsForEntity(self.entity,TagsToRemove)
  52.     #tags that are presently set for the entity
  53.     actualTagFields={'test_tag1': 1,'test_tag3':3,'test_tag2':2}
  54.     remEntityTags={'test_tag3':3}
  55.     expectedEntityTags={}
  56.     #get tag,value from entity attributes
  57.     for attr in actualTagFields:
  58.        try:
  59.           val=getattr(self.entity,attr)
  60.           expectedEntityTags.update(dict(attr,v))
  61.        except:
  62.           pass
  63.    
  64.     assertEqual(remEntityTags,expectedEntityTags)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement