import pytest
from django.core.exceptions import ImproperlyConfigured

from dj_raincheck.decorators import raincheck


def test_missing_installed_app(settings):
    settings.INSTALLED_APPS = []

    with pytest.raises(ImproperlyConfigured, match="'dj_raincheck' must be in INSTALLED_APPS"):

        @raincheck
        def _():
            pass


def test_schedule(settings):
    @raincheck
    def func():
        pass

    assert hasattr(func, "schedule")


def test_internal(settings):
    @raincheck
    def func():
        pass

    expected = {}
    actual = func.__raincheck

    assert actual == expected


def test_internal_with_function(settings):
    @raincheck()
    def func():
        pass

    expected = {}
    actual = func.__raincheck

    assert actual == expected


def test_internal_with_kwargs(settings):
    @raincheck(blob=1)
    def func():
        pass

    expected = {"blob": 1}
    actual = func.__raincheck

    assert actual == expected


def test_docstring(settings):
    @raincheck(blob=1)
    def func():
        """This is a docstring"""
        pass

    expected = "This is a docstring"
    actual = func.__doc__

    assert actual == expected
