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/05/10 14:50:30 UTC
svn commit: r1480997 - in
/bloodhound/trunk/bloodhound_relations/bhrelations: api.py db_default.py
model.py templates/manage.html tests/__init__.py tests/api.py tests/mocks.py
Author: andrej
Date: Fri May 10 12:50:30 2013
New Revision: 1480997
URL: http://svn.apache.org/r1480997
Log:
implementing insert in tickets comments on bhrelation modification - towards BEP-0006
Added:
bloodhound/trunk/bloodhound_relations/bhrelations/tests/mocks.py
Modified:
bloodhound/trunk/bloodhound_relations/bhrelations/api.py
bloodhound/trunk/bloodhound_relations/bhrelations/db_default.py
bloodhound/trunk/bloodhound_relations/bhrelations/model.py
bloodhound/trunk/bloodhound_relations/bhrelations/templates/manage.html
bloodhound/trunk/bloodhound_relations/bhrelations/tests/__init__.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=1480997&r1=1480996&r2=1480997&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/api.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/api.py Fri May 10 12:50:30 2013
@@ -17,31 +17,75 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-from copy import copy
+from datetime import datetime
from bhrelations import db_default
from bhrelations.model import Relation
from multiproduct.api import ISupportMultiProductEnvironment
-from multiproduct.env import ProductEnvironment
-from trac.core import Component, implements, TracError
+from trac.core import (Component, implements, TracError, Interface,
+ ExtensionPoint)
from trac.env import IEnvironmentSetupParticipant
from trac.db import DatabaseManager
-from trac.resource import (manager_for_neighborhood, ResourceSystem, Resource,
+from trac.resource import (ResourceSystem, Resource,
get_resource_shortname, Neighborhood)
from trac.ticket import Ticket, ITicketManipulator, ITicketChangeListener
+from trac.util.datefmt import utc, to_utimestamp
PLUGIN_NAME = 'Bloodhound Relations Plugin'
-class CycleValidationError(TracError):
+
+class BaseValidationError(TracError):
+ def __init__(self, message, title=None, show_traceback=False):
+ super(BaseValidationError, self).__init__(
+ message, title, show_traceback)
+ self.failed_ids = []
+
+
+class CycleValidationError(BaseValidationError):
pass
-class ParentValidationError(TracError):
+
+class ParentValidationError(BaseValidationError):
pass
+
+#TODO: consider making the interface part of future
+# I[*|Resource]ChangingListener approach based on output from the
+# correlated discussion in Trac community
+# (http://trac.edgewall.org/ticket/11148)
+class IRelationChangingListener(Interface):
+ """
+ Extension point interface for components that require notification
+ when relations are created or deleted and database transaction is not
+ yet committed. The interface can be used when database actions have to be
+ made by listener must be performed within the same transaction as
+ relations modification.
+
+ Caution:
+ Because the database transaction is not yet committed during the event
+ notification, a long running listener activity may
+ influence overall database performance or raise lock
+ or transaction timeout errors. If component have to perform non-transaction
+ activity, use IRelationChanged interface instead.
+
+ If a listener raises an exception, all changes that were made within the
+ transaction will not be applied.
+ """
+
+ def adding_relation(relation):
+ """
+ Called when a relation was added but transaction was not committed.
+ """
+
+ def deleting_relation(relation, when):
+ """
+ Called when a relation was added but transaction was not committed.
+ """
+
+
class EnvironmentSetup(Component):
implements(IEnvironmentSetupParticipant, ISupportMultiProductEnvironment)
def environment_created(self):
- self.found_db_version = 0
self.upgrade_environment(self.env.db_transaction)
def environment_needs_upgrade(self, db):
@@ -64,7 +108,7 @@ class EnvironmentSetup(Component):
if db_installed_version < 1:
self._initialize_db(db)
self._update_db_version(db, db_default.DB_VERSION)
- #add upgrade logic later if needed
+ #add upgrade logic later if needed
def _get_version(self, db):
"""Finds the current version of the bloodhound database schema"""
@@ -91,6 +135,7 @@ class EnvironmentSetup(Component):
return version
def _initialize_db(self, db):
+ # pylint: disable=protected-access
self.log.debug("creating initial db schema for %s.", PLUGIN_NAME)
db_connector, dummy = DatabaseManager(self.env)._get_connector()
for table in db_default.SCHEMA:
@@ -103,10 +148,11 @@ class RelationsSystem(Component):
CHILDREN_RELATION_TYPE = 'children'
RELATIONS_CONFIG_NAME = 'bhrelations_links'
+ changing_listeners = ExtensionPoint(IRelationChangingListener)
+
def __init__(self):
- self._links, self._labels, \
- self._validators, self._blockers, \
- self._copy_fields = self._get_links_config()
+ self._links, self._labels, self._validators, self._blockers, \
+ self._copy_fields = self._get_links_config()
self.link_ends_map = {}
for end1, end2 in self.get_ends():
@@ -121,14 +167,15 @@ class RelationsSystem(Component):
source_resource_instance,
destination_resource_instance,
relation_type,
- comment = None,
- author = None,
- when = None,
- ):
+ comment=None,
+ author=None,
+ when=None):
source = ResourceIdSerializer.get_resource_id_from_instance(
self.env, source_resource_instance)
destination = ResourceIdSerializer.get_resource_id_from_instance(
self.env, destination_resource_instance)
+ if when is None:
+ when = datetime.now(utc)
relation = Relation(self.env)
relation.source = source
relation.destination = destination
@@ -137,29 +184,35 @@ class RelationsSystem(Component):
relation.author = author
relation.when = when
self.add_relation(relation)
+ return relation
+
+ def get_reverted_relation(self, relation):
+ """Return None if relation is one way"""
+ other_end = self.link_ends_map[relation.type]
+ if other_end:
+ return relation.clone_reverted(other_end)
def add_relation(self, relation):
#TBD: add changes in source and destination ticket history
self.validate(relation)
with self.env.db_transaction:
relation.insert()
- other_end = self.link_ends_map[relation.type]
- if other_end:
- reverted_relation = relation.clone_reverted(other_end)
- # self.validate(relation)
+ reverted_relation = self.get_reverted_relation(relation)
+ if reverted_relation:
reverted_relation.insert()
- def delete(
- self,
- relation_id,
- ):
- #TODO: some optimization may be added here by not loading relations
- #before actual DELETE SQL
+ for listener in self.changing_listeners:
+ listener.adding_relation(relation)
+
+ def delete(self, relation_id, when=None):
+ if when is None:
+ when = datetime.now(utc)
relation = Relation.load_by_relation_id(self.env, relation_id)
source = relation.source
destination = relation.destination
relation_type = relation.type
with self.env.db_transaction:
+ cloned_relation = relation.clone()
relation.delete()
other_end = self.link_ends_map[relation_type]
if other_end:
@@ -170,6 +223,9 @@ class RelationsSystem(Component):
))
reverted_relation.delete()
+ for listener in self.changing_listeners:
+ listener.deleting_relation(cloned_relation, when)
+
def delete_resource_relations(self, resource_instance):
sql = "DELETE FROM " + Relation.get_table_name() + \
" WHERE source=%s OR destination=%s"
@@ -189,14 +245,14 @@ class RelationsSystem(Component):
for relation in self._select_relations_for_resource_instance(
resource_instance):
relation_list.append(dict(
- relation_id = relation.get_relation_id(),
- destination_id = relation.destination,
+ relation_id=relation.get_relation_id(),
+ destination_id=relation.destination,
destination=ResourceIdSerializer.get_resource_by_id(
relation.destination),
- type = relation.type,
- comment = relation.comment,
- when = relation.when,
- author = relation.author,
+ type=relation.type,
+ comment=relation.comment,
+ when=relation.when,
+ author=relation.author,
))
return relation_list
@@ -211,15 +267,15 @@ class RelationsSystem(Component):
#a lot of child tickets
where = dict(source=source)
if resource_type:
- where["type"]=resource_type
- order_by=["destination"]
+ where["type"] = resource_type
+ order_by = ["destination"]
else:
- order_by=["type", "destination"]
+ order_by = ["type", "destination"]
return Relation.select(
self.env,
where=where,
order_by=order_by
- )
+ )
# Copied from trac/ticket/links.py, ticket-links-trunk branch
def _get_links_config(self):
@@ -255,7 +311,8 @@ class RelationsSystem(Component):
blockers[end1] = config.getbool(end1 + '.blocks', default=False)
if end2:
- blockers[end2] = config.getbool(end2 + '.blocks', default=False)
+ blockers[end2] = config.getbool(end2 + '.blocks',
+ default=False)
# <end>.copy_fields may be absent or intentionally set empty.
# config.getlist() will return [] in either case, so check that
@@ -295,7 +352,7 @@ class RelationsSystem(Component):
relation.source,
relation.type)
if path:
- cycle_str = [self._get_resource_name_from_id(resource_id)
+ cycle_str = [self.get_resource_name_from_id(resource_id)
for resource_id in path]
error = 'Cycle in ''%s'': %s' % (
self.render_relation_type(relation.type),
@@ -317,10 +374,10 @@ class RelationsSystem(Component):
parent_relations = self._select_relations(
source, self.PARENT_RELATION_TYPE)
if len(parent_relations) > 0:
- source_resource_name = self._get_resource_name_from_id(
+ source_resource_name = self.get_resource_name_from_id(
relation.source)
parent_ids_ins_string = ", ".join(
- [self._get_resource_name_from_id(relation.destination)
+ [self.get_resource_name_from_id(relation.destination)
for relation in parent_relations]
)
error = "Multiple links in '%s': %s -> [%s]" % (
@@ -334,7 +391,7 @@ class RelationsSystem(Component):
def _find_path(self, source, destination, relation_type):
known_nodes = set()
- new_nodes = set([source])
+ new_nodes = {source}
paths = {(source, source): [source]}
while new_nodes:
@@ -369,32 +426,17 @@ class RelationsSystem(Component):
resource_instance = is_blocker_method(resource)
if resource_instance is not None:
all_blockers.append(resource_instance)
- # blockers = self._recursive_find_blockers(
- # relation, is_blocker_method)
- # if blockers:
- # all_blockers.extend(blockers)
+ # blockers = self._recursive_find_blockers(
+ # relation, is_blocker_method)
+ # if blockers:
+ # all_blockers.extend(blockers)
return all_blockers
- # def _recursive_find_blockers(self, relation, blockers, is_blocker_method):
- # #todo: optimize performance by possibility to select more
- # # source ids at once
- # for linked_relation in self._select_relations(
- # relation.destination):
- # resource = ResourceIdSerializer.get_resource_by_id(
- # linked_relation.destination)
- # resource_instance = is_blocker_method(resource)
- # if resource_instance is not None:
- # blockers.append(resource_instance)
- # else:
- # self._recursive_find_blockers(linked_relation, blockers)
- # return blockers
-
- def _get_resource_name_from_id(self, resource_id):
+ def get_resource_name_from_id(self, resource_id):
resource = ResourceIdSerializer.get_resource_by_id(resource_id)
return get_resource_shortname(self.env, resource)
-
class ResourceIdSerializer(object):
RESOURCE_ID_DELIMITER = u":"
@@ -404,7 +446,7 @@ class ResourceIdSerializer(object):
* resource_full_id: fully qualified resource id in format
"product:ticket:123". In case of global environment it is ":ticket:123"
"""
- nbhprefix, realm, resource_id = cls._split_full_id(resource_full_id)
+ nbhprefix, realm, resource_id = cls.split_full_id(resource_full_id)
if nbhprefix:
neighborhood = Neighborhood('product', nbhprefix)
return neighborhood.child(realm, id=resource_id)
@@ -412,10 +454,9 @@ class ResourceIdSerializer(object):
return Resource(realm, id=resource_id)
@classmethod
- def _split_full_id(cls, resource_full_id):
+ def split_full_id(cls, resource_full_id):
return resource_full_id.split(cls.RESOURCE_ID_DELIMITER)
-
@classmethod
def get_resource_id_from_instance(cls, env, resource_instance):
"""
@@ -485,12 +526,79 @@ class TicketRelationsSpecifics(Component
def _get_env_for_resource(self, resource):
if hasattr(resource, "neighborhood"):
- env = ResourceSystem(self.env).load_component_manager(
+ env = ResourceSystem(self.env).load_component_manager(
resource.neighborhood)
else:
env = self.env
return env
+
+class TicketChangeRecordUpdater(Component):
+ implements(IRelationChangingListener)
+
+ def adding_relation(self, relation):
+ self.update_tickets_change_records(
+ relation, False, relation.time)
+
+ def deleting_relation(self, relation, when):
+ when_ts = to_utimestamp(when)
+ self.update_tickets_change_records(relation, True, when_ts)
+
+ def update_tickets_change_records(self, relation, is_delete, when_ts):
+ relation_system = RelationsSystem(self.env)
+ with self.env.db_direct_transaction as db:
+ self._add_ticket_change_record(
+ db,
+ relation,
+ relation_system,
+ is_delete,
+ when_ts
+ )
+
+ reverted_relation = relation_system.get_reverted_relation(relation)
+ if reverted_relation:
+ self._add_ticket_change_record(
+ db,
+ reverted_relation,
+ relation_system,
+ is_delete,
+ when_ts
+ )
+
+ def _get_ticket_id_and_product(self, resource_full_id):
+ nbhprefix, realm, resource_id = ResourceIdSerializer.split_full_id(
+ resource_full_id)
+ ticket_id = None
+ if realm == "ticket":
+ ticket_id = int(resource_id)
+ return ticket_id, nbhprefix
+
+ def _add_ticket_change_record(
+ self, db, relation, relation_system, is_delete, when_ts):
+ ticket_id, product = self._get_ticket_id_and_product(relation.source)
+ if ticket_id is None:
+ return
+
+ related_resource_name = relation_system.get_resource_name_from_id(
+ relation.destination)
+ if is_delete:
+ old_value = related_resource_name
+ new_value = None
+ else:
+ old_value = None
+ new_value = related_resource_name
+
+ db("""INSERT INTO ticket_change
+ (ticket, time, author, field, oldvalue, newvalue, product)
+ VALUES (%s, %s, %s, %s, %s, %s, %s)""",
+ (ticket_id,
+ when_ts,
+ relation.author,
+ relation.type,
+ old_value,
+ new_value,
+ product))
+
# Copied from trac/utils.py, ticket-links-trunk branch
def unique(seq):
"""Yield unique elements from sequence of hashables, preserving order.
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/db_default.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/db_default.py?rev=1480997&r1=1480996&r2=1480997&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/db_default.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/db_default.py Fri May 10 12:50:30 2013
@@ -22,6 +22,7 @@ from bhrelations.model import Relation
DB_SYSTEM_KEY = 'bhrelations'
DB_VERSION = 2
+# pylint: disable=protected-access
SCHEMA = [mcls._get_schema() for mcls in (Relation, )]
migrations = [
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/model.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/model.py?rev=1480997&r1=1480996&r2=1480997&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/model.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/model.py Fri May 10 12:50:30 2013
@@ -61,6 +61,14 @@ class Relation(ModelBase):
data["source"] = self.destination
data["destination"] = self.source
relation = Relation(self._env)
+ # pylint: disable=protected-access
+ relation._data = data
+ return relation
+
+ def clone(self):
+ data = self._data.copy()
+ relation = Relation(self._env)
+ # pylint: disable=protected-access
relation._data = data
return relation
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/templates/manage.html
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/templates/manage.html?rev=1480997&r1=1480996&r2=1480997&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/templates/manage.html (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/templates/manage.html Fri May 10 12:50:30 2013
@@ -43,6 +43,11 @@
</div>
</div>
+ <!--temporary solution-->
+ <div>
+ <!--todo: change it to appropriate markup-->
+ </div>
+
<div class="row">
<div class="span8">
<div class="well">
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/tests/__init__.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/tests/__init__.py?rev=1480997&r1=1480996&r2=1480997&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/tests/__init__.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/tests/__init__.py Fri May 10 12:50:30 2013
@@ -18,3 +18,19 @@
# specific language governing permissions and limitations
# under the License.
+# import sys
+# if sys.version < (2, 7):
+# import unittest2 as unittest
+# else:
+# import unittest
+import unittest
+
+from bhrelations.tests import api
+
+def suite():
+ test_suite = unittest.TestSuite()
+ test_suite.addTest(api.suite())
+ return test_suite
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='suite')
\ No newline at end of file
Modified: bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py?rev=1480997&r1=1480996&r2=1480997&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py (original)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/tests/api.py Fri May 10 12:50:30 2013
@@ -19,9 +19,11 @@
# under the License.
from datetime import datetime
from _sqlite3 import OperationalError, IntegrityError
+import unittest
from bhrelations.api import (EnvironmentSetup, RelationsSystem,
CycleValidationError, ParentValidationError,
TicketRelationsSpecifics)
+from bhrelations.tests.mocks import TestRelationChangingListener
from multiproduct.env import ProductEnvironment
from tests.env import MultiproductTestCase
from trac.ticket.model import Ticket
@@ -31,11 +33,13 @@ from trac.util.datefmt import utc
try:
from babel import Locale
+
locale_en = Locale.parse('en_US')
except ImportError:
locale_en = None
-class ApiTestCase(MultiproductTestCase):
+
+class BaseApiApiTestCase(MultiproductTestCase):
def setUp(self):
env = EnvironmentStub(
default_data=True,
@@ -45,12 +49,12 @@ class ApiTestCase(MultiproductTestCase):
env.config.set(config_name, 'dependency', 'dependson,dependent')
env.config.set(config_name, 'dependency.validator', 'no_cycle')
env.config.set(config_name, 'dependent.blocks', 'true')
- env.config.set(config_name, 'parent_children','parent,children')
+ env.config.set(config_name, 'parent_children', 'parent,children')
env.config.set(config_name, 'parent_children.validator',
- 'parent_child')
+ 'parent_child')
env.config.set(config_name, 'children.label', 'Overridden')
env.config.set(config_name, 'parent.copy_fields',
- 'summary, foo')
+ 'summary, foo')
env.config.set(config_name, 'oneway', 'refersto')
self.global_env = env
@@ -76,12 +80,12 @@ class ApiTestCase(MultiproductTestCase):
# table remains but database version is deleted
pass
- #classmethod
+ @classmethod
def _insert_ticket(cls, env, summary, **kw):
"""Helper for inserting a ticket into the database"""
ticket = Ticket(env)
ticket["Summary"] = summary
- for k,v in kw.items():
+ for k, v in kw.items():
ticket[k] = v
return ticket.insert()
@@ -91,6 +95,8 @@ class ApiTestCase(MultiproductTestCase):
def _insert_and_load_ticket_with_env(self, env, summary, **kw):
return Ticket(env, self._insert_ticket(env, summary, **kw))
+
+class ApiTestCase(BaseApiApiTestCase):
def test_can_add_two_ways_relations(self):
#arrange
ticket = self._insert_and_load_ticket("A1")
@@ -202,7 +208,6 @@ class ApiTestCase(MultiproductTestCase):
relations_system = self.relations_system
relations_system.add(ticket, referred, "refersto")
-
ticket = self._insert_and_load_ticket("A1")
dependent_ticket = self._insert_and_load_ticket("A2")
relations_system = self.relations_system
@@ -238,7 +243,7 @@ class ApiTestCase(MultiproductTestCase):
self.assertSequenceEqual(
["tp1:ticket:1", "tp1:ticket:2"], ex.failed_ids)
- def test_can_add_more_dependsons(self):
+ def test_can_add_more_depends_ons(self):
#arrange
ticket1 = self._insert_and_load_ticket("A1")
ticket2 = self._insert_and_load_ticket("A2")
@@ -391,8 +396,6 @@ class ApiTestCase(MultiproductTestCase):
self.assertEqual(1, len(relations_system.get_relations(ticket1)))
self.assertEqual(1, len(relations_system.get_relations(ticket2)))
- #todo: add multi-product ticket relations test
-
def _debug_select(self):
"""
used for debug purposes
@@ -403,3 +406,107 @@ class ApiTestCase(MultiproductTestCase):
# for row in db(sql, ("source", "destination", "type")):
for row in db(sql):
print row
+
+
+class RelationChangingListenerTestCase(BaseApiApiTestCase):
+ def test_can_sent_adding_event(self):
+ #arrange
+ ticket1 = self._insert_and_load_ticket("A1")
+ ticket2 = self._insert_and_load_ticket("A2")
+ relations_system = self.relations_system
+ test_changing_listener = self.env[TestRelationChangingListener]
+ #act
+ relations_system.add(ticket1, ticket2, "dependent")
+ #assert
+ self.assertEqual("adding_relation", test_changing_listener.action)
+ relation = test_changing_listener.relation
+ self.assertEqual("dependent", relation.type)
+
+ def test_can_sent_deleting_event(self):
+ #arrange
+ ticket1 = self._insert_and_load_ticket("A1")
+ ticket2 = self._insert_and_load_ticket("A2")
+ relations_system = self.relations_system
+ test_changing_listener = self.env[TestRelationChangingListener]
+ relations_system.add(ticket1, ticket2, "dependent")
+ #act
+ relations = relations_system.get_relations(ticket1)
+ relation_to_delete = relations[0]
+ relations_system.delete(relation_to_delete["relation_id"])
+ #assert
+ self.assertEqual("deleting_relation", test_changing_listener.action)
+ relation = test_changing_listener.relation
+ self.assertEqual("dependent", relation.type)
+
+
+class TicketChangeRecordUpdaterTestCase(BaseApiApiTestCase):
+ def test_can_update_ticket_history_on_relation_add_on(self):
+ #arrange
+ ticket1 = self._insert_and_load_ticket("A1")
+ ticket2 = self._insert_and_load_ticket("A2")
+ relations_system = self.relations_system
+ #act
+ relations_system.add(ticket1, ticket2, "dependent")
+ #assert
+ change_log1 = Ticket(self.env, ticket1.id).get_changelog()
+ self.assertEquals(1, len(change_log1))
+
+ change_log2 = Ticket(self.env, ticket2.id).get_changelog()
+ self.assertEquals(1, len(change_log2))
+
+ def test_can_update_ticket_history_on_relation_deletion(self):
+ #arrange
+ ticket1 = self._insert_and_load_ticket("A1")
+ ticket2 = self._insert_and_load_ticket("A2")
+ relations_system = self.relations_system
+ relations_system.add(ticket1, ticket2, "dependent")
+ relations = relations_system.get_relations(ticket1)
+ #act
+ relation_to_delete = relations[0]
+ relations_system.delete(relation_to_delete["relation_id"])
+ #assert
+ change_log1 = Ticket(self.env, ticket1.id).get_changelog()
+ self.assertEquals(2, len(change_log1))
+
+ change_log2 = Ticket(self.env, ticket2.id).get_changelog()
+ self.assertEquals(2, len(change_log2))
+
+ def _debug_select(self, ticket_id=None):
+ """
+ used for debug purposes
+ """
+ # print " source, destination, type"
+ sql = "SELECT * FROM ticket_change"
+ print "db_direct_transaction result:"
+ with self.env.db_direct_transaction as db:
+ # for row in db(sql, ("source", "destination", "type")):
+ for row in db(sql):
+ print row
+
+ sql = "SELECT * FROM ticket_change"
+ print "db_transaction result:"
+ with self.env.db_transaction as db:
+ for row in db(sql):
+ print row
+
+ if ticket_id:
+ sql = """SELECT time, author, field, oldvalue, newvalue
+ FROM ticket_change WHERE ticket=%s"""
+ print "db_transaction select by ticket_id result:"
+ with self.env.db_transaction:
+ for row in self.env.db_query(sql, (ticket_id, )):
+ print row
+
+
+def suite():
+ test_suite = unittest.TestSuite()
+ test_suite.addTest(unittest.makeSuite(ApiTestCase, 'test'))
+ test_suite.addTest(unittest.makeSuite(
+ RelationChangingListenerTestCase, 'test'))
+ test_suite.addTest(unittest.makeSuite(
+ TicketChangeRecordUpdaterTestCase, 'test'))
+ return test_suite
+
+
+if __name__ == '__main__':
+ unittest.main()
Added: bloodhound/trunk/bloodhound_relations/bhrelations/tests/mocks.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_relations/bhrelations/tests/mocks.py?rev=1480997&view=auto
==============================================================================
--- bloodhound/trunk/bloodhound_relations/bhrelations/tests/mocks.py (added)
+++ bloodhound/trunk/bloodhound_relations/bhrelations/tests/mocks.py Fri May 10 12:50:30 2013
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from bhrelations.api import IRelationChangingListener
+from trac.core import Component, implements
+
+
+class TestRelationChangingListener(Component):
+ implements(IRelationChangingListener)
+
+ def adding_relation(self, relation):
+ self.action = "adding_relation"
+ self.relation = relation
+
+ def deleting_relation(self, relation, when):
+ self.action = "deleting_relation"
+ self.relation = relation
+ self.when = when