forked from openapi-generators/openapi-python-client
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest___init__.py
More file actions
62 lines (45 loc) · 2.34 KB
/
test___init__.py
File metadata and controls
62 lines (45 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from unittest.mock import MagicMock
import pytest
from openapi_python_client import Config, ErrorLevel, Project
from openapi_python_client.config import ConfigFile
default_http_timeout = ConfigFile.model_json_schema()["properties"]["http_timeout"]["default"]
def make_project(config: Config) -> Project:
return Project(openapi=MagicMock(title="My Test API"), config=config)
@pytest.fixture
def project_with_dir(config) -> Project:
"""Return a Project with the project dir pre-made (needed for cwd of commands). Unlinks after the test completes"""
project = make_project(config)
project.project_dir.mkdir()
yield project
project.project_dir.rmdir()
class TestProject:
def test__run_post_hooks_reports_missing_commands(self, project_with_dir: Project) -> None:
fake_command_name = "blahblahdoesntexist"
project_with_dir.config.post_hooks = [fake_command_name]
need_to_make_cwd = not project_with_dir.project_dir.exists()
if need_to_make_cwd:
project_with_dir.project_dir.mkdir()
project_with_dir._run_post_hooks()
assert len(project_with_dir.errors) == 1
error = project_with_dir.errors[0]
assert error.level == ErrorLevel.WARNING
assert error.header == "Skipping Integration"
assert fake_command_name in error.detail
def test__run_post_hooks_reports_stdout_of_commands_that_error_with_no_stderr(self, project_with_dir):
failing_command = "python3 -c \"print('a message'); exit(1)\""
project_with_dir.config.post_hooks = [failing_command]
project_with_dir._run_post_hooks()
assert len(project_with_dir.errors) == 1
error = project_with_dir.errors[0]
assert error.level == ErrorLevel.ERROR
assert error.header == "python3 failed"
assert "a message" in error.detail
def test__run_post_hooks_reports_stderr_of_commands_that_error(self, project_with_dir):
failing_command = "python3 -c \"print('a message'); raise Exception('some exception')\""
project_with_dir.config.post_hooks = [failing_command]
project_with_dir._run_post_hooks()
assert len(project_with_dir.errors) == 1
error = project_with_dir.errors[0]
assert error.level == ErrorLevel.ERROR
assert error.header == "python3 failed"
assert "some exception" in error.detail