-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathconftest.py
154 lines (124 loc) · 3.87 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
147
148
149
150
151
152
153
154
"""Fixtures for tests"""
import os
import pytest
import pytz
from constants import (
DJANGO,
LIBRARY_TYPE,
NPM,
PYTHON_VERSION,
NPM_VERSION,
SETUPTOOLS,
WEB_APPLICATION_TYPE,
)
from repo_info import RepoInfo
from test_util import make_test_repo
from test_util import async_wrapper
SETUP_PY = """
from setuptools import setup, find_packages
setup(
name='ccxcon',
version='0.2.0',
license='AGPLv3',
author='MIT ODL Engineering',
author_email='odl-engineering@mit.edu',
url='http://github.com/mitodl/ccxcon',
description="CCX Connector",
# long_description=README,
packages=find_packages(),
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Programming Language :: Python',
],
include_package_data=True,
zip_safe=False,
)
"""
WEB_TEST_REPO_INFO = RepoInfo(
name="doof_repo",
repo_url="http://github.com/mitodl/doof.git",
prod_hash_url="http://doof.example.com/hash.txt",
rc_hash_url="http://doof-rc.example.com/hash.txt",
ci_hash_url="http://doof-ci.example.com/hash.txt",
channel_id="doof",
project_type=WEB_APPLICATION_TYPE,
web_application_type=DJANGO,
packaging_tool=None,
versioning_strategy=PYTHON_VERSION,
)
# pylint: disable=redefined-outer-name, unused-argument
@pytest.fixture
def test_repo_directory():
"""Helper function to make a repo for testing"""
with make_test_repo() as working_dir:
yield working_dir
@pytest.fixture
def test_repo(test_repo_directory):
"""Initialize the testing repo from the gzipped file"""
yield WEB_TEST_REPO_INFO
NPM_TEST_REPO_INFO = RepoInfo(
name="node_doof",
repo_url="http://github.com/mitodl/doof-node.git",
prod_hash_url=None,
rc_hash_url=None,
ci_hash_url=None,
channel_id="doof-node",
project_type=LIBRARY_TYPE,
packaging_tool=NPM,
web_application_type=None,
versioning_strategy=NPM_VERSION,
)
LIBRARY_TEST_REPO_INFO = RepoInfo(
name="lib_repo",
repo_url="http://github.com/mitodl/doof-lib.git",
prod_hash_url=None,
rc_hash_url=None,
ci_hash_url=None,
channel_id="doof-lib",
project_type=LIBRARY_TYPE,
packaging_tool=SETUPTOOLS,
web_application_type=None,
versioning_strategy=PYTHON_VERSION,
)
@pytest.fixture
def library_test_repo_directory():
"""Directory created for testing with library_test_repo"""
with make_test_repo() as working_dir:
yield working_dir
@pytest.fixture
def library_test_repo(library_test_repo_directory):
"""Initialize the library test repo from the gzipped file"""
with open(
os.path.join(library_test_repo_directory, "setup.py"), "w", encoding="utf-8"
) as f:
# Hacky way to convert a web application project to a library
f.write(SETUP_PY)
yield LIBRARY_TEST_REPO_INFO
@pytest.fixture
def npm_library_test_repo(library_test_repo):
"""Create a repository"""
yield NPM_TEST_REPO_INFO
@pytest.fixture
def timezone():
"""Return a timezone object"""
yield pytz.timezone("America/New_York")
@pytest.fixture
def mocker(mocker): # pylint: disable=redefined-outer-name
"""Override to add async_patch"""
def async_patch(*args, **kwargs):
"""Add a helper function to patch with an async wrapped function, which is returned"""
mocked = mocker.Mock(**kwargs)
mocker.patch(*args, new_callable=lambda: async_wrapper(mocked))
return mocked
mocker.async_patch = async_patch
return mocker
def _raiser(message):
"""Raise an exception"""
raise Exception(message)
@pytest.fixture(autouse=True)
def log_exception(mocker):
"""Patch log.error and log.exception to raise an exception so tests do not silence it"""
mocker.patch("bot.log.exception", side_effect=_raiser)
mocker.patch("bot.log.error", side_effect=_raiser)