-
Notifications
You must be signed in to change notification settings - Fork 254
Expand file tree
/
Copy pathtest_extract_yml.py
More file actions
142 lines (128 loc) · 4.44 KB
/
test_extract_yml.py
File metadata and controls
142 lines (128 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from io import StringIO
import pytest
from pydantic.v1 import ValidationError
from cumulusci.tasks.bulkdata.extract_dataset_utils.extract_yml import (
ExtractDeclaration,
ExtractRulesFile,
)
class TestExtractYML:
def test_simple_parse(self):
yaml = """
version: 1
extract:
Opportunity:
fields:
- Name
- ContactId
- AccountId
OBJECTS(CUSTOM):
fields: FIELDS(CUSTOM)
OBJECTS(STANDARD):
fields: FIELDS(CUSTOM)
"""
parse_result = ExtractRulesFile.parse_from_yaml(StringIO(yaml))
assert parse_result.version == 1
extract = parse_result.extract
assert tuple(extract.keys()) == (
"Opportunity",
"OBJECTS(CUSTOM)",
"OBJECTS(STANDARD)",
)
assert extract["OBJECTS(STANDARD)"].fields == ["FIELDS(CUSTOM)"]
assert extract["OBJECTS(STANDARD)"].sf_object == "OBJECTS(STANDARD)"
assert extract["OBJECTS(STANDARD)"].group_type.value == "standard"
assert extract["Opportunity"].group_type is None
def test_default_version(self):
yaml = """
extract:
Opportunity:
fields:
- Name
- ContactId
- AccountId
"""
parse_result = ExtractRulesFile.parse_from_yaml(StringIO(yaml))
assert parse_result.version == 1
extract = parse_result.extract
assert tuple(extract.keys()) == ("Opportunity",)
def test_mini_parser(self):
assert (
ExtractDeclaration.parse_field_complex_type("FIELDS(STANDARD)").value
== "standard"
)
assert ExtractDeclaration.parse_field_complex_type("ffff") is None
def test_weird_syntaxes(self):
yaml = """
extract:
OBJECTS(XYZZY):
fields: FIELDS(CUSTOM)
"""
with pytest.raises(ValidationError, match="xyzzy"):
ExtractRulesFile.parse_from_yaml(StringIO(yaml))
yaml = """
extract:
OBJECTS(XYZZY):
fields:
- FIELDS(CUSTOM)
"""
with pytest.raises(ValidationError, match="xyzzy"):
ExtractRulesFile.parse_from_yaml(StringIO(yaml))
yaml = """
extract:
OBJECTS(POPULATED):
fields: FIELDS(XYZZY)
"""
with pytest.raises(ValidationError, match="XYZZY"):
ExtractRulesFile.parse_from_yaml(StringIO(yaml))
yaml = """
extract:
OBJECTS(POPULATED):
fields:
- FIELDS(XYZZY)
"""
with pytest.raises(ValidationError, match="XYZZY"):
ExtractRulesFile.parse_from_yaml(StringIO(yaml))
yaml = """
extract:
OBJECTS(POPULATED):
fields:
- abcde
- FIELDS(XYZZY)
"""
with pytest.raises(ValidationError, match="XYZZY"):
ExtractRulesFile.parse_from_yaml(StringIO(yaml))
yaml = """
extract:
abcd.efgh:
fields:
- Id
"""
with pytest.raises(ValidationError, match="abcd.efgh"):
ExtractRulesFile.parse_from_yaml(StringIO(yaml))
yaml = """
extract:
OBJECTS(POPULATED):
fields: XYZZY(CUSTOM)
"""
with pytest.raises(ValidationError, match="XYZZY"):
ExtractRulesFile.parse_from_yaml(StringIO(yaml))
yaml = """
extract:
OBJECTS(POPULATED):
fields:
- XYZZY(CUSTOM)
"""
with pytest.raises(ValidationError, match="XYZZY"):
ExtractRulesFile.parse_from_yaml(StringIO(yaml))
def test_parse_real_file(self, cumulusci_test_repo_root):
parse_result = ExtractRulesFile.parse_from_yaml(
cumulusci_test_repo_root / "datasets/test.extract.yml"
)
assert parse_result.version == 1
extract = parse_result.extract
assert tuple(extract.keys()) == (
"Opportunity",
"Contact",
"Account",
"OBJECTS(CUSTOM)",
)