Skip to content

Commit

Permalink
chore(tests): added and adjusted tests for project command
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Sep 5, 2023
1 parent 1683fb2 commit f44333f
Show file tree
Hide file tree
Showing 8 changed files with 16,750 additions and 93,506 deletions.
3 changes: 1 addition & 2 deletions api/outdated/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from outdated.outdated.models import Project


class ProjectCommand(BaseCommand):
def add_arguments(self, parser: CommandParser):
projects = parser.add_mutually_exclusive_group(required=True)
Expand Down Expand Up @@ -37,5 +36,5 @@ def handle(self, *args, **options):
for project in projects:
self._handle(project)

def _handle(self, project: Project): # pragma: no cover
def _handle(self, project: Project): # pragma: no cover
raise NotImplementedError()
20,306 changes: 14,548 additions & 5,758 deletions api/outdated/outdated/tests/cassettes/test_sync_project_endpoint.yaml

Large diffs are not rendered by default.

3,054 changes: 1,658 additions & 1,396 deletions api/outdated/outdated/tests/cassettes/test_syncproject.yaml

Large diffs are not rendered by default.

85,831 changes: 0 additions & 85,831 deletions api/outdated/outdated/tests/cassettes/test_syncprojects.yaml

This file was deleted.

25 changes: 7 additions & 18 deletions api/outdated/outdated/tests/test_syncproject.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
from unittest.mock import ANY

import pytest
from django.core.management import call_command

from outdated.outdated.synchroniser import Synchroniser


@pytest.mark.vcr()
@pytest.mark.django_db(transaction=True)
def test_syncproject(project_factory):
call_command("syncproject", "foo")

def test_syncproject(project_factory, mocker):
project = project_factory.create(repo="https://github.com/projectcaluma/caluma")

sync_init_mocker = mocker.spy(Synchroniser, "__init__")
call_command("syncproject", project.name)
assert project.versioned_dependencies.count() > 0


@pytest.mark.vcr()
@pytest.mark.django_db(transaction=True)
def test_syncprojects(project_factory):
projects = [
project_factory(repo=f"https://github.com/adfinis/{project}")
for project in ["outdated", "mysagw"]
]

call_command("syncprojects")
for project in projects:
assert project.versioned_dependencies.count() > 0
sync_init_mocker.assert_called_once_with(ANY, project)
37 changes: 37 additions & 0 deletions api/outdated/tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from unittest.mock import call

import pytest

from outdated.commands import ProjectCommand


@pytest.mark.parametrize("all", [True, False])
def test_command_handle(transactional_db, project_factory, all, mocker):
projects = project_factory.create_batch(5)
argv = ["", "project-command-test"]
handle_mocker = mocker.patch.object(ProjectCommand, "_handle")
ProjectCommand().run_from_argv(
[*argv, *(["--all"] if all else [project.name for project in projects])]
)
handle_mocker.assert_has_calls([call(project) for project in projects], True)


@pytest.mark.parametrize(
"existing_projects",
[
[],
["foo"],
["Foo"],
["foo", "foobar"],
],
)
@pytest.mark.parametrize("nonexistant_projects", [["bar"], ["bar", "baz"]])
def test_project_command(
transactional_db, project_factory, capsys, nonexistant_projects, existing_projects
):
argv = ["", "project-command-test"]
for project in existing_projects:
project_factory(name=project)
ProjectCommand().run_from_argv([*argv, *nonexistant_projects, *existing_projects])
_, stderr = capsys.readouterr()
assert stderr == f"Projects with names {nonexistant_projects} do not exist\n"
999 changes: 498 additions & 501 deletions api/poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pytest = "7.3.1"
isort = "5.11.4"
pytest-factoryboy = "2.5.1"
pytest-cov = "^4.0.0"
pytest-mock = "^3.11.1"
pytest-vcr = "^1.0.2"
pdbpp = "^0.10.3"
requests-mock = "^1.10.0"
Expand Down

0 comments on commit f44333f

Please sign in to comment.