You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by an...@apache.org on 2013/04/30 16:42:05 UTC
svn commit: r1477669 - in
/bloodhound/trunk/bloodhound_relations/bhrelations: api.py model.py
tests/api.py
Author: andrej
Date: Tue Apr 30 14:42:05 2013
New Revision: 1477669
URL: http://svn.apache.org/r1477669
Log:
adding author and time fields to bhrealations model- towards BEP-0006
Modified:
bloodhound/trunk/bloodhound_relations/bhrelations/api.py
bloodhound/trunk/bloodhound_relations/bhrelations/model.py
bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/api.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/api.py?rev=1477669&r1=1477668&r2=1477669&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/api.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/api.py Tue Apr 30 14:42:05 2013
@@ -124,6 +124,8 @@ class RelationsSystem(Component):
destination_resource_instance,
relation_type,
comment = None,
+ author = None,
+ when = None,
):
source = ResourceIdSerializer.get_resource_id_from_instance(
self.env, source_resource_instance)
@@ -134,6 +136,8 @@ class RelationsSystem(Component):
relation.destination = destination
relation.type = relation_type
relation.comment = comment
+ relation.author = author
+ relation.when = when
self.add_relation(relation)
def add_relation(self, relation):
@@ -187,7 +191,9 @@ class RelationsSystem(Component):
destination=ResourceIdSerializer.get_resource_by_id(
relation.destination),
type = relation.type,
- comment = relation.comment
+ comment = relation.comment,
+ when = relation.when,
+ author = relation.author,
))
return relation_list
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/model.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/model.py?rev=1477669&r1=1477668&r2=1477669&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/model.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/model.py Tue Apr 30 14:42:05 2013
@@ -19,6 +19,7 @@
# under the License.
from bhdashboard.model import ModelBase
from trac.resource import Resource
+from trac.util.datefmt import to_utimestamp, from_utimestamp
class Relation(ModelBase):
@@ -28,32 +29,39 @@ class Relation(ModelBase):
_meta = {'table_name':'bloodhound_relations',
'object_name':'Relation',
'key_fields':['source', 'type', 'destination'],
- 'non_key_fields':['comment'],
+ 'non_key_fields':[
+ 'comment',
+ 'author',
+ {'name': 'time','type': 'int64'},
+ ],
'no_change_fields':['source', 'destination', 'type'],
'unique_fields':[],
- # 'auto_inc_fields': ['id'],
}
- # _meta = {'table_name':'bloodhound_relations',
- # 'object_name':'Relation',
- # 'key_fields':['id'],
- # 'non_key_fields':['source', 'destination', 'type', 'comment'],
- # 'no_change_fields':['source', 'destination', 'type'],
- # 'unique_fields':['source', 'destination', 'type'],
- # 'auto_inc_fields': ['id'],
- # }
-
@property
def resource(self):
"""Allow Relation to be treated as a Resource"""
return Resource('relation', self.prefix)
+ @property
+ def when(self):
+ when_ts = self._data.get("time")
+ if when_ts is not None:
+ return from_utimestamp(when_ts)
+ return None
+
+ @when.setter
+ def when(self, value):
+ when_ts = to_utimestamp(value)
+ self._data["time"] = when_ts
+
def clone_reverted(self, type):
+ data = self._data.copy()
+ data["type"] = type
+ data["source"] = self.destination
+ data["destination"] = self.source
relation = Relation(self._env)
- relation.source = self.destination
- relation.destination = self.source
- relation.comment = self.comment
- relation.type = type
+ relation._data = data
return relation
def get_relation_id(self):
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py?rev=1477669&r1=1477668&r2=1477669&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py Tue Apr 30 14:42:05 2013
@@ -17,6 +17,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+from datetime import datetime
from _sqlite3 import OperationalError, IntegrityError
from bhrelations.api import EnvironmentSetup, RelationsSystem, CycleValidationError, ParentValidationError, TicketRelationsSpecifics
from trac.ticket.model import Ticket
@@ -309,6 +310,17 @@ class ApiTestCase(unittest.TestCase):
child,
"children")
+ def test_can_save_and_load_relation_time(self):
+ #arrange
+ ticket1 = self._insert_and_load_ticket("A1")
+ ticket2 = self._insert_and_load_ticket("A2")
+ #act
+ time = datetime.now(utc)
+ self.relations_system.add(ticket1, ticket2, "dependent", when=time)
+ relations = self.relations_system.get_relations(ticket1)
+ #assert
+ self.assertEqual(time, relations[0]["when"])
+
def test_blocked_ticket_cannot_be_resolved(self):
ticket1 = self._insert_and_load_ticket("A1")
ticket2 = self._insert_and_load_ticket("A2")
@@ -318,6 +330,7 @@ class ApiTestCase(unittest.TestCase):
ticket_relations = TicketRelationsSpecifics(self.env)
warnings = ticket_relations.validate_ticket(self.req, ticket1)
self.assertEqual(1, len(list(warnings)))
+ #todo: fix the implementation to pass the test
#todo: add tests that relation were deleted when ticket was deleted