@@ -94,18 +94,28 @@ def test_is_sata30orless_sata31(self, mock_db,
94
94
b'SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)\n '
95
95
b'supressed text\n \n ' )
96
96
mock_subprocess_check_output .return_value = extcmd_output
97
+
97
98
mock_db_instance = MagicMock ()
98
99
mock_db .return_value = mock_db_instance
100
+
99
101
key = '/dev/sda_is_sata30orless'
100
- mock_db_instance .return_value = False
101
- if mock_db_instance .get (key ) is None :
102
- ret = utils .is_sata30orless ('/dev/sda' )
103
- mock_subprocess_check_output .assert_called ()
104
- self .assertEqual (ret , False )
105
- mock_db_instance .set .assert_called_with (key , False )
106
- else :
107
- ret = utils .is_sata30orless ('/dev/sda' )
108
- mock_subprocess_check_output .assert_not_called ()
102
+
103
+ # Case 1: Key is not in DataBase
104
+ mock_db_instance .get .return_value = None
105
+ ret = utils .is_sata30orless ('/dev/sda' )
106
+ mock_subprocess_check_output .assert_called ()
107
+ mock_db_instance .set .assert_called_with (key , False )
108
+ self .assertEqual (ret , False )
109
+
110
+ mock_subprocess_check_output .reset_mock ()
111
+ mock_db_instance .reset_mock ()
112
+
113
+ # Case 2: Key already exists in DataBase
114
+ mock_db_instance .get .return_value = False
115
+ ret = utils .is_sata30orless ('/dev/sda' )
116
+ mock_subprocess_check_output .assert_not_called ()
117
+ mock_db_instance .set .assert_not_called ()
118
+ self .assertEqual (ret , False )
109
119
110
120
@patch ('subprocess.check_output' )
111
121
@patch ('charmhelpers.core.unitdata.kv' )
@@ -115,18 +125,28 @@ def test_is_sata30orless_sata30(self, mock_db,
115
125
b'SATA 3.0, 6.0 Gb/s (current: 6.0 Gb/s)\n '
116
126
b'supressed text\n \n ' )
117
127
mock_subprocess_check_output .return_value = extcmd_output
128
+
118
129
mock_db_instance = MagicMock ()
119
130
mock_db .return_value = mock_db_instance
131
+
120
132
key = '/dev/sda_is_sata30orless'
133
+
134
+ # Case 1: Key is not in DataBase
121
135
mock_db_instance .get .return_value = None
122
- if mock_db_instance .get (key ) is None :
123
- ret = utils .is_sata30orless ('/dev/sda' )
124
- mock_subprocess_check_output .assert_called ()
125
- self .assertEqual (ret , True )
126
- mock_db_instance .set .assert_called_with (key , True )
127
- else :
128
- ret = utils .is_sata30orless ('/dev/sda' )
129
- mock_subprocess_check_output .assert_not_called ()
136
+ ret = utils .is_sata30orless ('/dev/sda' )
137
+ mock_subprocess_check_output .assert_called ()
138
+ mock_db_instance .set .assert_called_with (key , True )
139
+ self .assertEqual (ret , True )
140
+
141
+ mock_subprocess_check_output .reset_mock ()
142
+ mock_db_instance .reset_mock ()
143
+
144
+ # Case 2: Key already exists in DataBase
145
+ mock_db_instance .get .return_value = True
146
+ ret = utils .is_sata30orless ('/dev/sda' )
147
+ mock_subprocess_check_output .assert_not_called ()
148
+ mock_db_instance .set .assert_not_called ()
149
+ self .assertEqual (ret , True )
130
150
131
151
@patch ('subprocess.check_output' )
132
152
@patch ('charmhelpers.core.unitdata.kv' )
@@ -136,18 +156,28 @@ def test_is_sata30orless_sata26(self, mock_db,
136
156
b'SATA 2.6, 3.0 Gb/s (current: 3.0 Gb/s)\n '
137
157
b'supressed text\n \n ' )
138
158
mock_subprocess_check_output .return_value = extcmd_output
159
+
139
160
mock_db_instance = MagicMock ()
140
161
mock_db .return_value = mock_db_instance
162
+
141
163
key = '/dev/sda_is_sata30orless'
164
+
165
+ # Case 1: Key is not in DataBase
142
166
mock_db_instance .get .return_value = None
143
- if mock_db_instance .get (key ) is None :
144
- ret = utils .is_sata30orless ('/dev/sda' )
145
- mock_subprocess_check_output .assert_called ()
146
- self .assertEqual (ret , True )
147
- mock_db_instance .set .assert_called_with (key , True )
148
- else :
149
- ret = utils .is_sata30orless ('/dev/sda' )
150
- mock_subprocess_check_output .assert_not_called ()
167
+ ret = utils .is_sata30orless ('/dev/sda' )
168
+ mock_subprocess_check_output .assert_called ()
169
+ mock_db_instance .set .assert_called_with (key , True )
170
+ self .assertEqual (ret , True )
171
+
172
+ mock_subprocess_check_output .reset_mock ()
173
+ mock_db_instance .reset_mock ()
174
+
175
+ # Case 2: Key already exists in DataBase
176
+ mock_db_instance .get .return_value = True
177
+ ret = utils .is_sata30orless ('/dev/sda' )
178
+ mock_subprocess_check_output .assert_not_called ()
179
+ mock_db_instance .set .assert_not_called ()
180
+ self .assertEqual (ret , True )
151
181
152
182
@patch .object (utils , "function_get" )
153
183
def test_raise_on_missing_arguments (self , mock_function_get ):
0 commit comments