|
| 1 | +# Copyright 2016 F5 Networks Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | + |
| 16 | +import pytest |
| 17 | + |
| 18 | +from f5.bigip.contexts import TransactionContextManager |
| 19 | +from f5.bigip.contexts import TransactionSubmitException |
| 20 | + |
| 21 | + |
| 22 | +class TestTransaction(object): |
| 23 | + def test_create_empty(self, mgmt_root): |
| 24 | + tx = mgmt_root.tm.transactions.transaction |
| 25 | + with pytest.raises(TransactionSubmitException) as ex: |
| 26 | + # Do not remove this "NOQA". It is suppressing a flake8 |
| 27 | + # exception that would be raised about "not using the |
| 28 | + # 'api' variable". |
| 29 | + # |
| 30 | + # This is, however, exactly what we want to do in this |
| 31 | + # test. By not using the 'api' variable, I am forcing |
| 32 | + # this context to raise the expected exception, and testing |
| 33 | + # that that exception is raised. |
| 34 | + with TransactionContextManager(tx) as api: # NOQA |
| 35 | + pass |
| 36 | + assert "there is no command to commit in the transaction" \ |
| 37 | + in str(ex.value.message) |
0 commit comments