Skip to content

Commit 78adbae

Browse files
committed
fix: Update unit test
* Fix unit test by using full function/method/object path * Rename unit to test_unit python file * Move data information into a specific python file
1 parent ee0ca4b commit 78adbae

3 files changed

Lines changed: 71 additions & 69 deletions

File tree

tests/data.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
SETTINGS = {
3+
'name': 'Example Tenant',
4+
'identity': 'abc',
5+
'secret': 'def',
6+
'url': 'example.prismacloud.io',
7+
'verify': False,
8+
'debug': False
9+
}
10+
11+
META_INFO = {
12+
'twistlockUrl': 'example.prismacloud.io'
13+
}
14+
15+
USER_PROFILE = {
16+
'email': 'example@example.com',
17+
'firstName': 'Example',
18+
'lastName': 'User',
19+
'timeZone': 'America/Los_Angeles',
20+
'enabled': True,
21+
'lastModifiedBy': 'template@redlock.io',
22+
'lastModifiedTs': 1630000000000,
23+
'lastLoginTs': 1640000000000,
24+
'displayName': 'Example User',
25+
'accessKeysAllowed': True,
26+
'defaultRoleId': '1234-5678',
27+
'roleIds': ['1234-5678'],
28+
'roles': [{
29+
'id': '1234-5678',
30+
'name': 'System Admin',
31+
'type': 'System Admin',
32+
'onlyAllowCIAccess': False,
33+
'onlyAllowComputeAccess': False,
34+
'onlyAllowReadAccess': False
35+
}],
36+
'activeRole': {
37+
'id': '1234-5678',
38+
'name': 'System Admin',
39+
'type': 'System Admin',
40+
'onlyAllowCIAccess': False,
41+
'onlyAllowComputeAccess': False,
42+
'onlyAllowReadAccess': False
43+
}
44+
}

tests/test_unit.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
""" Unit Tests """
2+
3+
import unittest
4+
5+
from unittest import mock
6+
7+
# pylint: disable=import-error
8+
from prismacloud.api import pc_api
9+
from tests.data import META_INFO, SETTINGS, USER_PROFILE
10+
11+
12+
class TestPrismaCloudAPI(unittest.TestCase):
13+
""" Unit Tests with Mocking """
14+
15+
# Decorator
16+
@mock.patch('prismacloud.api.cspm.EndpointsPrismaCloudAPIMixin.meta_info')
17+
def test_pc_api_configure(self, meta_info):
18+
meta_info.return_value = META_INFO
19+
pc_api.configure(SETTINGS)
20+
self.assertEqual(pc_api.api_compute, 'example.prismacloud.io')
21+
22+
# With
23+
def test_pc_api_current_user(self):
24+
with mock.patch('prismacloud.api.PrismaCloudAPI.execute') as pc_api_execute:
25+
pc_api_execute.return_value = USER_PROFILE
26+
result = pc_api.current_user()
27+
self.assertEqual(result['displayName'], 'Example User')

tests/unit.py

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)