[SEBA-218] Making ONU serial number handling case insensitive

Change-Id: I7cd42041709c5e8041959da84c7e1853a8ba0636
diff --git a/xos/synchronizer/model_policies/model_policy_att_workflow_driver_service.py b/xos/synchronizer/model_policies/model_policy_att_workflow_driver_service.py
index 5fb076c..0c9d978 100644
--- a/xos/synchronizer/model_policies/model_policy_att_workflow_driver_service.py
+++ b/xos/synchronizer/model_policies/model_policy_att_workflow_driver_service.py
@@ -28,14 +28,14 @@
         # TODO(smbaker): This is redudant with AttWorkflowDriverWhiteListEntry model policy, though etaining this does provide
         # a handy way to trigger a full reexamination of the whitelist.
 
-        whitelist = [x.serial_number for x in service.whitelist_entries.all()]
+        whitelist = [x.serial_number.lower() for x in service.whitelist_entries.all()]
 
         for si in sis:
-            if si.serial_number in whitelist and not si.valid == "valid":
+            if si.serial_number.lower() in whitelist and not si.valid == "valid":
                 self.logger.debug("MODEL_POLICY: activating AttWorkflowDriverServiceInstance because of change in the whitelist", si=si)
                 si.valid = "valid"
                 si.save(update_fields=["valid", "no_sync", "updated"], always_update_timestamp=True)
-            if si.serial_number not in whitelist and not si.valid == "invalid":
+            if si.serial_number.lower() not in whitelist and not si.valid == "invalid":
                 self.logger.debug(
                     "MODEL_POLICY: disabling AttWorkflowDriverServiceInstance because of change in the whitelist", si=si)
                 si.valid = "invalid"
diff --git a/xos/synchronizer/model_policies/model_policy_att_workflow_driver_serviceinstance.py b/xos/synchronizer/model_policies/model_policy_att_workflow_driver_serviceinstance.py
index ef3363b..26b0367 100644
--- a/xos/synchronizer/model_policies/model_policy_att_workflow_driver_serviceinstance.py
+++ b/xos/synchronizer/model_policies/model_policy_att_workflow_driver_serviceinstance.py
@@ -67,7 +67,7 @@
 
             subscriber = None
             try:
-                subscriber = RCORDSubscriber.objects.get(onu_device=si.serial_number)
+                subscriber = [s for s in RCORDSubscriber.objects.all() if s.onu_device.lower() == si.serial_number.lower()][0]
             except IndexError:
                 # we just want to find out if it exists or not
                 pass
diff --git a/xos/synchronizer/model_policies/model_policy_att_workflow_driver_whitelistentry.py b/xos/synchronizer/model_policies/model_policy_att_workflow_driver_whitelistentry.py
index c38e7ec..c788d23 100644
--- a/xos/synchronizer/model_policies/model_policy_att_workflow_driver_whitelistentry.py
+++ b/xos/synchronizer/model_policies/model_policy_att_workflow_driver_whitelistentry.py
@@ -26,10 +26,19 @@
     def handle_update(self, whitelist):
         self.logger.debug("MODEL_POLICY: handle_update for AttWorkflowDriverWhiteListEntry", whitelist=whitelist)
 
-        sis = AttWorkflowDriverServiceInstance.objects.filter(serial_number = whitelist.serial_number,
-                                                   owner_id = whitelist.owner.id)
+        # TODO is Django construct '__iexact' available here?
+        # sis = AttWorkflowDriverServiceInstance.objects.filter(
+        #     serial_number = whitelist.serial_number,
+        #     owner_id = whitelist.owner.id)
+
+        sis = AttWorkflowDriverServiceInstance.objects.all()
 
         for si in sis:
+
+            if si.serial_number.lower() != whitelist.serial_number.lower():
+                # NOTE we don't care about this SI as it has a different serial number
+                continue
+
             if si.valid != "valid":
                 self.logger.debug("MODEL_POLICY: activating AttWorkflowDriverServiceInstance because of change in the whitelist", si=si)
                 si.valid = "valid"
diff --git a/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_service.py b/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_service.py
index 3af7cfe..576233f 100644
--- a/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_service.py
+++ b/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_service.py
@@ -111,7 +111,7 @@
             oss_si.return_value = [self.si1, self.si2, self.si3, self.si4]
 
             wle1 = AttWorkflowDriverWhiteListEntry(owner_id=self.service.id, serial_number="BRCM111")
-            wle2 = AttWorkflowDriverWhiteListEntry(owner_id=self.service.id, serial_number="BRCM222")
+            wle2 = AttWorkflowDriverWhiteListEntry(owner_id=self.service.id, serial_number="brcm222")
             self.service.whitelist_entries = self.MockObjectList([wle1, wle2])
 
             self.policy.handle_update(self.service)
diff --git a/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_serviceinstance.py b/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_serviceinstance.py
index 774efda..c47738d 100644
--- a/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_serviceinstance.py
+++ b/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_serviceinstance.py
@@ -200,7 +200,7 @@
     def test_subscriber_enable_status_auth_state_approved(self):
         self.si.valid = "valid"
         self.si.backend_code = 1
-        self.si.serial_number = "BRCM1234"
+        self.si.serial_number = "brcm1234"
         self.si.onu_state = "ENABLED"
         self.si.authentication_state = "APPROVED"
 
@@ -210,7 +210,7 @@
         )
 
         subscriber = RCORDSubscriber(
-            onu_device=self.si.serial_number,
+            onu_device="BRCM1234",
             status='awaiting-auth'
         )
 
diff --git a/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_whitelistentry.py b/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_whitelistentry.py
index 73c077a..68e1752 100644
--- a/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_whitelistentry.py
+++ b/xos/synchronizer/model_policies/test_model_policy_att_workflow_driver_whitelistentry.py
@@ -87,6 +87,20 @@
 
             self.assertEqual(si.valid, "valid")
 
+    def test_whitelist_update_case_insensitive(self):
+        """
+        When a whitelist entry is added, see that the AttWorkflowDriverIServicenstance was set to valid
+        """
+        with patch.object(AttWorkflowDriverServiceInstance.objects, "get_items") as oss_si_items:
+            si = AttWorkflowDriverServiceInstance(serial_number="brcm333", owner_id=self.service.id, valid="invalid")
+            oss_si_items.return_value = [si]
+
+            wle = AttWorkflowDriverWhiteListEntry(serial_number="BRCM333", owner_id=self.service.id, owner=self.service)
+
+            self.policy.handle_update(wle)
+
+            self.assertEqual(si.valid, "valid")
+
     def test_whitelist_delete(self):
         """
         When a whitelist entry is deleted, see that the AttWorkflowDriverIServicenstance was set to invalid