-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
143 lines (127 loc) · 5.35 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
import pytest
from unittest import mock
import app
import boto3
from dcicutils.env_utils import EnvUtils
from dcicutils.env_manager import EnvManager
from dcicutils.misc_utils import ignored
from dcicutils.env_base import EnvBase
from foursight_core.app_utils import AppUtils
from foursight_core.sqs_utils import SQS
from foursight_core.environment import Environment
from foursight_core.decorators import Decorators
from foursight_core.react.api.auth0_config import Auth0Config
from foursight_core.react.api.react_api_base import ReactApiBase
GLOBAL_ENV_BUCKET = 'GLOBAL_ENV_BUCKET'
FOURSIGHT_PREFIX = 'foursight-core-simulated'
SIMULATED_GLOBAL_ENV_BUCKET = FOURSIGHT_PREFIX + '-envs'
DEV_ENV = 'simulated'
ES_HOST = 'https://search-fourfront-testing-opensearch-kqm7pliix4wgiu4druk2indorq.us-east-1.es.amazonaws.com'
SIMULATED_ENV_CONFIG = {
'simulated': {
'fourfront': 'dummy-url',
'es': ES_HOST, # maybe dont even need this?
'ff_env': 'fourfront-simulated',
'bucket': 'foursight-core-simulated-results',
},
'main.ecosystem': {
'public_url_table': [
{
'name': 'simulated',
'url': 'dummy-url',
'host': 'dummy-host',
'environment': 'fourfront-simulated'
}
],
'foursight_bucket_table': {
'simulated': {
'dev': 'foursight-core-simulated-results'
}
}
}
}
SIMULATED_ENV_HEALTH_PAGE = {
"@type": [
"Health",
"Portal"
],
"@context": "/health",
"@id": "/health",
"content": None,
"application_bucket_prefix": "elasticbeanstalk-",
"beanstalk_app_version": "unknown-version-at-20220614112027174894",
"beanstalk_env": "foursight-core-simulated",
"blob_bucket": "elasticbeanstalk-fourfront-mastertest-blobs",
"elasticsearch": "vpc-es-fourfront-mastertest-b3j36tdu7mwrgdxt6y7jt46dem.us-east-1.es.amazonaws.com:443",
"file_upload_bucket": "elasticbeanstalk-fourfront-mastertest-files",
"identity": "C4AppConfigFourfrontMastertestApplicationConfigurationfourfrontmastertest",
"indexer": "true",
"namespace": "foursight-core-simulated",
"processed_file_bucket": "elasticbeanstalk-fourfront-mastertest-wfoutput",
"project_version": "4.2.9",
"python_version": "3.7.12",
"snovault_version": "5.5.1",
"system_bucket": "elasticbeanstalk-fourfront-mastertest-system",
"tibanna_output_bucket": "tibanna-output",
"utils_version": "3.12.0.1b0"
}
deco = Decorators('placeholder_prefix')
CheckResult = deco.CheckResult
ActionResult = deco.ActionResult
check_function = deco.check_function
action_function = deco.action_function
class SimulatedAuth0Config(Auth0Config):
pass
class SimulatedAppUtils(AppUtils):
""" Overrides metadata such that we can bring up a simulated AppUtils object
without backing data in the cloud
"""
prefix = FOURSIGHT_PREFIX
host = ES_HOST # we need a live ES
DEFAULT_ENV = DEV_ENV # subclass is intended to set this
check_setup_file = 'foursight_core/check_setup.json' # use dummy file
def init_environments(self, env='all', envs=None):
""" Overrides this method to mock out the call to s3 to get valid
env info for simulation
"""
return SIMULATED_ENV_CONFIG
@pytest.fixture(scope='session', autouse=True)
def setup():
app.set_stage('test') # set the stage info for tests
test_client = boto3.client('sqs') # purge test queue
queue_url = SQS(FOURSIGHT_PREFIX).get_sqs_queue().url
try:
test_client.purge_queue(
QueueUrl=queue_url
)
except test_client.exceptions.PurgeQueueInProgress:
print('Cannot purge test queue; purge already in progress')
@pytest.yield_fixture(scope='function')
def global_env_bucket():
with EnvBase.global_env_bucket_named(SIMULATED_GLOBAL_ENV_BUCKET):
yield
@pytest.yield_fixture(scope='function')
def app_utils_obj_conn(global_env_bucket): # noQA pytest fixture
""" Mocks appropriate operations such that we can generate a simulated app_utils
object for a non-existent foursight environment.
Description of mocks:
* FOURSIGHT_BUCKET_PREFIX so consistency checks are passed
* verify_and_get_env_config to simulate an env entry
* fetch_health_page_json to simulate a portal health page API call
* queue_check to
"""
ignored(global_env_bucket)
with mock.patch.object(ReactApiBase, 'resolve_auth0_config',
return_value=SimulatedAuth0Config('https://dummy-url')):
with mock.patch.object(EnvUtils, 'FOURSIGHT_BUCKET_PREFIX', FOURSIGHT_PREFIX):
apputils = SimulatedAppUtils()
with mock.patch.object(EnvUtils, '_get_config_object_from_s3',
return_value=SIMULATED_ENV_CONFIG['main.ecosystem']):
with mock.patch.object(EnvManager, 'fetch_health_page_json',
return_value=SIMULATED_ENV_HEALTH_PAGE):
with mock.patch.object(Environment, 'get_environment_and_bucket_info',
return_value=SIMULATED_ENV_CONFIG['simulated']):
conn = apputils.init_connection(DEV_ENV)
with EnvUtils.temporary_state():
yield apputils, conn
return