Changeset - 5c7da7c67a3e
[Not reviewed]
default
0 2 0
Branko Majic (branko) - 11 years ago 2013-07-14 13:27:02
branko@majic.rs
Noticket: Added a check for existing communications when attempting to move entity to a different project. Includes test of new functionality.
2 files changed with 32 insertions and 0 deletions:
0 comments (0 inline, 0 general)
conntrackt/models.py
Show inline comments
 
@@ -149,6 +149,26 @@ class Entity(models.Model):
 

	
 
        return reverse("entity", kwargs={'pk': self.pk})
 

	
 
    def clean(self):
 
        """
 
        Performs additional validation checks on the submitted data. It will
 
        verify the following:
 

	
 
          - That entity is not linked to any other entity in case of project
 
            change.
 
        """
 

	
 
        # Perform the check if entity is being updated.
 
        if self.pk:
 
            # Fetch the old data from database.
 
            # @TODO: Is it better to do copying during __init__ instead?
 
            old_object = Entity.objects.get(pk=1)
 

	
 
            # Make sure that entity has no communications in current project if
 
            # moving it around.
 
            if self.project != old_object.project and (self.incoming_communications() or self.outgoing_communications()):
 
                raise ValidationError("The entity cannot be moved to different project as long as it has valid communications with entities in current project.")
 

	
 

	
 
class Interface(models.Model):
 
    """
conntrackt/tests/test_models.py
Show inline comments
 
@@ -117,6 +117,18 @@ class EntityTest(TestCase):
 

	
 
        self.assertEqual(entity.get_absolute_url(), "/conntrackt/entity/1/")
 

	
 
    def test_project_move_constraints(self):
 
        """
 
        Tests if entity is prevented from being moved to different project in
 
        case of existing communications.
 
        """
 

	
 
        entity = Entity.objects.get(pk=1)
 
        new_project = Project.objects.get(pk=2)
 

	
 
        entity.project = new_project
 
        self.assertRaisesRegexp(ValidationError, "The entity cannot be moved to different project as long as it has valid communications with entities in current project." ,entity.clean)
 

	
 

	
 
class InterfaceTest(TestCase):
 
    fixtures = ['test-data.json']
0 comments (0 inline, 0 general)