|
1 | 1 | import unittest |
2 | | -from discogs_client.models import Artist, Release, ListItem, CollectionValue |
| 2 | +from discogs_client.models import Artist, Release, ListItem, CollectionValue, CollectionItemInstance |
3 | 3 | from discogs_client.tests import DiscogsClientTestCase |
4 | 4 | from discogs_client.exceptions import HTTPError |
5 | 5 |
|
@@ -265,7 +265,6 @@ def test_listing(self): |
265 | 265 | self.assertEqual(method, 'GET') |
266 | 266 | self.assertEqual(url, '/marketplace/listings/150899904') |
267 | 267 |
|
268 | | - |
269 | 268 | def test_collection(self): |
270 | 269 | """Collection folders can be manipulated""" |
271 | 270 | # Fetch the users collection folders from the filesystem |
@@ -314,6 +313,41 @@ def test_collection(self): |
314 | 313 | self.assertEqual(method, 'POST') |
315 | 314 | self.assertEqual(url, '/users/example/collection/folders/1/releases/1') |
316 | 315 |
|
| 316 | + def test_collection_move_release(self): |
| 317 | + """Collection items can be moved to another folder""" |
| 318 | + # Fetch the users collection folders from the filesystem |
| 319 | + u = self.d.user("example") |
| 320 | + self.assertEqual(u.collection_folders[2].id, 2) |
| 321 | + |
| 322 | + # Mock expected responses for move_release test using "MemoryFetcher" |
| 323 | + self.m._fetcher.fetcher.responses = { |
| 324 | + "/users/example/collection/folders": (b''' |
| 325 | + {"folders": [ |
| 326 | + {"resource_url": "/users/example/collection/folders/0", "id": 0, "name": "All"}, |
| 327 | + {"resource_url": "/users/example/collection/folders/1", "id": 1, "name": "Uncategorized folder"}, |
| 328 | + {"resource_url": "/users/example/collection/folders/2", "id": 2, "name": "Collection folder 2"} |
| 329 | + ]} |
| 330 | + ''', 200), |
| 331 | + # Mock the response of the POST request to the instance resource URL |
| 332 | + "/users/example/collection/folders/1/releases/123456/instances/123": (b"", 204), |
| 333 | + } |
| 334 | + |
| 335 | + # Bind the user to the MemoryFetcher |
| 336 | + u.client = self.m |
| 337 | + |
| 338 | + # Mock a collection item instance |
| 339 | + instance = CollectionItemInstance( |
| 340 | + client=u.client, |
| 341 | + dict_={"id": 123456, "instance_id": 123} |
| 342 | + ) |
| 343 | + # Perform the move |
| 344 | + u.collection_folders[1].move_release(instance, 2) |
| 345 | + |
| 346 | + # Verify |
| 347 | + method, url, _, _ = self.m._fetcher.last_request |
| 348 | + self.assertEqual(method, "POST") |
| 349 | + self.assertEqual(url, "/users/example/collection/folders/1/releases/123456/instances/123") |
| 350 | + |
317 | 351 | def test_delete_object(self): |
318 | 352 | """Can request DELETE on an APIObject""" |
319 | 353 | u = self.d.user('example') |
|
0 commit comments