Skip to content

Commit 8586a52

Browse files
authored
Merge pull request #652 from jasonrahm/bugfix.ifiles_tests
iFiles tests cleanup for issue #635
2 parents 7152a52 + c94d32d commit 8586a52

6 files changed

Lines changed: 91 additions & 65 deletions

File tree

conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def teardown():
224224

225225
@pytest.fixture
226226
def IFILE(mgmt_root):
227-
ntf = NamedTemporaryFile()
227+
ntf = NamedTemporaryFile(delete=False)
228228
ntf_basename = os.path.basename(ntf.name)
229229
ntf.write('this is a test file')
230230
ntf.seek(0)

f5/bigip/tm/ltm/test/test_ifile.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@
1616
import mock
1717
import pytest
1818

19-
from f5.bigip import ManagementRoot
2019
from f5.bigip.resource import MissingRequiredCreationParameter
2120
from f5.bigip.tm.ltm.ifile import Ifile
2221

2322

2423
@pytest.fixture
25-
def FakeIfile():
24+
def FakeLtmIfile():
2625
fake_ifile_s = mock.MagicMock()
2726
fake_ifile = Ifile(fake_ifile_s)
2827
return fake_ifile
2928

3029

31-
class TestCreate(object):
32-
def test_create_two(self, fakeicontrolsession):
33-
mgmt = ManagementRoot('172.16.44.15', 'admin', 'admin')
34-
r1 = mgmt.tm.ltm.ifiles.ifile
35-
r2 = mgmt.tm.ltm.ifiles.ifile
36-
assert r1 is not r2
30+
def test_create_no_args(FakeLtmIfile):
31+
with pytest.raises(MissingRequiredCreationParameter):
32+
FakeLtmIfile.create()
3733

38-
def test_create_no_args(self, FakeIfile):
39-
with pytest.raises(MissingRequiredCreationParameter):
40-
FakeIfile.create()
34+
35+
def test_create_missing_arg(FakeLtmIfile):
36+
with pytest.raises(MissingRequiredCreationParameter) as ex:
37+
FakeLtmIfile.create(name='test_ifile')
38+
assert 'fileName' in ex.value.message

f5/bigip/tm/sys/file.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from f5.bigip.resource import Collection
3030
from f5.bigip.resource import OrganizingCollection
3131
from f5.bigip.resource import Resource
32+
from f5.sdk_exception import UnsupportedMethod
3233

3334

3435
class File(OrganizingCollection):
@@ -76,6 +77,15 @@ def __init__(self, ifiles):
7677
self._meta_data['required_creation_parameters'].update(
7778
('name', 'sourcePath'))
7879

80+
def modify(self, **kwargs):
81+
'''Modify is not supported for iFiles
82+
83+
:raises: UnsupportedOperation
84+
'''
85+
raise UnsupportedMethod(
86+
"%s does not support the update method" % self.__class__.__name__
87+
)
88+
7989

8090
class Ssl_Certs(Collection):
8191
def __init__(self, File):

f5/bigip/tm/sys/test/test_file.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# limitations under the License.
1414
#
1515

16-
from distutils.version import LooseVersion
1716
import mock
1817
import pytest
1918

@@ -23,6 +22,7 @@
2322
from f5.bigip.tm.sys.file import Ssl_Crl
2423
from f5.bigip.tm.sys.file import Ssl_Csr
2524
from f5.bigip.tm.sys.file import Ssl_Key
25+
from f5.sdk_exception import UnsupportedMethod
2626

2727

2828
@pytest.fixture
@@ -43,6 +43,11 @@ def test_ifile_create_missing_arg(FakeSysIfile):
4343
assert 'sourcePath' in ex.value.message
4444

4545

46+
def test_ifile_modify(FakeSysIfile):
47+
with pytest.raises(UnsupportedMethod):
48+
FakeSysIfile.modify(value='Fake')
49+
50+
4651
@pytest.fixture
4752
def FakeSysCert():
4853
fake_cert_s = mock.MagicMock()
@@ -86,23 +91,11 @@ def FakeSysCsr():
8691
return fake_csr
8792

8893

89-
@pytest.mark.skipif(
90-
LooseVersion(
91-
pytest.config.getoption('--release')
92-
) < LooseVersion('12.0.0'),
93-
reason='csr management is only supported in 12.0.0 or greater.'
94-
)
9594
def test_csr_create_no_args(FakeSysCsr):
9695
with pytest.raises(MissingRequiredCreationParameter):
9796
FakeSysCsr.create()
9897

9998

100-
@pytest.mark.skipif(
101-
LooseVersion(
102-
pytest.config.getoption('--release')
103-
) < LooseVersion('12.0.0'),
104-
reason='csr management is only supported in 12.0.0 or greater.'
105-
)
10699
def test_csr_create_missing_arg(FakeSysCsr):
107100
with pytest.raises(MissingRequiredCreationParameter) as ex:
108101
FakeSysCsr.create(name='test_csr')

test/functional/tm/ltm/test_ifile.py

Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
#
1515

16+
import copy
1617
from f5.bigip.resource import MissingRequiredCreationParameter
1718
import pytest
1819
from requests.exceptions import HTTPError
@@ -44,48 +45,70 @@ def teardown():
4445
request.addfinalizer(teardown)
4546

4647

47-
def setup_basic_test(request, mgmt_root, name, partition, IFILE):
48+
def setup_basic_test(request, mgmt_root, name, partition, IFILE, **kwargs):
4849
def teardown():
4950
delete_ifile(mgmt_root, name, partition, IFILE)
5051

5152
ifile1 = mgmt_root.tm.ltm.ifiles.ifile.create(
52-
name='ifile1', partition='Common', fileName=IFILE.name)
53+
name='ifile1', partition='Common', fileName=IFILE.name, **kwargs)
5354

