Skip to content

Commit

Permalink
Added collection value property to user (#55)
Browse files Browse the repository at this point in the history
Co-authored-by: alistair.hughes <[email protected]>
  • Loading branch information
alifhughes and alistair.hughes authored May 21, 2021
1 parent d0a8ae8 commit 32e255b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
18 changes: 18 additions & 0 deletions discogs_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,11 @@ def collection_folders(self):
resp = self.client._get(self.fetch('collection_folders_url'))
return [CollectionFolder(self.client, d) for d in resp['folders']]

@property
def collection_value(self):
resp = self.client._get(f"{self.fetch('resource_url')}/collection/value")
return CollectionValue(self.client, resp)

def __repr__(self):
return '<User {0!r} {1!r}>'.format(self.id, self.username)

Expand Down Expand Up @@ -644,6 +649,18 @@ def __repr__(self):
return '<CollectionItemInstance {0!r} {1!r}>'.format(self.id, self.release.title)


class CollectionValue(PrimaryAPIObject):
maximum = SimpleField()
median = SimpleField()
minimum = SimpleField()

def __init__(self, client, dict_):
super(CollectionValue, self).__init__(client, dict_)

def __repr__(self):
return f"<CollectionValue {self.median}>"


class CollectionFolder(PrimaryAPIObject):
id = SimpleField()
name = SimpleField()
Expand Down Expand Up @@ -826,4 +843,5 @@ def __repr__(self):
'listing': Listing,
'wantlistitem': WantlistItem,
'ordermessage': OrderMessage,
'collectionvalue': CollectionValue,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"median": "£2.50", "minimum":"£1.05", "maximum":"£5"}
16 changes: 15 additions & 1 deletion discogs_client/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
from discogs_client.models import Artist, Release, ListItem
from discogs_client.models import Artist, Release, ListItem, CollectionValue
from discogs_client.tests import DiscogsClientTestCase
from discogs_client.exceptions import HTTPError

Expand Down Expand Up @@ -297,6 +297,20 @@ def test_marketplace_stats(self):
self.assertEqual(method, 'GET')
self.assertEqual(url, '/marketplace/stats/1')

def test_collection_value(self):
"""Collection Value can be fetched and parsed"""
u = self.d.user("example")

self.assertEqual(isinstance(u.collection_value, CollectionValue), True)
self.assertEqual(u.collection_value.minimum, "£1.05")
self.assertEqual(u.collection_value.maximum, "£5")
self.assertEqual(u.collection_value.median, "£2.50")

# Assert that request URL and method is correct.
method, url, data, headers = self.d._fetcher.requests[0]
self.assertEqual(method, "GET")
self.assertEqual(url, "/users/example/collection/value")


def suite():
suite = unittest.TestSuite()
Expand Down

0 comments on commit 32e255b

Please sign in to comment.