[SEBA-312] fixed c_tag validation in subscriber

Change-Id: I9368604abd3b4f5b47b6b69930580898aeda93c1
diff --git a/VERSION b/VERSION
index ee90284..74bcb8d 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-1.0.4
+1.0.5-dev
diff --git a/xos/synchronizer/models/models.py b/xos/synchronizer/models/models.py
index 9a8b163..ccf5211 100644
--- a/xos/synchronizer/models/models.py
+++ b/xos/synchronizer/models/models.py
@@ -36,7 +36,7 @@
 
         for link in self.subscribed_links.all():
             outer_service_instance = link.provider_service_instance
-            # TODO: We may need to invalide the vOLT too...
+            # TODO: We may need to invalidate the vOLT too...
             for link in outer_service_instance.subscribed_links.all():
                 inner_service_instance = link.provider_service_instance
                 inner_service_instance.save(update_fields=["updated"])
@@ -54,8 +54,11 @@
         return tag
 
     def get_used_c_tags(self):
+        # TODO add validation for no duplicate c_tag on the same s_tag
         same_onu_subscribers = RCORDSubscriber.objects.filter(onu_device=self.onu_device)
-        return [s.c_tag for s in same_onu_subscribers]
+        same_onu_subscribers = [s for s in same_onu_subscribers if s.id != self.id]
+        used_tags = [s.c_tag for s in same_onu_subscribers]
+        return used_tags
 
     def save(self, *args, **kwargs):
 
diff --git a/xos/synchronizer/models/test_models.py b/xos/synchronizer/models/test_models.py
index 3209fe3..1e66be2 100644
--- a/xos/synchronizer/models/test_models.py
+++ b/xos/synchronizer/models/test_models.py
@@ -107,7 +107,19 @@
         self.assertEqual(e.exception.message, "The onu_device you specified (BRCM1234) does not exists")
         self.models_decl.RCORDSubscriber_decl.save.assert_not_called()
 
-    def test_validate_c_tag(self):
+    def test_validate_c_tag_pass(self):
+        """
+        check that other subscriber attached to the same ONU don't have the same c_tag
+        """
+
+        self.models_decl.RCORDSubscriber_decl.objects.filter.return_value = [self.rcord_subscriber]
+
+
+        self.rcord_subscriber.save()
+
+        self.models_decl.RCORDSubscriber_decl.save.assert_called()
+
+    def test_validate_c_tag_fail(self):
         """
         check that other subscriber attached to the same ONU don't have the same c_tag
         """
@@ -116,7 +128,7 @@
         s.c_tag = 111
         s.onu_device = "BRCM1234"
 
-        self.models_decl.RCORDSubscriber_decl.objects.filter.return_value = [s]
+        self.models_decl.RCORDSubscriber_decl.objects.filter.return_value = [s, self.rcord_subscriber]
 
         with self.assertRaises(Exception) as e:
             self.rcord_subscriber.save()
@@ -124,6 +136,23 @@
         self.assertEqual(e.exception.message, "The c_tag you specified (111) has already been used on device BRCM1234")
         self.models_decl.RCORDSubscriber_decl.save.assert_not_called()
 
+    def _test_validate_c_tag_on_same_s_tag(self):
+        """
+        check that other subscriber using the same s_tag don't have the same c_tag
+        """
+        s = Mock()
+        s.id = 123
+        s.c_tag = 111
+        s.s_tag = 222
+        s.onu_device = "BRCM1234"
+
+        with self.assertRaises(Exception) as e:
+            self.rcord_subscriber.save()
+
+        self.assertEqual(e.exception.message, "The c_tag you specified (111) has already been used by Subscriber with id 123 and the same s_tag: 222")
+        self.models_decl.RCORDSubscriber_decl.save.assert_not_called()
+
+
     def test_validate_c_tag_on_update(self):
         s = Mock()
         s.c_tag = 111