SEBA-612 Port SEBA-571 changes to tt-workflow-driver
Change-Id: I8d6933805fa0106979e9f2e4bd6ac68be0f51e6c
diff --git a/xos/synchronizer/model_policies/test_model_policy_tt_workflow_driver_serviceinstance.py b/xos/synchronizer/model_policies/test_model_policy_tt_workflow_driver_serviceinstance.py
index a067779..2496f9d 100644
--- a/xos/synchronizer/model_policies/test_model_policy_tt_workflow_driver_serviceinstance.py
+++ b/xos/synchronizer/model_policies/test_model_policy_tt_workflow_driver_serviceinstance.py
@@ -15,11 +15,12 @@
import unittest
-from mock import patch, call, Mock, PropertyMock
+from mock import patch
-import os, sys
+import os
+import sys
-test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
+test_path = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
class TestModelPolicyTtWorkflowDriverServiceInstance(unittest.TestCase):
@@ -46,14 +47,12 @@
from model_policy_tt_workflow_driver_serviceinstance import TtWorkflowDriverServiceInstancePolicy, TtHelpers
self.TtHelpers = TtHelpers
- from mock_modelaccessor import MockObjectList
-
# import all class names to globals
for (k, v) in model_accessor.all_model_classes.items():
globals()[k] = v
- # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to creation of
- # tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world.
+ # Some of the functions we call have side-effects. For example, creating a VSGServiceInstance may lead to
+ # creation of tags. Ideally, this wouldn't happen, but it does. So make sure we reset the world.
model_accessor.reset_all_object_stores()
@@ -72,7 +71,7 @@
admin_state="ENABLED"
)
with patch.object(ONUDevice.objects, "get_items") as get_onu, \
- patch.object(onu, "save") as onu_save:
+ patch.object(onu, "save") as onu_save:
get_onu.return_value = [onu]
self.policy.update_onu("brcm1234", "ENABLED")
@@ -80,13 +79,13 @@
self.policy.update_onu("brcm1234", "DISABLED")
self.assertEqual(onu.admin_state, "DISABLED")
- onu_save.assert_called_with(always_update_timestamp=True, update_fields=['admin_state', 'serial_number', 'updated'])
-
+ onu_save.assert_called_with(
+ always_update_timestamp=True, update_fields=[
+ 'admin_state', 'serial_number', 'updated'])
def test_enable_onu(self):
with patch.object(self.TtHelpers, "validate_onu") as validate_onu, \
- patch.object(self.policy, "update_onu") as update_onu, \
- patch.object(self.si, "save") as save_si:
+ patch.object(self.policy, "update_onu") as update_onu:
validate_onu.return_value = [True, "valid onu"]
self.policy.process_onu_state(self.si)
@@ -98,8 +97,7 @@
def test_disable_onu(self):
with patch.object(self.TtHelpers, "validate_onu") as validate_onu, \
- patch.object(self.policy, "update_onu") as update_onu, \
- patch.object(self.si, "save") as save_si:
+ patch.object(self.policy, "update_onu") as update_onu:
validate_onu.return_value = [False, "invalid onu"]
self.policy.process_onu_state(self.si)
@@ -115,24 +113,26 @@
when necessary
"""
with patch.object(self.policy, "process_onu_state") as process_onu_state, \
- patch.object(self.policy, "update_onu") as update_onu, \
- patch.object(self.policy, "get_subscriber") as get_subscriber:
+ patch.object(self.policy, "update_onu") as update_onu, \
+ patch.object(self.policy, "get_subscriber") as get_subscriber:
update_onu.return_value = None
get_subscriber.return_value = None
- self.si.onu_state = "AWAITING"
+ self.si.admin_onu_state = "AWAITING"
+ self.si.oper_onu_status = "AWAITING"
self.policy.handle_update(self.si)
process_onu_state.assert_called_with(self.si)
- self.si.onu_state = "ENABLED"
+ self.si.admin_onu_state = "ENABLED"
+ self.si.oper_onu_status = "ENABLED"
self.policy.handle_update(self.si)
process_onu_state.assert_called_with(self.si)
- self.si.onu_state = "DISABLED"
+ self.si.admin_onu_state = "DISABLED"
+ self.si.oper_onu_status = "DISABLED"
self.policy.handle_update(self.si)
process_onu_state.assert_called_with(self.si)
-
def test_get_subscriber(self):
sub = RCORDSubscriber(
@@ -160,7 +160,7 @@
self.si.status_message = "some content"
with patch.object(sub, "save") as sub_save:
- self.si.onu_state = "ENABLED"
+ self.si.admin_onu_state = "ENABLED"
sub.status = "awaiting-auth"
self.policy.update_subscriber(sub, self.si)
self.assertEqual(sub.status, "enabled")
@@ -168,7 +168,7 @@
sub_save.reset_mock()
sub.status = None
- self.si.onu_state = "DISABLED"
+ self.si.admin_onu_state = "DISABLED"
sub.status = "enabled"
self.policy.update_subscriber(sub, self.si)
self.assertEqual(sub.status, "awaiting-auth")
@@ -183,12 +183,12 @@
with patch.object(sub, "save") as sub_save:
sub.status = "enabled"
- self.si.onu_state = "ENABLED"
+ self.si.admin_onu_state = "ENABLED"
self.policy.update_subscriber(sub, self.si)
sub_save.assert_not_called()
sub.status = "awaiting-auth"
- self.si.onu_state = "DISABLED"
+ self.si.admin_onu_state = "DISABLED"
self.policy.update_subscriber(sub, self.si)
sub_save.assert_not_called()
@@ -208,8 +208,8 @@
self.si.mac_address = "4321"
with patch.object(sub, "save") as sub_save, \
- patch.object(RCORDIpAddress.objects, "get_items") as get_ips, \
- patch.object(ip, "save_changed_fields") as ip_mock:
+ patch.object(RCORDIpAddress.objects, "get_items") as get_ips, \
+ patch.object(ip, "save_changed_fields") as ip_mock:
get_ips.return_value = [ip]
ip_mock.return_value = []
@@ -231,7 +231,7 @@
self.si.mac_address = "4321"
with patch.object(sub, "save") as sub_save, \
- patch.object(RCORDIpAddress, "save", autospec=True) as ip_mock:
+ patch.object(RCORDIpAddress, "save", autospec=True) as ip_mock:
ip_mock.return_value = []
@@ -245,19 +245,19 @@
self.assertEqual(saved_ip.description, "DHCP Assigned IP Address")
def test_handle_update_subscriber(self):
- self.si.onu_state = "DISABLED"
+ self.si.admin_onu_state = "DISABLED"
sub = RCORDSubscriber(
onu_device="BRCM1234"
)
with patch.object(self.policy, "get_subscriber") as get_subscriber, \
- patch.object(self.policy, "update_onu") as update_onu, \
- patch.object(self.policy, "update_subscriber") as update_subscriber:
+ patch.object(self.policy, "update_onu") as update_onu, \
+ patch.object(self.policy, "update_subscriber") as update_subscriber:
get_subscriber.return_value = None
self.policy.handle_update(self.si)
- update_onu.assert_called_with(sub.onu_device, "DISABLED");
+ update_onu.assert_called_with(sub.onu_device, "DISABLED")
self.assertEqual(update_subscriber.call_count, 0)
get_subscriber.return_value = sub
@@ -266,5 +266,5 @@
if __name__ == '__main__':
+ sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
unittest.main()
-