You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by as...@apache.org on 2014/03/06 10:33:53 UTC
svn commit: r1574816 - in
/bloodhound/trunk/bloodhound_relations/bhrelations: api.py tests/api.py
validation.py
Author: astaric
Date: Thu Mar 6 09:33:53 2014
New Revision: 1574816
URL: http://svn.apache.org/r1574816
Log:
Refactor OneToManyValidator.
Modified:
bloodhound/trunk/bloodhound_relations/bhrelations/api.py
bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py
bloodhound/trunk/bloodhound_relations/bhrelations/validation.py
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/api.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/api.py?rev=1574816&r1=1574815&r2=1574816&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/api.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/api.py Thu Mar 6 09:33:53 2014
@@ -336,15 +336,19 @@ class RelationsSystem(Component):
return self._select_relations(resource_full_id)
def _select_relations(
- self, source, resource_type=None):
+ self, source=None, resource_type=None, destination=None):
#todo: add optional paging for possible umbrella tickets with
#a lot of child tickets
- where = dict(source=source)
+ where = dict()
+ if source:
+ where["source"] = source
if resource_type:
where["type"] = resource_type
order_by = ["destination"]
else:
order_by = ["type", "destination"]
+ if destination:
+ where["destination"] = destination
return Relation.select(
self.env,
where=where,
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py?rev=1574816&r1=1574815&r2=1574816&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py Thu Mar 6 09:33:53 2014
@@ -247,6 +247,16 @@ class ApiTestCase(BaseRelationsTestCase)
parent2,
"children")
+ def test_can_add_more_than_one_child(self):
+ parent = self._insert_and_load_ticket("A1")
+ child1 = self._insert_and_load_ticket("A2")
+ child2 = self._insert_and_load_ticket("A3")
+
+ relations_system = self.relations_system
+ relations_system.add(parent, child1, 'parent')
+ relations_system.add(parent, child2, 'parent')
+
+
def test_ticket_can_be_resolved(self):
#arrange
child = self._insert_and_load_ticket("A1")
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/validation.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/validation.py?rev=1574816&r1=1574815&r2=1574816&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/validation.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/validation.py Thu Mar 6 09:33:53 2014
@@ -190,15 +190,13 @@ class OneToManyValidator(Validator):
parents."""
def validate(self, relation):
rls = RelationsSystem(self.env)
- if relation.type != rls.PARENT_RELATION_TYPE:
- return
- existing_relations = rls._select_relations(relation.destination,
- rls.CHILDREN_RELATION_TYPE)
+ existing_relations = rls._select_relations(resource_type=relation.type,
+ destination=relation.destination)
if existing_relations:
raise ValidationError(
- tag_("Resource %(source)s can only have one %(relation)s "
- "relation.",
- source=tag.em(relation.destination),
+ tag_("Another resource is already related to %(destination)s "
+ "with %(relation)s relation.",
+ destination=tag.em(relation.destination),
relation=tag.b(self.render_relation_type(relation.type)))
)