blob: 35f83502a5649031ec2fa2e6477295e2e80ce654 [file] [log] [blame]
Matteo Scandoload0c1752018-08-09 15:47:16 -07001# Copyright 2017-present Open Networking Foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import unittest
16from mock import patch, call, Mock, PropertyMock
17import json
18
19import os, sys
20
Matteo Scandoload0c1752018-08-09 15:47:16 -070021test_path=os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
Matteo Scandoload0c1752018-08-09 15:47:16 -070022
23class TestSubscriberAuthEvent(unittest.TestCase):
24
25 def setUp(self):
26
27 self.sys_path_save = sys.path
Matteo Scandoload0c1752018-08-09 15:47:16 -070028
29 # Setting up the config module
30 from xosconfig import Config
31 config = os.path.join(test_path, "../test_config.yaml")
32 Config.clear()
33 Config.init(config, "synchronizer-config-schema.yaml")
34 from multistructlog import create_logger
35 log = create_logger(Config().get('logging'))
36 # END Setting up the config module
37
Scott Baker71d20472019-02-01 12:05:35 -080038 from xossynchronizer.mock_modelaccessor_build import mock_modelaccessor_config
39 mock_modelaccessor_config(test_path, [("att-workflow-driver", "att-workflow-driver.xproto"),
40 ("olt-service", "volt.xproto"),
Matteo Scandoload6c8942019-02-14 13:02:08 -080041 ("rcord", "rcord.xproto")])
Matteo Scandoload0c1752018-08-09 15:47:16 -070042
Scott Baker71d20472019-02-01 12:05:35 -080043 import xossynchronizer.modelaccessor
44 import mock_modelaccessor
45 reload(mock_modelaccessor) # in case nose2 loaded it in a previous test
46 reload(xossynchronizer.modelaccessor) # in case nose2 loaded it in a previous test
47
48 from xossynchronizer.modelaccessor import model_accessor
49 from auth_event import SubscriberAuthEventStep
Matteo Scandoload0c1752018-08-09 15:47:16 -070050
51 # import all class names to globals
52 for (k, v) in model_accessor.all_model_classes.items():
53 globals()[k] = v
54
Scott Baker71d20472019-02-01 12:05:35 -080055 self.model_accessor = model_accessor
Matteo Scandoload0c1752018-08-09 15:47:16 -070056 self.log = log
57
Scott Baker71d20472019-02-01 12:05:35 -080058 self.event_step = SubscriberAuthEventStep(model_accessor=self.model_accessor, log=self.log)
Matteo Scandoload0c1752018-08-09 15:47:16 -070059
60 self.event = Mock()
61
62 self.volt = Mock()
63 self.volt.name = "vOLT"
64 self.volt.leaf_model = Mock()
65
66 self.hippie_si = AttWorkflowDriverServiceInstance()
67 self.hippie_si.serial_number = "BRCM1234"
68 self.hippie_si.save = Mock()
69
70
71 def tearDown(self):
72 sys.path = self.sys_path_save
73
74 def test_authenticate_subscriber(self):
75
76 self.event.value = json.dumps({
77 'authenticationState': "APPROVED",
78 'deviceId': "of:0000000ce2314000",
79 'portNumber': "101",
80 })
81
82 with patch.object(VOLTService.objects, "get_items") as volt_service_mock, \
83 patch.object(AttWorkflowDriverServiceInstance.objects, "get_items") as hippie_si_mock, \
84 patch.object(self.volt, "get_onu_sn_from_openflow") as get_onu_sn:
85
86 volt_service_mock.return_value = [self.volt]
87 get_onu_sn.return_value = "BRCM1234"
88 hippie_si_mock.return_value = [self.hippie_si]
89
90 self.event_step.process_event(self.event)
91
Andy Bavier0d631eb2018-10-17 18:05:04 -070092 self.hippie_si.save.assert_called_with(always_update_timestamp=True, update_fields=['authentication_state', 'serial_number', 'updated'])
Matteo Scandoload0c1752018-08-09 15:47:16 -070093 self.assertEqual(self.hippie_si.authentication_state, 'APPROVED')
Scott Baker71d20472019-02-01 12:05:35 -080094
95if __name__ == '__main__':
96 sys.path.append("..") # for import of helpers.py
97 unittest.main()