|
13 | 13 | # limitations under the License. |
14 | 14 | # |
15 | 15 |
|
| 16 | +import copy |
16 | 17 | from f5.bigip.resource import MissingRequiredCreationParameter |
17 | 18 | import pytest |
18 | 19 | from requests.exceptions import HTTPError |
@@ -44,48 +45,70 @@ def teardown(): |
44 | 45 | request.addfinalizer(teardown) |
45 | 46 |
|
46 | 47 |
|
47 | | -def setup_basic_test(request, mgmt_root, name, partition, IFILE): |
| 48 | +def setup_basic_test(request, mgmt_root, name, partition, IFILE, **kwargs): |
48 | 49 | def teardown(): |
49 | 50 | delete_ifile(mgmt_root, name, partition, IFILE) |
50 | 51 |
|
51 | 52 | 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) |
53 | 54 |
|
54 | 55 | request.addfinalizer(teardown) |
55 | 56 | return ifile1 |
56 | 57 |
|
57 | 58 |
|
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' |
0 commit comments