Skip to content

Commit 2d8c037

Browse files
authored
Merge pull request #604 from caphrim007/bugfix.transactions-broken
Fixes transactions and adds functional tests
2 parents 651900d + 5aacd22 commit 2d8c037

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

f5/bigip/contexts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def __enter__(self):
4747
be able to use the API object as you normally would.
4848
"""
4949

50-
self.transaction.create()
50+
self.transaction = self.transaction.create()
51+
5152
self.icr.session.headers.update({
5253
'X-F5-REST-Coordination-Id': self.transaction.transId
5354
})
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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

Comments
 (0)