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