13 # |
13 # |
14 # Description: |
14 # Description: |
15 # |
15 # |
16 |
16 |
17 import unittest |
17 import unittest |
18 import os, shutil |
18 import os |
19 import sys |
|
20 import pkg_resources |
|
21 import re |
|
22 |
19 |
23 import __init__ |
20 from cone.public import api |
24 |
|
25 from ruleplugin import ruleml, relations |
|
26 from cone.public import api, exceptions |
|
27 from ruleplugin.evals import accesspoint_id_counter |
21 from ruleplugin.evals import accesspoint_id_counter |
28 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
22 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
29 |
23 |
30 class TestAPIDC(unittest.TestCase): |
24 class TestAPIDC(unittest.TestCase): |
31 def test_get_ApDnContainer(self): |
25 def test_get_ApDnContainer(self): |
32 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
26 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
33 config = project.get_configuration('root.confml') |
27 config = project.get_configuration('root.confml') |
34 dview = config.get_default_view() |
28 dview = config.get_default_view() |
35 |
29 |
36 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True) |
30 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("WLAN_APs"), dview.get_feature("APs"), dview.get_feature("DNs")) |
37 |
31 |
38 self.assertEquals('Internet', container.get_all_dns()[0].get_name()) |
32 self.assertEquals('Internet', container.get_all_dns()[0].get_name()) |
39 self.assertEquals('1', container.get_all_dns()[0].get_id()) |
33 self.assertEquals('1', container.get_all_dns()[0].get_id()) |
40 self.assertEquals(['IAP11', 'IAP12', 'IAP13', None, None, None, None, None, None, None], container.get_all_dns()[0].get_iaps()) |
34 self.assertEquals(['IAP11', 'IAP12', 'IAP13', 'WIAP16', None, None, None, None, None, None], |
|
35 container.get_all_dns()[0].get_iaps()) |
41 |
36 |
42 self.assertEquals('MMS', container.get_all_dns()[1].get_name()) |
37 self.assertEquals('MMS', container.get_all_dns()[1].get_name()) |
43 self.assertEquals('2', container.get_all_dns()[1].get_id()) |
38 self.assertEquals('2', container.get_all_dns()[1].get_id()) |
44 self.assertEquals(['IAP21', 'IAP22', 'IAP23', 'IAP13', None, None, None, None, None, None], container.get_all_dns()[1].get_iaps()) |
39 self.assertEquals(['IAP21', 'IAP22', 'IAP23', None, None, None, None, None, None, None], |
|
40 container.get_all_dns()[1].get_iaps()) |
45 |
41 |
46 self.assertEquals('Operator', container.get_all_dns()[2].get_name()) |
42 self.assertEquals('Operator', container.get_all_dns()[2].get_name()) |
47 self.assertEquals('3', container.get_all_dns()[2].get_id()) |
43 self.assertEquals('3', container.get_all_dns()[2].get_id()) |
48 self.assertEquals(['IAP31', 'IAP32', 'IAP33', None, None, None, None, None, None, None], container.get_all_dns()[2].get_iaps()) |
44 self.assertEquals(['IAP31', 'IAP32', 'IAP33', None, None, None, None, None, None, None], |
|
45 container.get_all_dns()[2].get_iaps()) |
49 |
46 |
50 self.assertEquals('IAP11', container.get_all_aps()[0].get_name()) |
47 self.assertEquals('WIAP16', container.get_all_aps()[0].get_name()) |
51 self.assertEquals('1', container.get_all_aps()[0].get_id()) |
48 self.assertEquals('5', container.get_all_aps()[0].get_id()) |
52 |
49 |
53 def test_get_apid_by_apname(self): |
50 def test_get_apid_by_apname(self): |
54 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
51 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
55 config = project.get_configuration('root.confml') |
52 config = project.get_configuration('root.confml') |
56 dview = config.get_default_view() |
53 dview = config.get_default_view() |
57 |
54 |
58 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True) |
55 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("WLAN_APs"), dview.get_feature("APs"), dview.get_feature("DNs")) |
59 |
56 |
60 self.assertEquals('1', container.get_apid_by_apname('IAP11')) |
57 self.assertEquals('1', container.get_apid_by_apname('IAP11')) |
61 self.assertEquals('2', container.get_apid_by_apname('IAP12')) |
58 self.assertEquals('2', container.get_apid_by_apname('IAP12')) |
62 self.assertEquals('7', container.get_apid_by_apname('IAP13')) |
59 self.assertEquals('7', container.get_apid_by_apname('IAP13')) |
63 |
60 |
64 def test_get_dnid_by_dnname(self): |
61 def test_get_dnid_by_dnname(self): |
65 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
62 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
66 config = project.get_configuration('root.confml') |
63 config = project.get_configuration('root.confml') |
67 dview = config.get_default_view() |
64 dview = config.get_default_view() |
68 |
65 |
69 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True) |
66 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("WLAN_APs"), dview.get_feature("APs"), dview.get_feature("DNs")) |
70 |
67 |
71 self.assertEquals('1', container.get_dnid_by_dnname('Internet')) |
68 self.assertEquals('1', container.get_dnid_by_dnname('Internet')) |
72 self.assertEquals('2', container.get_dnid_by_dnname('MMS')) |
69 self.assertEquals('2', container.get_dnid_by_dnname('MMS')) |
73 self.assertEquals('3', container.get_dnid_by_dnname('Operator')) |
70 self.assertEquals('3', container.get_dnid_by_dnname('Operator')) |
74 |
71 |
76 def test_get_apid_by_dnname_and_apname(self): |
73 def test_get_apid_by_dnname_and_apname(self): |
77 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
74 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
78 config = project.get_configuration('root.confml') |
75 config = project.get_configuration('root.confml') |
79 dview = config.get_default_view() |
76 dview = config.get_default_view() |
80 |
77 |
81 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True) |
78 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("WLAN_APs"), dview.get_feature("APs"), dview.get_feature("DNs")) |
82 |
79 |
83 self.assertEquals('2', container.get_apid_by_dnname_and_apname('Internet', 'IAP12')) |
80 self.assertEquals('2', container.get_apid_by_dnname_and_apname('Internet', 'IAP12')) |
84 |
81 |
85 def test_calc_ap_ids(self): |
82 def test_calc_ap_ids(self): |
86 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
83 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
87 config = project.get_configuration('root.confml') |
84 config = project.get_configuration('root.confml') |
88 dview = config.get_default_view() |
85 dview = config.get_default_view() |
89 |
86 |
90 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True) |
87 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("WLAN_APs"), dview.get_feature("APs"), dview.get_feature("DNs")) |
91 |
88 |
92 self.assertEquals('9', container.get_all_aps()[6].get_id()) |
89 self.assertEquals('6', container.get_all_aps()[6].get_id()) |
|
90 self.assertEquals('5', container.get_all_aps()[0].get_id()) |
93 |
91 |
94 def test_all_in_array(self): |
92 def test_all_in_array(self): |
95 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
93 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
96 config = project.get_configuration('root.confml') |
94 config = project.get_configuration('root.confml') |
97 dview = config.get_default_view() |
95 dview = config.get_default_view() |
98 |
96 |
99 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True) |
97 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("WLAN_APs"), dview.get_feature("APs"), dview.get_feature("DNs")) |
100 |
98 |
101 self.assertEquals(container.get_all_in_array(), [['Internet', '1', ['IAP11', 'IAP12', 'IAP13', None, None, None, None, None, None, None], ['1', '2', '7', None, None, None, None, None, None, None], ['1', '2', '3', None, None, None, None, None, None, None]], ['MMS', '2', ['IAP21', 'IAP22', 'IAP23', 'IAP13', None, None, None, None, None, None], ['4', '8', '6', '7', None, None, None, None, None, None], ['4', '5', '6', '3', None, None, None, None, None, None]], ['Operator', '3', ['IAP31', 'IAP32', 'IAP33', None, None, None, None, None, None, None], [None, None, '9', None, None, None, None, None, None, None], [None, None, '7', None, None, None, None, None, None, None]]]) |
99 self.assertEquals(container.get_all_in_array(), |
|
100 [ |
|
101 ['Internet', '1', |
|
102 ['IAP11', 'IAP12', 'IAP13', 'WIAP16', None, None, None, None, None, None], |
|
103 ['1', '2', '7', '5', None, None, None, None, None, None], |
|
104 ['1', '2', '3', '4', None, None, None, None, None, None]], |
|
105 ['MMS', '2', |
|
106 ['IAP21', 'IAP22', 'IAP23', None, None, None, None, None, None, None], |
|
107 ['4', '8', '6', None, None, None, None, None, None, None], |
|
108 ['5', '6', '7', None, None, None, None, None, None, None]], |
|
109 ['Operator', '3', |
|
110 ['IAP31', 'IAP32', 'IAP33', None, None, None, None, None, None, None], |
|
111 [None, None, '9', None, None, None, None, None, None, None], |
|
112 [None, None, '8', None, None, None, None, None, None, None]] |
|
113 ] |
|
114 ) |
102 |
115 |
103 def test_get_next_free_id(self): |
116 def test_get_next_free_id(self): |
104 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
117 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
105 config = project.get_configuration('root.confml') |
118 config = project.get_configuration('root.confml') |
106 dview = config.get_default_view() |
119 dview = config.get_default_view() |
107 |
120 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("WLAN_APs"), dview.get_feature("APs"), dview.get_feature("DNs")) |
108 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True) |
|
109 |
121 |
110 self.assertEquals("4", accesspoint_id_counter._get_next_free_id_(container.get_all_dns())) |
122 self.assertEquals("4", accesspoint_id_counter._get_next_free_id_(container.get_all_dns())) |
111 self.assertEquals("10", accesspoint_id_counter._get_next_free_id_(container.get_all_aps())) |
123 self.assertEquals("10", accesspoint_id_counter._get_next_free_id_(container.get_all_aps())) |
112 |
124 |
113 def test_get_apindex_by_apname(self): |
125 def test_get_apindex_by_apname(self): |
114 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
126 project = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'ruleproject'))) |
115 config = project.get_configuration('root.confml') |
127 config = project.get_configuration('root.confml') |
116 dview = config.get_default_view() |
128 dview = config.get_default_view() |
117 |
129 |
118 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("APs"), dview.get_feature("DNs"), True) |
130 container = accesspoint_id_counter._get_ApDnContainer_(dview.get_feature("WLAN_APs"), dview.get_feature("APs"), dview.get_feature("DNs")) |
119 |
131 |
120 self.assertEquals("4", container.get_apindex_by_apname("IAP21")) |
132 self.assertEquals("5", container.get_apindex_by_apname("IAP21")) |
121 self.assertEquals("1", container.get_apindex_by_apname("IAP11")) |
133 self.assertEquals("1", container.get_apindex_by_apname("IAP11")) |
122 |
134 |
123 |
135 |
124 if __name__ == "__main__": |
136 if __name__ == "__main__": |
125 unittest.main() |
137 unittest.main() |