# Path: tmapi/exceptions.py
# class TopicInUseException (ModelConstraintException):
# 
#     """Thrown when an attempt is made to remove a `Topic` which is
#     being used as a type, as a reifier, or as a role player in an
#     association, or in a scope."""
#     
#     def __init__ (self, topic, message):
#         """Creates a new `TopicInUseException` with the specified message.
# 
#         :param topic: the topic which is not removable
#         :type topic: `Topic`
#         :param message: the detail message
#         :type message: string
# 
#         """
#         super(TopicInUseException, self).__init__(topic, message)


from tmapi.exceptions import TopicInUseException
from tmapi_test_case import TMAPITestCase

"""Tests if the engine respects the constraint if a Topic is removable
or not.

Most if not all of these tests are ported from the public domain tests
that come with the TMAPI 2.0 distribution (http://www.tmapi.org/2.0/).

"""




class TopicRemovableConstraintTest (TMAPITestCase):

    def _test_typed (self, typed):
        """Tests if hte topic removable constraint is respected if the
        topic is used as a type.

        :param typed: a typed construct
        :type typed: `Typed`

        """
        topic_count = self.tm.get_topics().count()
        old_type = typed.get_type()
        topic = self.create_topic()
        self.assertEqual(topic_count+1, self.tm.get_topics().count())
        typed.set_type(topic)
        try:
            topic.remove()
            self.fail('The topic is used as a type')

# Path: tmapi/exceptions.py
# class TopicInUseException (ModelConstraintException):
# 
#     """Thrown when an attempt is made to remove a `Topic` which is
#     being used as a type, as a reifier, or as a role player in an
#     association, or in a scope."""
#     
#     def __init__ (self, topic, message):
#         """Creates a new `TopicInUseException` with the specified message.
# 
#         :param topic: the topic which is not removable
#         :type topic: `Topic`
#         :param message: the detail message
#         :type message: string
# 
#         """
#         super(TopicInUseException, self).__init__(topic, message)


# Path: tmapi/tests/models/test_topic_removable_constraint.py
from tmapi.exceptions import TopicInUseException
from tmapi_test_case import TMAPITestCase


"""Tests if the engine respects the constraint if a Topic is removable
or not.

Most if not all of these tests are ported from the public domain tests
that come with the TMAPI 2.0 distribution (http://www.tmapi.org/2.0/).

"""




class TopicRemovableConstraintTest (TMAPITestCase):

    def _test_typed (self, typed):
        """Tests if hte topic removable constraint is respected if the
        topic is used as a type.

        :param typed: a typed construct
        :type typed: `Typed`

        """
        topic_count = self.tm.get_topics().count()
        old_type = typed.get_type()
        topic = self.create_topic()
        self.assertEqual(topic_count+1, self.tm.get_topics().count())
        typed.set_type(topic)
        try:
            topic.remove()
            self.fail('The topic is used as a type')

        except TopicInUseException, ex: