minor fixes on DummyRelationRegistry and functional tests
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1082 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									2011cf593d
								
							
						
					
					
						commit
						b79cfea129
					
				
					 2 changed files with 32 additions and 3 deletions
				
			
		|  | @ -30,7 +30,7 @@ class BrowserTest(FunctionalTestCase): | ||||||
|         browser.addHeader('Accept-Language', 'en-US') |         browser.addHeader('Accept-Language', 'en-US') | ||||||
|         browser.open('http://localhost/++etc++site/default/@@contents.html') |         browser.open('http://localhost/++etc++site/default/@@contents.html') | ||||||
|         self.assert_(browser.isHtml) |         self.assert_(browser.isHtml) | ||||||
|         addLink = browser.getLink('Relations Registry') |         addLink = browser.getLink('Relation Registry') | ||||||
|         addLink.click() |         addLink.click() | ||||||
|         self.assert_(browser.isHtml) |         self.assert_(browser.isHtml) | ||||||
|         inp = browser.getControl(name='new_value') |         inp = browser.getControl(name='new_value') | ||||||
|  |  | ||||||
|  | @ -60,7 +60,9 @@ class DummyRelationRegistry(object): | ||||||
|         for r in self.relations: |         for r in self.relations: | ||||||
|             hit = True |             hit = True | ||||||
|             for k in kw: |             for k in kw: | ||||||
|                 if ((k == 'relationship' and r.__class__ != kw[k]) |                 #if ((k == 'relationship' and r.__class__ != kw[k]) | ||||||
|  |                 if ((k == 'relationship' | ||||||
|  |                         and r.getPredicateName() != kw[k].getPredicateName()) | ||||||
|                  or (k != 'relationship' |                  or (k != 'relationship' | ||||||
|                         and (not hasattr(r, k) or getattr(r, k) != kw[k]))): |                         and (not hasattr(r, k) or getattr(r, k) != kw[k]))): | ||||||
|                     hit = False |                     hit = False | ||||||
|  | @ -137,7 +139,7 @@ class IndexableRelationAdapter(object): | ||||||
|             return value |             return value | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| # convenience function: | # convenience functions: | ||||||
| 
 | 
 | ||||||
| def getRelations(first=None, second=None, third=None, relationships=None): | def getRelations(first=None, second=None, third=None, relationships=None): | ||||||
|     """ Return a sequence of relations matching the query specified by the |     """ Return a sequence of relations matching the query specified by the | ||||||
|  | @ -160,6 +162,33 @@ def getRelations(first=None, second=None, third=None, relationships=None): | ||||||
|             result.update(registry.query(**query)) |             result.update(registry.query(**query)) | ||||||
|         return result |         return result | ||||||
| 
 | 
 | ||||||
|  | def getRelationSingle(first, relationship): | ||||||
|  |     """ Returns the one and only relation for first having relationship | ||||||
|  |         or None if there is none. | ||||||
|  | 
 | ||||||
|  |         Raise an error if there is more than one hit. | ||||||
|  |     """ | ||||||
|  |     rels = getRelations(first, relationships=[relationship]) | ||||||
|  |     if len(rels) == 0: | ||||||
|  |         return None | ||||||
|  |     if len(rels) > 1: | ||||||
|  |         raise ValueError('Multiple hits when only one relation expected: ' | ||||||
|  |                 '%s, relationship: %s' % (zapi.getName(first), | ||||||
|  |                                         relationship.getPredicateName())) | ||||||
|  |     return list(rels)[0] | ||||||
|  | 
 | ||||||
|  | def setRelationSingle(relation): | ||||||
|  |     """ Register the relation given, unregistering already existing | ||||||
|  |         relations for first and relationship. After this operation there | ||||||
|  |         will be only one relation for first with the relationship given. | ||||||
|  |     """ | ||||||
|  |     first = relation.first | ||||||
|  |     registry = zapi.getUtility(IRelationRegistry) | ||||||
|  |     rels = list(registry.query(first=first, relationship=relation)) | ||||||
|  |     for oldRel in rels: | ||||||
|  |         registry.unregister(oldRel) | ||||||
|  |     registry.register(relation) | ||||||
|  | 
 | ||||||
|          |          | ||||||
| # events and handlers | # events and handlers | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm