|
| 1 | +import pytest |
| 2 | +from tests.integration import asserts |
| 3 | +from threescale_api import errors |
| 4 | +from .asserts import assert_resource, assert_resource_params |
| 5 | + |
| 6 | + |
| 7 | +# Files |
| 8 | +def test_file_list(api, cms_file): |
| 9 | + """ List all files. """ |
| 10 | + assert len(api.cms_files.list()) >= 1 |
| 11 | + |
| 12 | + |
| 13 | +def test_file_can_be_created(cms_file_data, cms_file): |
| 14 | + """ Is file created properly? """ |
| 15 | + assert_resource(cms_file) |
| 16 | + assert_resource_params(cms_file, cms_file_data) |
| 17 | + |
| 18 | + |
| 19 | +def test_file_can_be_read(api, cms_file_data, cms_file): |
| 20 | + """ It is possible to get file by ID? """ |
| 21 | + read = api.cms_files.read(cms_file.entity_id) |
| 22 | + asserts.assert_resource(read) |
| 23 | + asserts.assert_resource_params(read, cms_file_data) |
| 24 | + |
| 25 | + |
| 26 | +def test_file_can_be_read_by_name(api, cms_file_data, cms_file): |
| 27 | + """ It is possible to get file by name? """ |
| 28 | + file_path = cms_file['path'] |
| 29 | + read = api.cms_files[file_path] |
| 30 | + asserts.assert_resource(read) |
| 31 | + asserts.assert_resource_params(read, cms_file_data) |
| 32 | + |
| 33 | + |
| 34 | +def test_file_can_be_updated(cms_file_data, cms_file): |
| 35 | + """ Can be file object updated? """ |
| 36 | + updated_path = cms_file['path'] + 'up' |
| 37 | + cms_file['path'] = cms_file['path'] + 'up' |
| 38 | + # TODO https://issues.redhat.com/browse/THREESCALE-9571 |
| 39 | + for item in "created_at", "updated_at", "url", "title", "content_type": |
| 40 | + cms_file.pop(item) |
| 41 | + cms_file.update() |
| 42 | + assert cms_file['path'] == updated_path |
| 43 | + updated = cms_file.read() |
| 44 | + assert updated['path'] == updated_path |
| 45 | + assert cms_file['path'] == updated_path |
| 46 | + |
| 47 | + |
| 48 | +# Sections |
| 49 | + |
| 50 | + |
| 51 | +def test_section_list(api, cms_section): |
| 52 | + """ List all sections. """ |
| 53 | + assert len(api.cms_sections.list()) >= 1 |
| 54 | + |
| 55 | + |
| 56 | +def test_section_can_be_created(cms_section_params, cms_section): |
| 57 | + """ Is section created properly? """ |
| 58 | + assert_resource(cms_section) |
| 59 | + assert_resource_params(cms_section, cms_section_params) |
| 60 | + |
| 61 | + |
| 62 | +def test_section_can_be_read(api, cms_section_params, cms_section): |
| 63 | + """ It is possible to get section by ID? """ |
| 64 | + read = api.cms_sections.read(cms_section.entity_id) |
| 65 | + asserts.assert_resource(read) |
| 66 | + asserts.assert_resource_params(read, cms_section_params) |
| 67 | + |
| 68 | + |
| 69 | +def test_section_can_be_updated(cms_section_params, cms_section): |
| 70 | + """ Can be section object updated? """ |
| 71 | + updated_title = cms_section['title'] + 'up' |
| 72 | + cms_section['title'] = cms_section['title'] + 'up' |
| 73 | + # TODO https://issues.redhat.com/browse/THREESCALE-9571 |
| 74 | + for item in "created_at", "updated_at": |
| 75 | + cms_section.pop(item) |
| 76 | + cms_section.update() |
| 77 | + assert cms_section['title'] == updated_title |
| 78 | + updated = cms_section.read() |
| 79 | + assert updated['title'] == updated_title |
| 80 | + assert cms_section['title'] == updated_title |
| 81 | + |
| 82 | + |
| 83 | +# # bug!!! TODO https://issues.redhat.com/browse/THREESCALE-9572 |
| 84 | +# def test_builtin_section_delete(api): |
| 85 | +# """It is not possible to delete section partial.""" |
| 86 | +# with pytest.raises(errors.ApiClientError) as exc_info: |
| 87 | +# api.cms_sections.list()[0].delete() |
| 88 | +# assert exc_info.value.code == 423 |
| 89 | +# # TODO |
| 90 | +# # assert exc_info.value.code == 400 |
| 91 | + |
| 92 | + |
| 93 | +# Partials |
| 94 | +# builtin |
| 95 | + |
| 96 | + |
| 97 | +def test_builtin_partials_list(api): |
| 98 | + """ List all sections. """ |
| 99 | + assert len(api.cms_builtin_partials.list()) >= 1 |
| 100 | + |
| 101 | + |
| 102 | +def test_builtin_partial_can_be_read(api): |
| 103 | + """ It is possible to get partial by ID? """ |
| 104 | + cms_partial = api.cms_builtin_partials.list()[-1] |
| 105 | + read = api.cms_builtin_partials.read(cms_partial.entity_id) |
| 106 | + asserts.assert_resource(read) |
| 107 | + |
| 108 | +def test_builtin_partial_delete(api): |
| 109 | + """It is not possible to delete builtin partial.""" |
| 110 | + with pytest.raises(errors.ApiClientError) as exc_info: |
| 111 | + api.cms_builtin_partials.list()[0].delete() |
| 112 | + assert exc_info.value.code == 423 |
| 113 | + # TODO https://issues.redhat.com/browse/THREESCALE-9572 |
| 114 | + # assert exc_info.value.code == 400 |
| 115 | + |
| 116 | +# user |
| 117 | + |
| 118 | + |
| 119 | +def test_partial_list(api, cms_partial): |
| 120 | + """ List all user defined partials. """ |
| 121 | + assert len(api.cms_partials.list()) >= 1 |
| 122 | + |
| 123 | + |
| 124 | +def test_partial_can_be_created(cms_partial_params, cms_partial): |
| 125 | + """ Is partial created properly? """ |
| 126 | + assert_resource(cms_partial) |
| 127 | + assert_resource_params(cms_partial, cms_partial_params) |
| 128 | + |
| 129 | + |
| 130 | +def test_partial_can_be_read(api, cms_partial_params, cms_partial): |
| 131 | + """ It is possible to get partial by ID? """ |
| 132 | + read = api.cms_partials.read(cms_partial.entity_id) |
| 133 | + asserts.assert_resource(read) |
| 134 | + asserts.assert_resource_params(read, cms_partial_params) |
| 135 | + |
| 136 | + |
| 137 | +def test_partial_can_be_updated(cms_partial_params, cms_partial): |
| 138 | + """ Can be partial object updated? """ |
| 139 | + updated_draft = cms_partial['draft'] + 'up' |
| 140 | + cms_partial['draft'] = cms_partial['draft'] + 'up' |
| 141 | + # TODO https://issues.redhat.com/browse/THREESCALE-9571 |
| 142 | + for item in "created_at", "updated_at", "published": |
| 143 | + cms_partial.pop(item) |
| 144 | + cms_partial.update() |
| 145 | + assert cms_partial['draft'] == updated_draft |
| 146 | + updated = cms_partial.read() |
| 147 | + assert updated['draft'] == updated_draft |
| 148 | + assert cms_partial['draft'] == updated_draft |
| 149 | + |
| 150 | + |
| 151 | +def test_partial_publish(cms_partial): |
| 152 | + """ Test publishing of partials. """ |
| 153 | + assert cms_partial.entity.get('published', None) is None |
| 154 | + draft = cms_partial['draft'] |
| 155 | + cms_partial = cms_partial.publish() |
| 156 | + # assert draft == cms_partial['draft'] bug |
| 157 | + # assert cms_partial['published'] == cms_partial['draft'] bug |
| 158 | + assert draft == cms_partial['published'] |
| 159 | + |
| 160 | + |
| 161 | +# Pages |
| 162 | +# builtin |
| 163 | + |
| 164 | + |
| 165 | +def test_builtin_pages_list(api): |
| 166 | + """ List all sections. """ |
| 167 | + assert len(api.cms_builtin_pages.list()) >= 1 |
| 168 | + |
| 169 | + |
| 170 | +def test_builtin_page_can_be_read(api): |
| 171 | + """ It is possible to get page by ID? """ |
| 172 | + cms_page = api.cms_builtin_pages.list()[-1] |
| 173 | + read = api.cms_builtin_pages.read(cms_page.entity_id) |
| 174 | + asserts.assert_resource(read) |
| 175 | + |
| 176 | + |
| 177 | +def test_builtin_page_delete(api): |
| 178 | + """It is not possible to delete builtin page.""" |
| 179 | + with pytest.raises(errors.ApiClientError) as exc_info: |
| 180 | + api.cms_builtin_pages.list()[0].delete() |
| 181 | + assert exc_info.value.code == 423 |
| 182 | + # TODO https://issues.redhat.com/browse/THREESCALE-9572 |
| 183 | + # assert exc_info.value.code == 400 |
| 184 | + |
| 185 | + |
| 186 | +# user |
| 187 | + |
| 188 | + |
| 189 | +def test_page_list(api, cms_page): |
| 190 | + """ List all user defined pages. """ |
| 191 | + assert len(api.cms_pages.list()) >= 1 |
| 192 | + |
| 193 | + |
| 194 | +def test_page_can_be_created(cms_page_params, cms_page): |
| 195 | + """ Is page created properly? """ |
| 196 | + assert_resource(cms_page) |
| 197 | + assert_resource_params(cms_page, cms_page_params) |
| 198 | + |
| 199 | + |
| 200 | +def test_page_can_be_read(api, cms_page_params, cms_page): |
| 201 | + """ It is possible to get page by ID? """ |
| 202 | + read = api.cms_pages.read(cms_page.entity_id) |
| 203 | + asserts.assert_resource(read) |
| 204 | + asserts.assert_resource_params(read, cms_page_params) |
| 205 | + |
| 206 | + |
| 207 | +def test_page_can_be_updated(cms_page_params, cms_page): |
| 208 | + """ Can be page object updated? """ |
| 209 | + updated_draft = cms_page['draft'] + 'up' |
| 210 | + cms_page['draft'] = cms_page['draft'] + 'up' |
| 211 | + # TODO https://issues.redhat.com/browse/THREESCALE-9571 |
| 212 | + for item in "created_at", "updated_at", "hidden", "published": |
| 213 | + cms_page.pop(item) |
| 214 | + cms_page.update() |
| 215 | + assert cms_page['draft'] == updated_draft |
| 216 | + updated = cms_page.read() |
| 217 | + assert updated['draft'] == updated_draft |
| 218 | + assert cms_page['draft'] == updated_draft |
| 219 | + |
| 220 | + |
| 221 | +def test_page_publish(cms_page): |
| 222 | + """ Test publishing of pages. """ |
| 223 | + assert cms_page.entity.get('published', None) is None |
| 224 | + draft = cms_page['draft'] |
| 225 | + cms_page = cms_page.publish() |
| 226 | + # assert draft == cms_page['draft'] bug |
| 227 | + # assert cms_page['published'] == cms_page['draft'] bug |
| 228 | + assert draft == cms_page['published'] |
| 229 | + |
| 230 | + |
| 231 | +# Layouts |
| 232 | + |
| 233 | + |
| 234 | +def test_layout_list(api, cms_layout): |
| 235 | + """ List all user defined layouts. """ |
| 236 | + assert len(api.cms_layouts.list()) >= 1 |
| 237 | + |
| 238 | + |
| 239 | +def test_layout_can_be_created(cms_layout_params, cms_layout): |
| 240 | + """ Is layout created properly? """ |
| 241 | + assert_resource(cms_layout) |
| 242 | + assert_resource_params(cms_layout, cms_layout_params) |
| 243 | + |
| 244 | + |
| 245 | +def test_layout_can_be_read(api, cms_layout_params, cms_layout): |
| 246 | + """ It is possible to get layout by ID? """ |
| 247 | + read = api.cms_layouts.read(cms_layout.entity_id) |
| 248 | + asserts.assert_resource(read) |
| 249 | + asserts.assert_resource_params(read, cms_layout_params) |
| 250 | + |
| 251 | + |
| 252 | +def test_layout_can_be_updated(cms_layout_params, cms_layout): |
| 253 | + """ Can be layout object updated? """ |
| 254 | + updated_draft = cms_layout['draft'] + 'up' |
| 255 | + cms_layout['draft'] = cms_layout['draft'] + 'up' |
| 256 | + # TODO https://issues.redhat.com/browse/THREESCALE-9571 |
| 257 | + for item in "created_at", "updated_at", "published": |
| 258 | + cms_layout.pop(item) |
| 259 | + cms_layout.update() |
| 260 | + assert cms_layout['draft'] == updated_draft |
| 261 | + updated = cms_layout.read() |
| 262 | + assert updated['draft'] == updated_draft |
| 263 | + assert cms_layout['draft'] == updated_draft |
| 264 | + |
| 265 | + |
| 266 | +def test_layout_publish(cms_layout): |
| 267 | + """ Test publishing of layouts. """ |
| 268 | + assert cms_layout.entity.get('published', None) is None |
| 269 | + draft = cms_layout['draft'] |
| 270 | + cms_layout = cms_layout.publish() |
| 271 | + # assert draft == cms_layout['draft'] bug |
| 272 | + # assert cms_layout['published'] == cms_layout['draft'] bug |
| 273 | + assert draft == cms_layout['published'] |
0 commit comments