mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 04:09:16 +02:00
See #170: now record downloads count on tracks/uploads
This commit is contained in:
parent
3674d1235d
commit
b22b9c83b0
12 changed files with 161 additions and 18 deletions
|
@ -45,3 +45,49 @@ def test_guess_mimetype_dont_crash_with_s3(factories, mocker, settings):
|
|||
f = factories["music.Upload"].build(audio_file__filename="test.mp3")
|
||||
|
||||
assert utils.guess_mimetype(f.audio_file) == "audio/mpeg"
|
||||
|
||||
|
||||
def test_increment_downloads_count(factories, mocker, cache, anonymous_user, settings):
|
||||
ident = {"type": "anonymous", "id": "noop"}
|
||||
get_ident = mocker.patch(
|
||||
"funkwhale_api.common.throttling.get_ident", return_value=ident
|
||||
)
|
||||
cache_set = mocker.spy(utils.cache, "set")
|
||||
wsgi_request = mocker.Mock(META={})
|
||||
upload = factories["music.Upload"]()
|
||||
utils.increment_downloads_count(
|
||||
upload=upload, user=anonymous_user, wsgi_request=wsgi_request
|
||||
)
|
||||
|
||||
upload.refresh_from_db()
|
||||
get_ident.assert_called_once_with(user=anonymous_user, request=wsgi_request)
|
||||
|
||||
assert upload.downloads_count == 1
|
||||
assert upload.track.downloads_count == 1
|
||||
cache_set.assert_called_once_with(
|
||||
"downloads_count:upload-{}:{}-{}".format(upload.pk, ident["type"], ident["id"]),
|
||||
1,
|
||||
settings.MIN_DELAY_BETWEEN_DOWNLOADS_COUNT,
|
||||
)
|
||||
|
||||
|
||||
def test_increment_downloads_count_already_tracked(
|
||||
factories, mocker, cache, anonymous_user
|
||||
):
|
||||
ident = {"type": "anonymous", "id": "noop"}
|
||||
mocker.patch("funkwhale_api.common.throttling.get_ident", return_value=ident)
|
||||
wsgi_request = mocker.Mock(META={})
|
||||
upload = factories["music.Upload"]()
|
||||
cache.set(
|
||||
"downloads_count:upload-{}:{}-{}".format(upload.pk, ident["type"], ident["id"]),
|
||||
1,
|
||||
)
|
||||
|
||||
utils.increment_downloads_count(
|
||||
upload=upload, user=anonymous_user, wsgi_request=wsgi_request
|
||||
)
|
||||
|
||||
upload.refresh_from_db()
|
||||
|
||||
assert upload.downloads_count == 0
|
||||
assert upload.track.downloads_count == 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue