|
5 | 5 | from osf_tests.factories import ( |
6 | 6 | ProjectFactory, |
7 | 7 | AuthUserFactory, |
8 | | - PrivateLinkFactory |
| 8 | + PrivateLinkFactory, |
| 9 | + NodeRelationFactory |
9 | 10 | ) |
10 | 11 |
|
11 | 12 |
|
@@ -54,6 +55,11 @@ def view_only_link(public_project): |
54 | 55 | return view_only_link |
55 | 56 |
|
56 | 57 |
|
| 58 | +@pytest.fixture() |
| 59 | +def components_factory(): |
| 60 | + return ProjectFactory |
| 61 | + |
| 62 | + |
57 | 63 | @pytest.mark.django_db |
58 | 64 | class TestViewOnlyLinksList: |
59 | 65 |
|
@@ -227,3 +233,77 @@ def test_cannot_create_vol( |
227 | 233 | } |
228 | 234 | res = app.post_json_api(url, {'data': payload}, expect_errors=True) |
229 | 235 | assert res.status_code == 401 |
| 236 | + |
| 237 | + def test_create_vol_with_components( |
| 238 | + self, app, user, url, public_project, view_only_link, components_factory): |
| 239 | + component1 = components_factory(creator=user) |
| 240 | + component2 = components_factory(creator=user) |
| 241 | + component3 = components_factory(creator=user) |
| 242 | + NodeRelationFactory(parent=public_project, child=component1) |
| 243 | + NodeRelationFactory(parent=public_project, child=component2) |
| 244 | + NodeRelationFactory(parent=public_project, child=component3) |
| 245 | + |
| 246 | + url = f'{url}?embed=creator&embed=nodes' |
| 247 | + payload = { |
| 248 | + 'attributes': { |
| 249 | + 'name': 'testmultiplenodes', |
| 250 | + 'anonymous': False, |
| 251 | + }, |
| 252 | + 'relationships': { |
| 253 | + 'nodes': { |
| 254 | + 'data': [ |
| 255 | + { |
| 256 | + 'id': component1._id, |
| 257 | + 'type': 'nodes' |
| 258 | + }, |
| 259 | + { |
| 260 | + 'id': component2._id, |
| 261 | + 'type': 'nodes' |
| 262 | + }, |
| 263 | + { |
| 264 | + 'id': component3._id, |
| 265 | + 'type': 'nodes' |
| 266 | + } |
| 267 | + ] |
| 268 | + } |
| 269 | + } |
| 270 | + } |
| 271 | + res = app.post_json_api(url, {'data': payload}, auth=user.auth) |
| 272 | + assert res.status_code == 201 |
| 273 | + data = res.json['data'] |
| 274 | + assert len(data['embeds']['nodes']['data']) == 4 |
| 275 | + |
| 276 | + def test_create_vol_no_duplicated_components( |
| 277 | + self, app, user, url, public_project, view_only_link, components_factory): |
| 278 | + component1 = components_factory(creator=user) |
| 279 | + NodeRelationFactory(parent=public_project, child=component1) |
| 280 | + |
| 281 | + url = f'{url}?embed=creator&embed=nodes' |
| 282 | + payload = { |
| 283 | + 'attributes': { |
| 284 | + 'name': 'testmultiplenodes', |
| 285 | + 'anonymous': False, |
| 286 | + }, |
| 287 | + 'relationships': { |
| 288 | + 'nodes': { |
| 289 | + 'data': [ |
| 290 | + { |
| 291 | + 'id': component1._id, |
| 292 | + 'type': 'nodes' |
| 293 | + }, |
| 294 | + { |
| 295 | + 'id': component1._id, |
| 296 | + 'type': 'nodes' |
| 297 | + }, |
| 298 | + { |
| 299 | + 'id': component1._id, |
| 300 | + 'type': 'nodes' |
| 301 | + }, |
| 302 | + ] |
| 303 | + } |
| 304 | + } |
| 305 | + } |
| 306 | + res = app.post_json_api(url, {'data': payload}, auth=user.auth) |
| 307 | + assert res.status_code == 201 |
| 308 | + data = res.json['data'] |
| 309 | + assert len(data['embeds']['nodes']['data']) == 2 |
0 commit comments