80 lines
2.4 KiB
Python
80 lines
2.4 KiB
Python
import json
|
|
import os
|
|
import sys
|
|
from unittest.mock import MagicMock
|
|
|
|
from fedora_messaging.config import conf as fm_config
|
|
import pytest
|
|
|
|
from toddlers.utils.cache import cache
|
|
from toddlers.utils.requests import make_session
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def disable_cache():
|
|
cache.configure(backend="dogpile.cache.null", replace_existing_backend=True)
|
|
|
|
|
|
@pytest.fixture
|
|
def toddler(request, monkeypatch):
|
|
"""Fixture creating a toddler for a class testing it
|
|
|
|
The test class must set the toddler class in its `toddler_cls` attribute.
|
|
The fixture will mock out the `make_session` function before creating the
|
|
object so that any request objects the toddler creates in its constructor
|
|
won't be real.
|
|
"""
|
|
test_cls = request.cls
|
|
if not hasattr(test_cls, "toddler_cls"):
|
|
raise RuntimeError(f"{test_cls} needs to set `toddler_cls`")
|
|
|
|
toddler_cls = test_cls.toddler_cls
|
|
toddler_module = sys.modules[toddler_cls.__module__]
|
|
|
|
for name in dir(toddler_module):
|
|
obj = getattr(toddler_module, name)
|
|
if obj is make_session:
|
|
monkeypatch.setattr(toddler_module, name, MagicMock())
|
|
|
|
monkeypatch.setitem(
|
|
fm_config,
|
|
"consumer_config",
|
|
{
|
|
"default": {
|
|
"dist_git_url": "https://src.fedoraproject.org",
|
|
},
|
|
},
|
|
)
|
|
|
|
toddler_obj = toddler_cls()
|
|
# disable the cache
|
|
cache.configure(backend="dogpile.cache.null", replace_existing_backend=True)
|
|
return toddler_obj
|
|
|
|
|
|
@pytest.fixture
|
|
def msg_file(request, monkeypatch):
|
|
"""Fixture creating a msg.json file containing the data sent by pungi upon
|
|
successful compose.
|
|
|
|
"""
|
|
data = {
|
|
"status": "FINISHED",
|
|
"release_type": "ga",
|
|
"compose_label": "RC-1.2",
|
|
"compose_respin": 0,
|
|
"compose_date": "20201019",
|
|
"release_short": "Fedora",
|
|
"release_version": "33",
|
|
"location": "https://kojipkgs.fedoraproject.org/compose/33/Fedora-33-20201019.0/compose",
|
|
"compose_type": "production",
|
|
"release_is_layered": False,
|
|
"release_name": "Fedora",
|
|
"compose_path": "/mnt/koji/compose/33/Fedora-33-20201019.0",
|
|
"compose_id": "Fedora-33-20201019.0",
|
|
}
|
|
here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
|
|
msg_file = os.path.join(here, "msg.json")
|
|
with open(msg_file, "w") as stream:
|
|
json.dump(data, stream)
|
|
return msg_file
|