-
Notifications
You must be signed in to change notification settings - Fork 0
/
dm_root_test.py
112 lines (87 loc) · 3.42 KB
/
dm_root_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/python
# Copyright 2011 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# unittest requires method names starting in 'test'
# pylint:disable=invalid-name
"""Unit tests for dm_root.py."""
__author__ = '[email protected] (Denton Gentry)'
import google3
import dm_root
import os.path
import shutil
import tempfile
import tr.basemodel
import tr.experiment
import tr.cwmptypes
from tr.wvtest import unittest
BASE181 = tr.basemodel.Device
BASE98 = tr.basemodel.InternetGatewayDevice
class MockTr181(BASE181):
pass
class MockTr98(BASE98):
pass
class MockManagement(object):
MostRecentURL = tr.cwmptypes.String()
def __init__(self):
self.EnableCWMP = False
class MockDevice(object):
def DeviceId(self):
class X(object):
SerialNumber = '1234'
return X()
class DeviceModelRootTest(unittest.TestCase):
def setUp(self):
self.tmpdir = tempfile.mkdtemp()
self.old_ACTIVEDIR = tr.experiment.ACTIVEDIR
tr.experiment.ACTIVEDIR = os.path.join(self.tmpdir, 'act')
os.mkdir(tr.experiment.ACTIVEDIR)
def tearDown(self):
tr.experiment.ACTIVEDIR = self.old_ACTIVEDIR
shutil.rmtree(self.tmpdir)
def testAddManagementServer(self):
root = dm_root.DeviceModelRoot(loop=None, platform=None,
ext_dir='ext_test')
mgmt = MockManagement()
root.add_management_server(mgmt) # should do nothing.
root.device = MockDevice()
root.Device = MockTr181()
root.InternetGatewayDevice = MockTr98()
root.Export(objects=['Device', 'InternetGatewayDevice'])
root.add_cwmp_extensions()
self.assertFalse(isinstance(root.InternetGatewayDevice.ManagementServer,
BASE98.ManagementServer))
self.assertFalse(isinstance(root.Device.ManagementServer,
BASE181.ManagementServer))
root.add_management_server(mgmt) # should actually work now
print type(root.InternetGatewayDevice.ManagementServer)
self.assertTrue(isinstance(root.InternetGatewayDevice.ManagementServer,
BASE98.ManagementServer))
print type(root.Device.ManagementServer)
self.assertTrue(isinstance(root.Device.ManagementServer,
BASE181.ManagementServer))
self.assertEqual(root.TestBaseExt, True)
self.assertEqual(root.TestSubExt, 97) # auto-rounded to int
# Make sure aliasing is working as expected
root.X_CATAWAMPUS_ORG_CATAWAMPUS.Experiments.Requested = 'test1'
self.assertEqual(root.X_CATAWAMPUS_ORG_CATAWAMPUS.Experiments.Requested,
'test1')
self.assertEqual(root.Device.X_CATAWAMPUS_ORG.Experiments.Requested,
'test1')
self.assertTrue(os.path.exists(
os.path.join(tr.experiment.ACTIVEDIR, 'test1.requested')))
def testValidateExports(self):
r = dm_root.DeviceModelRoot(None, None, None)
tr.handle.ValidateExports(r)
if __name__ == '__main__':
unittest.main()