2017-12-26 20:12:37 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from funkwhale_api.taskapp import celery
|
|
|
|
|
|
|
|
|
|
|
|
class Dummy:
|
|
|
|
@staticmethod
|
|
|
|
def noop(instance):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def test_require_instance_decorator(factories, mocker):
|
2018-06-09 13:36:16 +00:00
|
|
|
user = factories["users.User"]()
|
2017-12-26 20:12:37 +00:00
|
|
|
|
2018-06-09 13:36:16 +00:00
|
|
|
@celery.require_instance(user.__class__, "user")
|
2017-12-26 20:12:37 +00:00
|
|
|
def t(user):
|
|
|
|
Dummy.noop(user)
|
|
|
|
|
2018-06-09 13:36:16 +00:00
|
|
|
m = mocker.patch.object(Dummy, "noop")
|
2017-12-26 20:12:37 +00:00
|
|
|
t(user_id=user.pk)
|
|
|
|
|
|
|
|
m.assert_called_once_with(user)
|
|
|
|
|
|
|
|
|
|
|
|
def test_require_instance_decorator_accepts_qs(factories, mocker):
|
2018-06-09 13:36:16 +00:00
|
|
|
user = factories["users.User"](is_active=False)
|
2017-12-26 20:12:37 +00:00
|
|
|
qs = user.__class__.objects.filter(is_active=True)
|
|
|
|
|
2018-06-09 13:36:16 +00:00
|
|
|
@celery.require_instance(qs, "user")
|
2017-12-26 20:12:37 +00:00
|
|
|
def t(user):
|
|
|
|
pass
|
2018-06-09 13:36:16 +00:00
|
|
|
|
2017-12-26 20:12:37 +00:00
|
|
|
with pytest.raises(user.__class__.DoesNotExist):
|
|
|
|
t(user_id=user.pk)
|