88from cliff import show
99
1010from coriolisclient .cli import licensing
11+ from coriolisclient import constants
1112from coriolisclient .tests import test_base
1213
1314
@@ -18,29 +19,42 @@ def setUp(self):
1819 super (LicensingStatusFormatterTestCase , self ).setUp ()
1920 self .licence = licensing .LicensingStatusFormatter ()
2021
21- def test_get_formatted_data (self ):
22+ @staticmethod
23+ def _make_stats (offset ):
24+ """Builds a stats body whose counters are all distinguishable."""
25+ return {
26+ field : offset + i
27+ for i , field in enumerate (constants .LICENCE_STATS_FIELDS )}
28+
29+ def _make_status (self , standard_stats , sap_stats ):
2230 obj = mock .Mock ()
2331 obj .appliance_id = mock .sentinel .appliance_id
2432 obj .earliest_licence_expiry_time = \
2533 mock .sentinel .earliest_licence_expiry_time
2634 obj .latest_licence_expiry_time = \
2735 mock .sentinel .latest_licence_expiry_time
28- obj .current_performed_migrations = \
29- mock .sentinel .current_performed_migrations
30- obj .current_performed_replicas = \
31- mock .sentinel .current_performed_replicas
32- obj .current_available_migrations = \
33- mock .sentinel .current_available_migrations
34- obj .current_available_replicas = \
35- mock .sentinel .current_available_replicas
36- obj .lifetime_performed_migrations = \
37- mock .sentinel .lifetime_performed_migrations
38- obj .lifetime_performed_replicas = \
39- mock .sentinel .lifetime_performed_replicas
40- obj .lifetime_available_migrations = \
41- mock .sentinel .lifetime_available_migrations
42- obj .lifetime_available_replicas = \
43- mock .sentinel .lifetime_available_replicas
36+ setattr (obj , constants .LICENCE_STATS_KEY_STANDARD , standard_stats )
37+ setattr (obj , constants .LICENCE_STATS_KEY_SAP , sap_stats )
38+ return obj
39+
40+ def test_columns (self ):
41+ self .assertEqual (
42+ [
43+ "appliance_id" ,
44+ "earliest_licence_expiry_time" ,
45+ "latest_licence_expiry_time" ,
46+ ] + [
47+ "standard_%s" % f for f in constants .LICENCE_STATS_FIELDS
48+ ] + [
49+ "sap_%s" % f for f in constants .LICENCE_STATS_FIELDS
50+ ],
51+ self .licence .columns
52+ )
53+
54+ def test_get_formatted_data (self ):
55+ standard_stats = self ._make_stats (0 )
56+ sap_stats = self ._make_stats (100 )
57+ obj = self ._make_status (standard_stats , sap_stats )
4458
4559 result = self .licence ._get_formatted_data (obj )
4660
@@ -49,17 +63,30 @@ def test_get_formatted_data(self):
4963 mock .sentinel .appliance_id ,
5064 mock .sentinel .earliest_licence_expiry_time ,
5165 mock .sentinel .latest_licence_expiry_time ,
52- mock .sentinel .current_performed_migrations ,
53- mock .sentinel .current_performed_replicas ,
54- mock .sentinel .current_available_migrations ,
55- mock .sentinel .current_available_replicas ,
56- mock .sentinel .lifetime_performed_migrations ,
57- mock .sentinel .lifetime_performed_replicas ,
58- mock .sentinel .lifetime_available_migrations ,
59- mock .sentinel .lifetime_available_replicas
66+ ] + [
67+ standard_stats [f ] for f in constants .LICENCE_STATS_FIELDS
68+ ] + [
69+ sap_stats [f ] for f in constants .LICENCE_STATS_FIELDS
6070 ],
6171 result
6272 )
73+ self .assertEqual (len (self .licence .columns ), len (result ))
74+
75+ def test_get_formatted_data_standard_only (self ):
76+ standard_stats = self ._make_stats (0 )
77+ sap_stats = dict .fromkeys (constants .LICENCE_STATS_FIELDS , 0 )
78+ obj = self ._make_status (standard_stats , sap_stats )
79+
80+ result = self .licence ._get_formatted_data (obj )
81+
82+ self .assertEqual (
83+ [standard_stats [f ] for f in constants .LICENCE_STATS_FIELDS ],
84+ result [3 :3 + len (constants .LICENCE_STATS_FIELDS )]
85+ )
86+ self .assertEqual (
87+ [0 ] * len (constants .LICENCE_STATS_FIELDS ),
88+ result [- len (constants .LICENCE_STATS_FIELDS ):]
89+ )
6390
6491
6592class LicenceFormatterTestCase (test_base .CoriolisBaseTestCase ):
@@ -85,7 +112,7 @@ def test_get_sorted_list(self):
85112 result
86113 )
87114
88- def test_get_formatted_data (self ):
115+ def _assert_formatted (self , licence_version , licence_edition ):
89116 obj = mock .Mock ()
90117 obj .id = mock .sentinel .id
91118 obj .issue_date = mock .sentinel .issue_date
@@ -94,9 +121,7 @@ def test_get_formatted_data(self):
94121 obj .period_start = mock .sentinel .period_start
95122 obj .period_end = mock .sentinel .period_end
96123 obj .period_duration = mock .sentinel .period_duration
97- obj .licence_version = mock .sentinel .licence_version
98-
99- result = self .licence ._get_formatted_data (obj )
124+ obj .licence_version = licence_version
100125
101126 self .assertEqual (
102127 (
@@ -107,11 +132,27 @@ def test_get_formatted_data(self):
107132 mock .sentinel .period_start ,
108133 mock .sentinel .period_end ,
109134 mock .sentinel .period_duration ,
110- mock .sentinel .licence_version
135+ licence_version ,
136+ licence_edition ,
111137 ),
112- result
138+ self . licence . _get_formatted_data ( obj )
113139 )
114140
141+ def test_get_formatted_data (self ):
142+ self ._assert_formatted (
143+ constants .LICENCE_VERSION_V2 , constants .LICENCE_EDITION_STANDARD )
144+
145+ def test_get_formatted_data_sap (self ):
146+ self ._assert_formatted (
147+ constants .LICENCE_VERSION_V2_SAP , constants .LICENCE_EDITION_SAP )
148+
149+ def test_get_formatted_data_v1 (self ):
150+ self ._assert_formatted (
151+ constants .LICENCE_VERSION_V1 , constants .LICENCE_EDITION_STANDARD )
152+
153+ def test_get_formatted_data_unknown_version (self ):
154+ self ._assert_formatted ("v3-something" , None )
155+
115156
116157class LicensingApplianceStatusTestCase (test_base .CoriolisBaseTestCase ):
117158 """Test suite for the Coriolis Client Licensing Appliance Status."""
0 commit comments