blob: 059ea24c5648bd211b018785541ddafb07b34e1b [file] [log] [blame]
Michal Kobusee36c422018-11-26 15:02:31 +01001import os
2
3import pytest
4
Michal Kobusaa3accf2019-06-05 12:25:09 +02005from sf_notifier.salesforce.client import SalesforceClient, SfNotifierError
Michal Kobusee36c422018-11-26 15:02:31 +01006
7
8ENV_VARS = [
9 'SFDC_AUTH_URL',
10 'SFDC_USERNAME',
11 'SFDC_PASSWORD',
12 'SFDC_ORGANIZATION_ID',
13 'SFDC_ENVIRONMENT_ID',
14 'SFDC_SANDBOX_ENABLED'
15]
16
17
18def unset_env_vars():
19 for v in ENV_VARS:
20 if os.environ.get(v):
21 del os.environ[v]
22
23
24def test_validate_config():
25 OK_CONFIG_1 = [
26 {
27 'AUTH_URL': 'instance_xxx',
28 'USERNAME': 'username_xxx',
29 'PASSWORD': 'password_xxx',
30 'ORGANIZATION_ID': 'org_xxx',
31 'ENVIRONMENT_ID': 'env_xxx',
32 'SANDBOX_ENABLED': True
33 },
34 {
Michal Kobus211ee922019-04-15 17:44:06 +020035 'instance_url': 'instance_xxx',
Michal Kobusee36c422018-11-26 15:02:31 +010036 'username': 'username_xxx',
37 'password': 'password_xxx',
38 'organizationId': 'org_xxx',
39 'environment_id': 'env_xxx',
40 'domain': 'test'
41 }
42 ]
43 OK_CONFIG_2 = [
44 {
45 'AUTH_URL': 'instance_xxx',
46 'USERNAME': 'username_xxx',
47 'PASSWORD': 'password_xxx',
48 'ORGANIZATION_ID': 'org_xxx',
49 'ENVIRONMENT_ID': 'env_xxx'
50 },
51 {
Michal Kobus211ee922019-04-15 17:44:06 +020052 'instance_url': 'instance_xxx',
Michal Kobusee36c422018-11-26 15:02:31 +010053 'username': 'username_xxx',
54 'password': 'password_xxx',
55 'organizationId': 'org_xxx',
56 'environment_id': 'env_xxx'
57 }
58 ]
59 WRONG_CONFIG = {
60 'AUTH_URL': 'xxx',
61 'USERNAME': 'xxx',
62 'PASSWORD': 'xxx',
63 'ORGANIZATION_ID': 'xxx',
64 'SANDBOX_ENABLED': True
65 }
66
67 unset_env_vars()
68
69 assert SalesforceClient._validate_config(OK_CONFIG_1[0]) == OK_CONFIG_1[1]
70 assert SalesforceClient._validate_config(OK_CONFIG_2[0]) == OK_CONFIG_2[1]
71 pytest.raises(SfNotifierError,
72 SalesforceClient._validate_config, WRONG_CONFIG)