embulk-input-marketo 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,176 +0,0 @@
1
- require "prepare_embulk"
2
- require "lead_fixtures"
3
- require "embulk/input/marketo"
4
-
5
- module Embulk
6
- module Input
7
- class MarketoTest < Test::Unit::TestCase
8
- include LeadFixtures
9
-
10
- def setup_soap
11
- @soap = MarketoApi::Soap.new(settings[:endpoint], settings[:wsdl], settings[:user_id], settings[:encryption_key])
12
-
13
- stub(MarketoApi).soap_client(task) { @soap }
14
- end
15
-
16
- def setup_plugin
17
- @page_builder = Object.new
18
- @plugin = Marketo.new(task, nil, nil, @page_builder)
19
- stub(Embulk).logger { ::Logger.new(File::NULL) }
20
- end
21
-
22
- def test_transaction
23
- control = proc {} # dummy
24
- columns = task[:columns].map do |col|
25
- Column.new(nil, col["name"], col["type"].to_sym)
26
- end
27
-
28
- mock(Marketo).resume(task, columns, 1, &control)
29
- Marketo.transaction(config, &control)
30
- end
31
-
32
- class RunTest < self
33
- def setup
34
- setup_soap
35
- setup_plugin
36
- end
37
-
38
- def test_run_through
39
- stub(@plugin).preview? { false }
40
-
41
- any_instance_of(Savon::Client) do |klass|
42
- mock(klass).call(:get_multiple_leads, message: request) do
43
- leads_response
44
- end
45
-
46
- mock(klass).call(:get_multiple_leads, message: request.merge(stream_position: stream_position)) do
47
- next_stream_leads_response
48
- end
49
- end
50
-
51
- mock(@page_builder).add(["manyo"])
52
- mock(@page_builder).add(["everyleaf"])
53
- mock(@page_builder).add(["ten-thousand-leaf"])
54
- mock(@page_builder).finish
55
-
56
- @plugin.run
57
- end
58
-
59
- def test_preview_through
60
- stub(@plugin).preview? { true }
61
-
62
- any_instance_of(Savon::Client) do |klass|
63
- mock(klass).call(:get_multiple_leads, message: request) do
64
- preview_leads_response
65
- end
66
- end
67
-
68
- Marketo::PREVIEW_COUNT.times do |count|
69
- mock(@page_builder).add(["manyo#{count}"])
70
- end
71
- mock(@page_builder).finish
72
-
73
- @plugin.run
74
- end
75
-
76
- private
77
-
78
- def request
79
- {
80
- lead_selector: {oldest_updated_at: Time.parse(last_updated_at).iso8601},
81
- attributes!: {lead_selector: {"xsi:type"=>"ns1:LastUpdateAtSelector"}},
82
- batch_size: 1000
83
- }
84
- end
85
- end
86
-
87
- class GuessTest < self
88
- setup :setup_soap
89
-
90
- def setup_soap
91
- @soap = MarketoApi::Soap.new(settings[:endpoint], settings[:wsdl], settings[:user_id], settings[:encryption_key])
92
-
93
- stub(Marketo).soap_client(config) { @soap }
94
- end
95
-
96
- def test_include_metadata
97
- stub(@soap).lead_metadata { metadata }
98
-
99
- assert_equal(
100
- {"columns" => expected_guessed_columns},
101
- Marketo.guess(config)
102
- )
103
- end
104
- end
105
-
106
- def test_generate_columns
107
- assert_equal(expected_guessed_columns, Marketo.generate_columns(metadata))
108
- end
109
-
110
- private
111
-
112
- def config
113
- DataSource[settings.to_a]
114
- end
115
-
116
- def settings
117
- {
118
- endpoint: "https://marketo.example.com",
119
- wsdl: "https://marketo.example.com/?wsdl",
120
- user_id: "user_id",
121
- encryption_key: "TOPSECRET",
122
- last_updated_at: last_updated_at,
123
- columns: [
124
- {"name" => "Name", "type" => "string"},
125
- ]
126
- }
127
- end
128
-
129
- def last_updated_at
130
- "2015-07-01 00:00:00+00:00"
131
- end
132
-
133
- def task
134
- {
135
- endpoint_url: "https://marketo.example.com",
136
- wsdl_url: "https://marketo.example.com/?wsdl",
137
- user_id: "user_id",
138
- encryption_key: "TOPSECRET",
139
- last_updated_at: last_updated_at,
140
- columns: [
141
- {"name" => "Name", "type" => "string"},
142
- ]
143
- }
144
- end
145
-
146
- def metadata
147
- [
148
- {
149
- name: "FieldName",
150
- description: nil,
151
- display_name: "The Name of Field",
152
- source_object: "Lead",
153
- data_type: "datetime",
154
- size: nil,
155
- is_readonly: false,
156
- is_update_blocked: false,
157
- is_name: nil,
158
- is_primary_key: false,
159
- is_custom: true,
160
- is_dynamic: true,
161
- dynamic_field_ref: "leadAttributeList",
162
- updated_at: DateTime.parse("2000-01-01 22:22:22")
163
- }
164
- ]
165
- end
166
-
167
- def expected_guessed_columns
168
- [
169
- {name: "id", type: "long"},
170
- {name: "email", type: "string"},
171
- {name: "FieldName", type: "string"},
172
- ]
173
- end
174
- end
175
- end
176
- end