|
3 | 3 | from click.testing import CliRunner
|
4 | 4 | from utilities_common.db import Db
|
5 | 5 | from mock import patch
|
| 6 | +from jsonpatch import JsonPatchConflict |
6 | 7 | import config.main as config
|
7 | 8 | import config.nat as nat
|
8 | 9 | import config.validated_config_db_connector as validated_config_db_connector
|
@@ -116,3 +117,151 @@ def test_add_udp_yang_validation(self):
|
116 | 117 |
|
117 | 118 | result = runner.invoke(config.config.commands["nat"].commands["add"].commands["static"], ["udp", "65.66.45.1", "100", "12.12.12.14", "200"], obj=obj)
|
118 | 119 | assert "Invalid ConfigDB. Error" in result.output
|
| 120 | + |
| 121 | + def test_remove_basic(self): |
| 122 | + nat.ADHOC_VALIDATION = True |
| 123 | + runner = CliRunner() |
| 124 | + db = Db() |
| 125 | + obj = {'config_db':db.cfgdb} |
| 126 | + |
| 127 | + result = runner.invoke(config.config.commands["nat"].commands["remove"].commands["static"].commands["basic"], ["65.66.45.1", "12.12.12.14x"], obj=obj) |
| 128 | + assert "Please enter a valid local ip address" in result.output |
| 129 | + |
| 130 | + result = runner.invoke(config.config.commands["nat"].commands["remove"].commands["static"].commands["basic"], ["65.66.45.1x", "12.12.12.14"], obj=obj) |
| 131 | + assert "Please enter a valid global ip address" in result.output |
| 132 | + |
| 133 | + @patch("config.nat.ConfigDBConnector.get_entry", mock.Mock(return_value={"local_ip": "12.12.12.14"})) |
| 134 | + @patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True)) |
| 135 | + @patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_set_entry", mock.Mock(side_effect=JsonPatchConflict)) |
| 136 | + def test_remove_basic_yang_validation(self): |
| 137 | + nat.ADHOC_VALIDATION = True |
| 138 | + runner = CliRunner() |
| 139 | + db = Db() |
| 140 | + obj = {'config_db':db.cfgdb} |
| 141 | + |
| 142 | + result = runner.invoke(config.config.commands["nat"].commands["remove"].commands["static"].commands["basic"], ["65.66.45.1", "12.12.12.14"], obj=obj) |
| 143 | + assert "Invalid ConfigDB. Error" in result.output |
| 144 | + |
| 145 | + def test_remove_udp(self): |
| 146 | + nat.ADHOC_VALIDATION = True |
| 147 | + runner = CliRunner() |
| 148 | + db = Db() |
| 149 | + obj = {'config_db':db.cfgdb} |
| 150 | + |
| 151 | + result = runner.invoke(config.config.commands["nat"].commands["remove"].commands["static"].commands["udp"], ["65.66.45.1", "100", "12.12.12.14x", "200"], obj=obj) |
| 152 | + assert "Please enter a valid local ip address" in result.output |
| 153 | + |
| 154 | + result = runner.invoke(config.config.commands["nat"].commands["remove"].commands["static"].commands["udp"], ["65.66.45.1x", "100", "12.12.12.14", "200"], obj=obj) |
| 155 | + assert "Please enter a valid global ip address" in result.output |
| 156 | + |
| 157 | + @patch("config.nat.ConfigDBConnector.get_entry", mock.Mock(return_value={"local_ip": "12.12.12.14", "local_port": "200"})) |
| 158 | + @patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True)) |
| 159 | + @patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_set_entry", mock.Mock(side_effect=JsonPatchConflict)) |
| 160 | + def test_remove_udp_yang_validation(self): |
| 161 | + nat.ADHOC_VALIDATION = True |
| 162 | + runner = CliRunner() |
| 163 | + db = Db() |
| 164 | + obj = {'config_db':db.cfgdb} |
| 165 | + |
| 166 | + result = runner.invoke(config.config.commands["nat"].commands["remove"].commands["static"].commands["udp"], ["65.66.45.1", "100", "12.12.12.14", "200"], obj=obj) |
| 167 | + assert "Invalid ConfigDB. Error" in result.output |
| 168 | + |
| 169 | + @patch("config.nat.ConfigDBConnector.get_table", mock.Mock(return_value={"sample_table_key": "sample_table_value"})) |
| 170 | + @patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True)) |
| 171 | + @patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_set_entry", mock.Mock(side_effect=JsonPatchConflict)) |
| 172 | + def test_remove_static_all_yang_validation(self): |
| 173 | + nat.ADHOC_VALIDATION = True |
| 174 | + runner = CliRunner() |
| 175 | + db = Db() |
| 176 | + obj = {'config_db':db.cfgdb} |
| 177 | + |
| 178 | + result = runner.invoke(config.config.commands["nat"].commands["remove"].commands["static"].commands["all"], obj=obj) |
| 179 | + assert "Invalid ConfigDB. Error" in result.output |
| 180 | + |
| 181 | + @patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True)) |
| 182 | + @patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_mod_entry", mock.Mock(side_effect=ValueError)) |
| 183 | + def test_enable_yang_validation(self): |
| 184 | + nat.ADHOC_VALIDATION = True |
| 185 | + runner = CliRunner() |
| 186 | + db = Db() |
| 187 | + obj = {'config_db':db.cfgdb} |
| 188 | + |
| 189 | + result = runner.invoke(config.config.commands["nat"].commands["feature"].commands["enable"], obj=obj) |
| 190 | + assert "Invalid ConfigDB. Error" in result.output |
| 191 | + |
| 192 | + @patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True)) |
| 193 | + @patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_mod_entry", mock.Mock(side_effect=ValueError)) |
| 194 | + def test_disable_yang_validation(self): |
| 195 | + nat.ADHOC_VALIDATION = True |
| 196 | + runner = CliRunner() |
| 197 | + db = Db() |
| 198 | + obj = {'config_db':db.cfgdb} |
| 199 | + |
| 200 | + result = runner.invoke(config.config.commands["nat"].commands["feature"].commands["disable"], obj=obj) |
| 201 | + assert "Invalid ConfigDB. Error" in result.output |
| 202 | + |
| 203 | + @patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True)) |
| 204 | + @patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_mod_entry", mock.Mock(side_effect=ValueError)) |
| 205 | + def test_timeout_yang_validation(self): |
| 206 | + nat.ADHOC_VALIDATION = True |
| 207 | + runner = CliRunner() |
| 208 | + db = Db() |
| 209 | + obj = {'config_db':db.cfgdb} |
| 210 | + |
| 211 | + result = runner.invoke(config.config.commands["nat"].commands["set"].commands["timeout"], ["301"], obj=obj) |
| 212 | + assert "Invalid ConfigDB. Error" in result.output |
| 213 | + |
| 214 | + @patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True)) |
| 215 | + @patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_mod_entry", mock.Mock(side_effect=ValueError)) |
| 216 | + def test_tcp_timeout_yang_validation(self): |
| 217 | + nat.ADHOC_VALIDATION = True |
| 218 | + runner = CliRunner() |
| 219 | + db = Db() |
| 220 | + obj = {'config_db':db.cfgdb} |
| 221 | + |
| 222 | + result = runner.invoke(config.config.commands["nat"].commands["set"].commands["tcp-timeout"], ["301"], obj=obj) |
| 223 | + assert "Invalid ConfigDB. Error" in result.output |
| 224 | + |
| 225 | + @patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True)) |
| 226 | + @patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_mod_entry", mock.Mock(side_effect=ValueError)) |
| 227 | + def test_udp_timeout_yang_validation(self): |
| 228 | + nat.ADHOC_VALIDATION = True |
| 229 | + runner = CliRunner() |
| 230 | + db = Db() |
| 231 | + obj = {'config_db':db.cfgdb} |
| 232 | + |
| 233 | + result = runner.invoke(config.config.commands["nat"].commands["set"].commands["udp-timeout"], ["301"], obj=obj) |
| 234 | + assert "Invalid ConfigDB. Error" in result.output |
| 235 | + |
| 236 | + @patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True)) |
| 237 | + @patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_mod_entry", mock.Mock(side_effect=ValueError)) |
| 238 | + def test_reset_timeout_yang_validation(self): |
| 239 | + nat.ADHOC_VALIDATION = True |
| 240 | + runner = CliRunner() |
| 241 | + db = Db() |
| 242 | + obj = {'config_db':db.cfgdb} |
| 243 | + |
| 244 | + result = runner.invoke(config.config.commands["nat"].commands["reset"].commands["timeout"], obj=obj) |
| 245 | + assert "Invalid ConfigDB. Error" in result.output |
| 246 | + |
| 247 | + @patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True)) |
| 248 | + @patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_mod_entry", mock.Mock(side_effect=ValueError)) |
| 249 | + def test_reset_tcp_timeout_yang_validation(self): |
| 250 | + nat.ADHOC_VALIDATION = True |
| 251 | + runner = CliRunner() |
| 252 | + db = Db() |
| 253 | + obj = {'config_db':db.cfgdb} |
| 254 | + |
| 255 | + result = runner.invoke(config.config.commands["nat"].commands["reset"].commands["tcp-timeout"], obj=obj) |
| 256 | + assert "Invalid ConfigDB. Error" in result.output |
| 257 | + |
| 258 | + @patch("validated_config_db_connector.device_info.is_yang_config_validation_enabled", mock.Mock(return_value=True)) |
| 259 | + @patch("config.validated_config_db_connector.ValidatedConfigDBConnector.validated_mod_entry", mock.Mock(side_effect=ValueError)) |
| 260 | + def test_reset_udp_timeout_yang_validation(self): |
| 261 | + nat.ADHOC_VALIDATION = True |
| 262 | + runner = CliRunner() |
| 263 | + db = Db() |
| 264 | + obj = {'config_db':db.cfgdb} |
| 265 | + |
| 266 | + result = runner.invoke(config.config.commands["nat"].commands["reset"].commands["udp-timeout"], obj=obj) |
| 267 | + assert "Invalid ConfigDB. Error" in result.output |
0 commit comments