forked from demisto/demisto-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
146 lines (106 loc) · 4.04 KB
/
conftest.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
"""Configuring tests for the content suite
"""
from typing import Generator
from unittest import mock
import pytest
from _pytest.fixtures import FixtureRequest
from _pytest.tmpdir import TempPathFactory, _mk_tmp
import demisto_sdk.commands.common.tools as tools
from TestSuite.integration import Integration
from TestSuite.json_based import JSONBased
from TestSuite.pack import Pack
from TestSuite.playbook import Playbook
from TestSuite.repo import Repo
from TestSuite.yml import YAML
# Helper Functions
def get_repo(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Repo:
tmp_dir = _mk_tmp(request, tmp_path_factory)
return Repo(tmp_dir)
def get_git_repo(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Repo:
tmp_dir = _mk_tmp(request, tmp_path_factory)
return Repo(tmp_dir, init_git=True)
def get_pack(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Pack:
"""Mocking tmp_path"""
return get_repo(request, tmp_path_factory).create_pack()
def get_integration(
request: FixtureRequest, tmp_path_factory: TempPathFactory
) -> Integration:
"""Mocking tmp_path"""
integration = get_pack(request, tmp_path_factory).create_integration()
integration.create_default_integration()
return integration
def get_playbook(
request: FixtureRequest, tmp_path_factory: TempPathFactory
) -> Playbook:
"""Mocking tmp_path"""
playbook = get_pack(request, tmp_path_factory).create_playbook()
playbook.create_default_playbook()
return playbook
def get_script(request: FixtureRequest, tmp_path_factory: TempPathFactory):
script = get_pack(request, tmp_path_factory).create_script()
script.create_default_script()
return script
# Fixtures
@pytest.fixture
def pack(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Pack:
"""Mocking tmp_path"""
return get_pack(request, tmp_path_factory)
@pytest.fixture()
def script(request: FixtureRequest, tmp_path_factory: TempPathFactory):
return get_script(request, tmp_path_factory)
@pytest.fixture
def integration(
request: FixtureRequest, tmp_path_factory: TempPathFactory
) -> Integration:
"""Mocking tmp_path"""
return get_integration(request, tmp_path_factory)
@pytest.fixture
def repo(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Repo:
"""
Initializes a repo without git.
"""
return get_repo(request, tmp_path_factory)
@pytest.fixture
def git_repo(request: FixtureRequest, tmp_path_factory: TempPathFactory):
"""
Initializes a repo with git.
"""
return get_git_repo(request, tmp_path_factory)
@pytest.fixture(scope="module")
def module_repo(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Repo:
from demisto_sdk.commands.find_dependencies.tests.find_dependencies_test import (
working_repo,
)
return working_repo(get_repo(request, tmp_path_factory))
@pytest.fixture
def playbook(request: FixtureRequest, tmp_path_factory: TempPathFactory) -> Playbook:
"""Mocking tmp_path"""
return get_playbook(request, tmp_path_factory)
@pytest.fixture()
def malformed_integration_yml(integration) -> YAML:
"""
Provides an invalid integration yml structure.
"""
integration.yml.write("1: 2\n//")
return integration.yml
@pytest.fixture()
def malformed_incident_field(pack) -> JSONBased:
"""
Provides an invalid incident field json structure.
"""
incident_field = pack.create_incident_field("malformed")
incident_field.write_as_text("{\n '1': '1'")
return incident_field
@pytest.fixture(scope="session", autouse=True)
def mock_update_id_set_cpu_count() -> Generator:
"""
Since Circle build has an issue in it's virtualization where it has only 2 vcpu's but the 'cpu_count' method returns
all physical cpu's (36) it uses too many processes in the process pools.
"""
with mock.patch(
"demisto_sdk.commands.common.update_id_set.cpu_count", return_value=2
) as _fixture:
yield _fixture
@pytest.fixture(autouse=True)
def clear_cache():
tools.get_file.cache_clear()