You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by rj...@apache.org on 2014/03/06 09:47:30 UTC
svn commit: r1574802 - in
/bloodhound/trunk/bloodhound_relations/bhrelations: tests/api.py
validation.py
Author: rjollos
Date: Thu Mar 6 08:47:29 2014
New Revision: 1574802
URL: http://svn.apache.org/r1574802
Log:
0.8dev: It was not possible to create multiple //is a parent of// relations. Refs #775.
Modified:
bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py
bloodhound/trunk/bloodhound_relations/bhrelations/validation.py
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py?rev=1574802&r1=1574801&r2=1574802&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py Thu Mar 6 08:47:29 2014
@@ -224,13 +224,13 @@ class ApiTestCase(BaseRelationsTestCase)
parent2 = self._insert_and_load_ticket("A3")
#act
relations_system = self.relations_system
- relations_system.add(child, parent1, "parent")
+ relations_system.add(parent1, child, 'parent')
self.assertRaises(
ValidationError,
relations_system.add,
- child,
parent2,
- "parent")
+ child,
+ 'parent')
def test_can_not_add_more_than_one_parents_via_children(self):
#arrange
@@ -239,12 +239,12 @@ class ApiTestCase(BaseRelationsTestCase)
parent2 = self._insert_and_load_ticket("A3")
#act
relations_system = self.relations_system
- relations_system.add(parent1, child, "children")
+ relations_system.add(child, parent1, "children")
self.assertRaises(
ValidationError,
relations_system.add,
- parent2,
child,
+ parent2,
"children")
def test_ticket_can_be_resolved(self):
@@ -254,13 +254,13 @@ class ApiTestCase(BaseRelationsTestCase)
parent2 = self._insert_and_load_ticket("A3")
#act
relations_system = self.relations_system
- relations_system.add(parent1, child, "children")
- self.assertRaises(
- ValidationError,
- relations_system.add,
- parent2,
- child,
- "children")
+ relations_system.add(child, parent1, "children")
+
+ self.req.args['action'] = 'resolve'
+ warnings = \
+ TicketRelationsSpecifics(self.env).validate_ticket(self.req, child)
+
+ self.assertEqual(0, len(list(warnings)))
def test_can_save_and_load_relation_time(self):
#arrange
@@ -397,53 +397,53 @@ class ApiTestCase(BaseRelationsTestCase)
def test_cannot_create_other_relations_between_descendants(self):
t1, t2, t3, t4, t5 = map(self._insert_and_load_ticket, "12345")
- self.relations_system.add(t4, t2, "parent") # t1 -> t2
- self.relations_system.add(t3, t2, "parent") # / \
- self.relations_system.add(t2, t1, "parent") # t3 t4
+ self.relations_system.add(t2, t4, "parent") # t1 -> t2
+ self.relations_system.add(t2, t3, "parent") # / \
+ self.relations_system.add(t1, t2, "parent") # t3 t4
self.assertRaises(
ValidationError,
- self.relations_system.add, t1, t2, "dependent"
+ self.relations_system.add, t2, t1, "dependent"
)
self.assertRaises(
ValidationError,
- self.relations_system.add, t2, t1, "dependent"
+ self.relations_system.add, t1, t2, "dependent"
)
self.assertRaises(
ValidationError,
- self.relations_system.add, t1, t4, "dependent"
+ self.relations_system.add, t4, t1, "dependent"
)
self.assertRaises(
ValidationError,
- self.relations_system.add, t3, t1, "dependent"
+ self.relations_system.add, t1, t3, "dependent"
)
try:
- self.relations_system.add(t1, t5, "dependent")
- self.relations_system.add(t3, t4, "dependent")
+ self.relations_system.add(t5, t1,"dependent")
+ self.relations_system.add(t4, t3, "dependent")
except ValidationError:
self.fail("Could not add valid relation.")
def test_cannot_add_parent_if_this_would_cause_invalid_relations(self):
t1, t2, t3, t4, t5 = map(self._insert_and_load_ticket, "12345")
- self.relations_system.add(t4, t2, "parent") # t1 -> t2
- self.relations_system.add(t3, t2, "parent") # / \
- self.relations_system.add(t2, t1, "parent") # t3 t4 t5
- self.relations_system.add(t2, t5, "dependent")
+ self.relations_system.add(t2, t4, "parent") # t1 -> t2
+ self.relations_system.add(t2, t3, "parent") # / \
+ self.relations_system.add(t1, t2, "parent") # t3 t4 t5
+ self.relations_system.add(t5, t2, "dependent")
self.assertRaises(
ValidationError,
- self.relations_system.add, t5, t2, "parent"
+ self.relations_system.add, t2, t5, "parent"
)
self.assertRaises(
ValidationError,
- self.relations_system.add, t5, t3, "parent"
+ self.relations_system.add, t3, t5, "parent"
)
self.assertRaises(
ValidationError,
- self.relations_system.add, t1, t5, "parent"
+ self.relations_system.add, t5, t1, "parent"
)
try:
- self.relations_system.add(t5, t1, "parent")
+ self.relations_system.add(t1, t5, "parent")
except ValidationError:
self.fail("Could not add valid relation.")
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/validation.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/validation.py?rev=1574802&r1=1574801&r2=1574802&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/validation.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/validation.py Thu Mar 6 08:47:29 2014
@@ -186,15 +186,19 @@ class NoSelfReferenceValidator(Validator
class OneToManyValidator(Validator):
+ """Only tree relationships are allowed. A ticket cannot have multiple
+ parents."""
def validate(self, relation):
rls = RelationsSystem(self.env)
- existing_relations = rls._select_relations(relation.source,
- relation.type)
+ if relation.type != rls.PARENT_RELATION_TYPE:
+ return
+ existing_relations = rls._select_relations(relation.destination,
+ rls.CHILDREN_RELATION_TYPE)
if existing_relations:
raise ValidationError(
tag_("Resource %(source)s can only have one %(relation)s "
"relation.",
- source=tag.em(relation.source),
+ source=tag.em(relation.destination),
relation=tag.b(self.render_relation_type(relation.type)))
)
Re: svn commit: r1574802 - in /bloodhound/trunk/bloodhound_relations/bhrelations:
tests/api.py validation.py
Posted by Anže Starič <an...@gmail.com>.
OneToMany validator can be added to any relation in the config. And it
is always called with the master relation (even when you create a
child relation, validator will be called with the parent relation), so
I do no not think that any relation type checking is required.
2014-03-06 10:07 GMT+01:00 Ryan Ollos <ry...@wandisco.com>:
> On Thu, Mar 6, 2014 at 12:55 AM, Anže Starič <an...@gmail.com> wrote:
>
>> 2014-03-06 9:47 GMT+01:00 <rj...@apache.org>:
>> > class OneToManyValidator(Validator):
>> > + """Only tree relationships are allowed. A ticket cannot have
>> multiple
>> > + parents."""
>> > def validate(self, relation):
>> > rls = RelationsSystem(self.env)
>> > - existing_relations = rls._select_relations(relation.source,
>> > - relation.type)
>> > + if relation.type != rls.PARENT_RELATION_TYPE:
>> > + return
>> > + existing_relations = rls._select_relations(relation.destination,
>> > +
>> rls.CHILDREN_RELATION_TYPE)
>>
>> I would prefer something like:
>>
>> - existing_relations = rls._select_relations(relation.source,
>> - relation.type)
>> + existing_relations = rls._select_relations(type=relation.type,
>> +
>> destination=relation.destination)
>>
>> (and modified select_relations method so it can also filter by
>> destination).
>> This way, validator would remain reusable.
>>
>
> That does seem more clear. I wasn't very happy with the inverted logic, but
> I didn't look at the possibility of changing _select_relations. I won't
> complain if you refactor my changes ;)
>
> In what contexts do you see it being reusable? Do you plan to extract
> rls.PARENT_RELATION_TYPE to a class variable, or in some way make
> OneToManyValidator usable as a base class?
Re: svn commit: r1574802 - in /bloodhound/trunk/bloodhound_relations/bhrelations:
tests/api.py validation.py
Posted by Ryan Ollos <ry...@wandisco.com>.
On Thu, Mar 6, 2014 at 12:55 AM, Anže Starič <an...@gmail.com> wrote:
> 2014-03-06 9:47 GMT+01:00 <rj...@apache.org>:
> > class OneToManyValidator(Validator):
> > + """Only tree relationships are allowed. A ticket cannot have
> multiple
> > + parents."""
> > def validate(self, relation):
> > rls = RelationsSystem(self.env)
> > - existing_relations = rls._select_relations(relation.source,
> > - relation.type)
> > + if relation.type != rls.PARENT_RELATION_TYPE:
> > + return
> > + existing_relations = rls._select_relations(relation.destination,
> > +
> rls.CHILDREN_RELATION_TYPE)
>
> I would prefer something like:
>
> - existing_relations = rls._select_relations(relation.source,
> - relation.type)
> + existing_relations = rls._select_relations(type=relation.type,
> +
> destination=relation.destination)
>
> (and modified select_relations method so it can also filter by
> destination).
> This way, validator would remain reusable.
>
That does seem more clear. I wasn't very happy with the inverted logic, but
I didn't look at the possibility of changing _select_relations. I won't
complain if you refactor my changes ;)
In what contexts do you see it being reusable? Do you plan to extract
rls.PARENT_RELATION_TYPE to a class variable, or in some way make
OneToManyValidator usable as a base class?
Re: svn commit: r1574802 - in /bloodhound/trunk/bloodhound_relations/bhrelations:
tests/api.py validation.py
Posted by Anže Starič <an...@gmail.com>.
2014-03-06 9:47 GMT+01:00 <rj...@apache.org>:
> class OneToManyValidator(Validator):
> + """Only tree relationships are allowed. A ticket cannot have multiple
> + parents."""
> def validate(self, relation):
> rls = RelationsSystem(self.env)
> - existing_relations = rls._select_relations(relation.source,
> - relation.type)
> + if relation.type != rls.PARENT_RELATION_TYPE:
> + return
> + existing_relations = rls._select_relations(relation.destination,
> + rls.CHILDREN_RELATION_TYPE)
I would prefer something like:
- existing_relations = rls._select_relations(relation.source,
- relation.type)
+ existing_relations = rls._select_relations(type=relation.type,
+
destination=relation.destination)
(and modified select_relations method so it can also filter by destination).
This way, validator would remain reusable.