Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python2.5
- from soc.logic import tags
- from tests.test_utils import DjangoTestCase
- class TagsServiceTest(DjangoTestCase):
- """Test for tags service
- """
- def setUp(self):
- self.init()
- self.tags_service=tags.TagsService({
- 'test_tag1':0,
- 'test_tag2':0,
- 'test_tag3':0
- })
- self.fields = {
- 'test_tag1':1,
- 'test_tag4':4,
- 'test_tag3':3,
- 'test_tag2':2
- }
- self.entity=self.org
- def testPrepareTagsForStoring(self):
- """asserts that the tags to be stored are generated as expected
- """
- actualFields=self.fields.copy()
- expectedFields={
- 'test_tag1':{'tags':1,'scope':'soc'},
- 'test_tag3':{'tags':3,'scope':'soc'},
- 'test_tag4':4
- }
- self.tags_service.prepareTagsForStoring(actualFields,'soc')
- self.assertNotEqual(actualFields,expectedFields)
- expectedFields.update({'test_tag2':{'tags':2,'scope':'soc'}})
- self.assertEqual(actualFields,expectedFields)
- def testSetTagValuesForEntity(self):
- """Asserts if the tags for the entity is set"""
- self.tags_service.setTagValuesForEntity(self.entity,self.fields)
- actualTagFields={'test_tag1': 1,'test_tag3':3,'test_tag2':2}
- expectedEntityTags=dict([(attr,getattr(self.entity,attr)) for attr in actualTagFields ])
- self.assertNotEqual(self.fields,expectedEntityTags)
- self.assertEqual(actualTagFields,expectedEntityTags)
- def testRemoveTagsForEntity(self):
- """Asserts if the given tags are removed from the entity attributes"""
- self.tags_service.setTagValuesForEntity(self.entity,self.fields)
- TagsToRemove=['test_tag1','test_tag2']
- self.tags_service.removeTagsForEntity(self.entity,TagsToRemove)
- #tags that are presently set for the entity
- actualTagFields={'test_tag1': 1,'test_tag3':3,'test_tag2':2}
- remEntityTags={'test_tag3':3}
- expectedEntityTags={}
- #get tag,value from entity attributes
- for attr in actualTagFields:
- try:
- val=getattr(self.entity,attr)
- expectedEntityTags.update(dict(attr,v))
- except:
- pass
- assertEqual(remEntityTags,expectedEntityTags)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement