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