Skip to content

Commit 19bbf4d

Browse files
committed
chore(tests): added and adjusted tests for project command
1 parent ad58983 commit 19bbf4d

File tree

7 files changed

+16746
-93579
lines changed

7 files changed

+16746
-93579
lines changed

api/outdated/outdated/tests/cassettes/test_sync_project_endpoint.yaml

Lines changed: 14548 additions & 5758 deletions
Large diffs are not rendered by default.

api/outdated/outdated/tests/cassettes/test_syncproject.yaml

Lines changed: 1658 additions & 1396 deletions
Large diffs are not rendered by default.

api/outdated/outdated/tests/cassettes/test_syncprojects.yaml

Lines changed: 0 additions & 85831 deletions
This file was deleted.
Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
1+
from unittest.mock import ANY
2+
13
import pytest
24
from django.core.management import call_command
35

6+
from outdated.outdated.synchroniser import Synchroniser
7+
48

59
@pytest.mark.vcr()
610
@pytest.mark.django_db(transaction=True)
7-
def test_syncproject(project_factory):
8-
call_command("syncproject", "foo")
9-
11+
def test_syncproject(project_factory, mocker):
1012
project = project_factory.create(repo="https://github.com/projectcaluma/caluma")
11-
13+
sync_init_mocker = mocker.spy(Synchroniser, "__init__")
1214
call_command("syncproject", project.name)
13-
assert project.versioned_dependencies.count() > 0
14-
15-
16-
@pytest.mark.vcr()
17-
@pytest.mark.django_db(transaction=True)
18-
def test_syncprojects(project_factory):
19-
projects = [
20-
project_factory(repo=f"https://github.com/adfinis/{project}")
21-
for project in ["outdated", "mysagw"]
22-
]
23-
24-
call_command("syncprojects")
25-
for project in projects:
26-
assert project.versioned_dependencies.count() > 0
15+
sync_init_mocker.assert_called_once_with(ANY, project)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from unittest.mock import call
2+
3+
import pytest
4+
5+
from outdated.commands import ProjectCommand
6+
7+
8+
@pytest.mark.parametrize("all", [True, False])
9+
def test_command_handle(transactional_db, project_factory, all, mocker):
10+
projects = project_factory.create_batch(5)
11+
argv = ["", "project-command-test"]
12+
handle_mocker = mocker.patch.object(ProjectCommand, "_handle")
13+
ProjectCommand().run_from_argv(
14+
[*argv, *(["--all"] if all else [project.name for project in projects])]
15+
)
16+
handle_mocker.assert_has_calls([call(project) for project in projects], True)
17+
18+
19+
@pytest.mark.parametrize(
20+
"existing_projects",
21+
[
22+
[],
23+
["foo"],
24+
["Foo"],
25+
["foo", "foobar"],
26+
],
27+
)
28+
@pytest.mark.parametrize("nonexistant_projects", [["bar"], ["bar", "baz"]])
29+
def test_project_command(
30+
transactional_db, project_factory, capsys, nonexistant_projects, existing_projects
31+
):
32+
argv = ["", "project-command-test"]
33+
for project in existing_projects:
34+
project_factory(name=project)
35+
ProjectCommand().run_from_argv([*argv, *nonexistant_projects, *existing_projects])
36+
_, stderr = capsys.readouterr()
37+
assert stderr == f"Projects with names {nonexistant_projects} do not exist\n"

api/poetry.lock

Lines changed: 495 additions & 576 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pytest-cov = "^4.0.0"
3838
pytest-vcr = "^1.0.2"
3939
pdbpp = "^0.10.3"
4040
requests-mock = "^1.10.0"
41+
pytest-mock = "^3.11.1"
4142

4243

4344
[tool.isort]

0 commit comments

Comments
 (0)