5455
request.addfinalizer(teardown)
5556
return ifile1
5657

5758

58-
def test_create_no_args(mgmt_root):
59-
with pytest.raises(MissingRequiredCreationParameter):
60-
mgmt_root.tm.ltm.ifiles.ifile.create()
61-
62-
63-
def test_create_no_filename(mgmt_root):
64-
with pytest.raises(MissingRequiredCreationParameter):
65-
mgmt_root.tm.ltm.ifiles.ifile.create(name='ifile1', partition='Common')
66-
67-
68-
def test_create(request, mgmt_root, IFILE):
69-
setup_create_test(request, mgmt_root, 'ifile1', 'Common', IFILE)
70-
ifile1 = mgmt_root.tm.ltm.ifiles.ifile.create(
71-
name='ifile1', partition='Common', fileName=IFILE.name)
72-
73-
assert ifile1.name == 'ifile1'
74-
assert ifile1.partition == 'Common'
75-
76-
77-
def test_delete(request, mgmt_root, IFILE):
78-
ifile1 = setup_basic_test(request, mgmt_root, 'ifile1', 'Common', IFILE)
79-
ifile1.delete()
80-
with pytest.raises(HTTPError) as err:
81-
mgmt_root.tm.ltm.ifiles.ifile.load(
82-
name='ifile1', partition='Common')
83-
assert err.response.status_code == 404
84-
85-
# not testing this function here; but need to clean it up
86-
try:
87-
IFILE.delete()
88-
except HTTPError as err:
89-
if err.response.status_code != 404:
90-
raise
91-
return
59+
class TestiFile(object):
60+
def test_create_no_args(self, mgmt_root):
61+
with pytest.raises(MissingRequiredCreationParameter):
62+
mgmt_root.tm.ltm.ifiles.ifile.create()
63+
64+
def test_create_no_filename(self, mgmt_root):
65+
with pytest.raises(MissingRequiredCreationParameter):
66+
mgmt_root.tm.ltm.ifiles.ifile.create(
67+
name='ifile1', partition='Common')
68+
69+
def test_create(self, request, mgmt_root, IFILE):
70+
setup_create_test(request, mgmt_root, 'ifile1', 'Common', IFILE)
71+
ifile1 = mgmt_root.tm.ltm.ifiles.ifile.create(
72+
name='ifile1', partition='Common', fileName=IFILE.name)
73+
74+
assert ifile1.name == 'ifile1'
75+
assert ifile1.partition == 'Common'
76+
77+
def test_delete(self, request, mgmt_root, IFILE):
78+
ifile1 = setup_basic_test(
79+
request, mgmt_root, 'ifile1', 'Common', IFILE)
80+
ifile1.delete()
81+
with pytest.raises(HTTPError) as err:
82+
mgmt_root.tm.ltm.ifiles.ifile.load(
83+
name='ifile1', partition='Common')
84+
assert err.response.status_code == 404
85+
86+
# not testing this function here; but need to clean it up
87+
try:
88+
IFILE.delete()
89+
except HTTPError as err:
90+
if err.response.status_code != 404:
91+
raise
92+
return
93+
94+
def test_modify(self, request, mgmt_root, IFILE):
95+
ifile1 = setup_basic_test(
96+
request, mgmt_root, 'ifile1', 'Common', IFILE,
97+
description='first_fake')
98+
assert ifile1.description == 'first_fake'
99+
original_dict = copy.copy(ifile1.__dict__)
100+
desc = 'description'
101+
ifile1.modify(description='CustomFake')
102+
for k, v in original_dict.items():
103+
if k != desc:
104+
original_dict[k] = ifile1.__dict__[k]
105+
elif k == desc:
106+
assert ifile1.__dict__[k] == 'CustomFake'
107+
108+
def test_update(self, request, mgmt_root, IFILE):
109+
ifile1 = setup_basic_test(request, mgmt_root, 'ifile1', 'Common',
110+
IFILE, description='first_fake')
111+
assert ifile1.description == 'first_fake'
112+
ifile1.description = 'CustomFake'
113+
ifile1.update()
114+
assert ifile1.description == 'CustomFake'

test/functional/tm/sys/test_file.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ def create_sslfiles():
7070
return key, csr, cert
7171

7272

73-
def setup_ifile_test(request, mgmt_root, name, sourcepath):
73+
def setup_ifile_test(request, mgmt_root, name, sourcepath, **kwargs):
7474
if1 = mgmt_root.tm.sys.file.ifiles.ifile.create(name=name,
75-
sourcePath=sourcepath)
75+
sourcePath=sourcepath,
76+
**kwargs)
7677

7778
def teardown():
7879
# Remove the ifile.
@@ -88,15 +89,16 @@ def teardown():
8889

8990
def test_CURDL_ifile(request, mgmt_root):
9091
# Create
91-
ntf = NamedTemporaryFile()
92+
ntf = NamedTemporaryFile(delete=False)
9293
ntf_basename = os.path.basename(ntf.name)
9394
ntf.write('this is a test file')
9495
ntf.seek(0)
9596
# Upload the file
9697
mgmt_root.shared.file_transfer.uploads.upload_file(ntf.name)
9798

9899
tpath_name = 'file:/var/config/rest/downloads/{0}'.format(ntf_basename)
99-
if1 = setup_ifile_test(request, mgmt_root, ntf_basename, tpath_name)
100+
if1 = setup_ifile_test(request, mgmt_root, ntf_basename, tpath_name,
101+
)
100102
assert if1.name == ntf_basename
101103

102104
# Load Object

0 commit comments

Comments
 (0)