forked from kernelci/kcidb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
51 lines (45 loc) · 1.67 KB
/
test_main.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
"""main.py tests"""
import os
import subprocess
import unittest
from unittest.mock import patch
from importlib import import_module
import yaml
class MainTestCase(unittest.TestCase):
"""main.py test case"""
def test_google_credentials_are_not_specified(self):
"""Check Google Application credentials are not specified"""
self.assertIsNone(os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"),
"Tests must run without "
"GOOGLE_APPLICATION_CREDENTIALS "
"environment variable")
@patch('kcidb.misc.get_secret')
@patch('kcidb.mq.ORMPatternPublisher')
@patch('kcidb.mq.IOSubscriber')
@patch('kcidb.monitor.spool.Client')
@patch('kcidb.db.Client')
@patch('kcidb.oo.Client')
# pylint: disable=unused-argument,too-many-arguments
def test_import(self, oo_client, db_client, spool_client,
mq_publisher, mq_subscriber, get_secret):
"""Check main.py can be loaded"""
# Load deployment environment variables
file_dir = os.path.dirname(os.path.abspath(__file__))
cloud_path = os.path.join(file_dir, "cloud")
env = yaml.safe_load(
subprocess.check_output([
cloud_path,
"env", "kernelci-production", "", "0",
"--log-level=DEBUG"
])
)
env["GCP_PROJECT"] = "TEST_PROJECT"
orig_env = dict(os.environ)
try:
os.environ.update(env)
import_module("main")
finally:
os.environ.clear()
os.environ.update(orig_env)
# Piss off, pylint
self.assertTrue(not False)