Michal Kobus | ee36c42 | 2018-11-26 15:02:31 +0100 | [diff] [blame] | 1 | import os |
| 2 | |
| 3 | import pytest |
| 4 | |
Michal Kobus | fc1e773 | 2019-05-16 18:30:48 +0200 | [diff] [blame] | 5 | from sf_notifier.salesforce.client import SalesforceClient |
| 6 | from sf_notifier.salesforce.exceptions import SfNotifierError |
Michal Kobus | ee36c42 | 2018-11-26 15:02:31 +0100 | [diff] [blame] | 7 | |
| 8 | |
| 9 | ENV_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 | |
| 19 | def unset_env_vars(): |
| 20 | for v in ENV_VARS: |
| 21 | if os.environ.get(v): |
| 22 | del os.environ[v] |
| 23 | |
| 24 | |
| 25 | def 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 Kobus | 211ee92 | 2019-04-15 17:44:06 +0200 | [diff] [blame] | 36 | 'instance_url': 'instance_xxx', |
Michal Kobus | ee36c42 | 2018-11-26 15:02:31 +0100 | [diff] [blame] | 37 | '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 Kobus | 211ee92 | 2019-04-15 17:44:06 +0200 | [diff] [blame] | 53 | 'instance_url': 'instance_xxx', |
Michal Kobus | ee36c42 | 2018-11-26 15:02:31 +0100 | [diff] [blame] | 54 | '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) |