funkwhale/api/tests/test_tasks.py

35 wiersze
750 B
Python
Czysty Zwykły widok Historia

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"]()
2018-06-09 13:36:16 +00:00
@celery.require_instance(user.__class__, "user")
def t(user):
Dummy.noop(user)
2018-06-09 13:36:16 +00:00
m = mocker.patch.object(Dummy, "noop")
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)
qs = user.__class__.objects.filter(is_active=True)
2018-06-09 13:36:16 +00:00
@celery.require_instance(qs, "user")
def t(user):
pass
2018-06-09 13:36:16 +00:00
with pytest.raises(user.__class__.DoesNotExist):
t(user_id=user.pk)