Skip to content

Commit

Permalink
test: Add unit tests for service models
Browse files Browse the repository at this point in the history
  • Loading branch information
NucciTheBoss committed Feb 15, 2024
1 parent 350ca69 commit 89b9807
Show file tree
Hide file tree
Showing 2 changed files with 550 additions and 1 deletion.
46 changes: 45 additions & 1 deletion tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@

"""Configure unit tests."""

from unittest.mock import MagicMock
from unittest.mock import MagicMock, PropertyMock

import pytest
from snaphelpers import Snap, SnapConfig, SnapConfigOptions, SnapServices
from snaphelpers._ctl import ServiceInfo

from slurmhelpers.models import Munge, Slurm, Slurmd, Slurmdbd, Slurmrestd


@pytest.fixture
Expand Down Expand Up @@ -64,3 +67,44 @@ def snap_empty_config(env):
snap.config = MagicMock(SnapConfig)
snap.services = MagicMock(SnapServices)
yield snap


@pytest.fixture
def base_model(snap):
"""Create a mock `_BaseModel` object."""
service = MagicMock(ServiceInfo)
type(service).active = PropertyMock(return_value=False)
snap.services.list.return_value = {"test": service}
# Use the `Slurm` data model since `_BaseModel` is an abstract class.
# `_BaseModel` cannot be directly instantiated since `update_config`
# is an abstract method.
yield Slurm(snap)


@pytest.fixture
def munge(snap):
"""Create a mock `Munge` object."""
yield Munge(snap)


@pytest.fixture
def slurm(snap):
"""Create a mock `Slurm` object."""
yield Slurm(snap)


@pytest.fixture
def slurmd(snap):
"""Create a mock `Slurmd` object."""
yield Slurmd(snap)


@pytest.fixture
def slurmdbd(snap):
yield Slurmdbd(snap)


@pytest.fixture
def slurmrestd(snap):
"""Create a mock `Slurmrestd` object."""
yield Slurmrestd(snap)
Loading

0 comments on commit 89b9807

Please sign in to comment.