cloudfactory 0.0.13
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.
- data/.gitignore +11 -0
- data/.rspec +1 -0
- data/Gemfile +10 -0
- data/README.md +44 -0
- data/Rakefile +40 -0
- data/bin/cf +8 -0
- data/cf.gemspec +76 -0
- data/example/google_translate_app/Gemfile +12 -0
- data/example/google_translate_app/config.ru +7 -0
- data/example/google_translate_app/google_translate_input.csv +4 -0
- data/example/google_translate_app/google_translator_app.rb +53 -0
- data/example/google_translate_app/views/index.haml +2 -0
- data/example/google_translate_app/views/layout.haml +7 -0
- data/example/google_translate_app/views/run.haml +4 -0
- data/example/google_translate_app/views/style.sass +2 -0
- data/example/human_worker_app/Gemfile +12 -0
- data/example/human_worker_app/config.ru +7 -0
- data/example/human_worker_app/human_worker_app.rb +55 -0
- data/example/human_worker_app/human_worker_input.csv +5 -0
- data/example/human_worker_app/public/app.js +12 -0
- data/example/human_worker_app/temp.csv +3 -0
- data/example/human_worker_app/views/index.haml +15 -0
- data/example/human_worker_app/views/layout.haml +10 -0
- data/example/human_worker_app/views/result.haml +18 -0
- data/example/human_worker_app/views/run.haml +12 -0
- data/example/human_worker_app/views/style.sass +25 -0
- data/example/sample_yaml_files/concept_tagging_robot.yaml +18 -0
- data/example/sample_yaml_files/content_scraping_robot.yaml +19 -0
- data/example/sample_yaml_files/entity_extraction_robot.yaml +18 -0
- data/example/sample_yaml_files/google_translate_robot.yaml +20 -0
- data/example/sample_yaml_files/image_processing_robot.yaml +20 -0
- data/example/sample_yaml_files/keyword_matching_and_text_extraction_robot.yaml +26 -0
- data/example/sample_yaml_files/mailer_robot.yaml +21 -0
- data/example/sample_yaml_files/media_converter_robot.yaml +21 -0
- data/example/sample_yaml_files/media_splitting_robot.yaml +20 -0
- data/example/sample_yaml_files/multiple_skill_badge.yaml +75 -0
- data/example/sample_yaml_files/sentiment_robot.yaml +19 -0
- data/example/sample_yaml_files/skill_badge.yaml +56 -0
- data/example/sample_yaml_files/stat_badge.yaml +40 -0
- data/example/sample_yaml_files/term_extraction_robot.yaml +20 -0
- data/example/sample_yaml_files/tournament_station_and_form_fields.yaml +40 -0
- data/features/form_generation.feature +46 -0
- data/features/form_preview.feature +98 -0
- data/features/line_creation.feature +99 -0
- data/features/line_deletion.feature +50 -0
- data/features/line_generation.feature +57 -0
- data/features/run.feature +141 -0
- data/features/support/cli_steps.rb +16 -0
- data/features/support/env.rb +23 -0
- data/features/target_url.feature +82 -0
- data/fixtures/api_credentials_example.yml +4 -0
- data/fixtures/input_data/media_converter_robot.csv +2 -0
- data/fixtures/input_data/test.csv +2 -0
- data/lib/cf.rb +94 -0
- data/lib/cf/account.rb +32 -0
- data/lib/cf/cli.rb +52 -0
- data/lib/cf/cli/config.rb +87 -0
- data/lib/cf/cli/form.rb +82 -0
- data/lib/cf/cli/line.rb +237 -0
- data/lib/cf/cli/production.rb +62 -0
- data/lib/cf/cli/templates/css_file.css.erb +22 -0
- data/lib/cf/cli/templates/form_preview.html.erb +17 -0
- data/lib/cf/cli/templates/html_file.html.erb +21 -0
- data/lib/cf/cli/templates/js_file.js.erb +18 -0
- data/lib/cf/cli/templates/line.tt +55 -0
- data/lib/cf/cli/templates/sample-line/form.css +27 -0
- data/lib/cf/cli/templates/sample-line/form.html +26 -0
- data/lib/cf/cli/templates/sample-line/form.js +7 -0
- data/lib/cf/cli/templates/sample-line/line.yml.erb +67 -0
- data/lib/cf/cli/templates/sample-line/sample-line.csv +3 -0
- data/lib/cf/client.rb +56 -0
- data/lib/cf/custom_task_form.rb +136 -0
- data/lib/cf/department.rb +24 -0
- data/lib/cf/final_output.rb +20 -0
- data/lib/cf/form_field.rb +62 -0
- data/lib/cf/human_worker.rb +67 -0
- data/lib/cf/input_format.rb +134 -0
- data/lib/cf/line.rb +231 -0
- data/lib/cf/robot_worker.rb +31 -0
- data/lib/cf/run.rb +158 -0
- data/lib/cf/station.rb +340 -0
- data/lib/cf/task_form.rb +147 -0
- data/lib/cf/version.rb +3 -0
- data/lib/generators/cf/form/form_generator.rb +55 -0
- data/lib/generators/cf/form/templates/cf_form.html.erb +11 -0
- data/lib/generators/cf/install/install_generator.rb +22 -0
- data/lib/generators/cf/install/templates/README +13 -0
- data/lib/generators/cf/install/templates/cloud_factory.rb +7 -0
- data/spec/account_spec.rb +11 -0
- data/spec/badge_spec.rb +88 -0
- data/spec/concept_tagging_robot_spec.rb +54 -0
- data/spec/config_spec.rb +20 -0
- data/spec/content_scraping_robot_spec.rb +58 -0
- data/spec/custom_task_form_spec.rb +190 -0
- data/spec/department_spec.rb +14 -0
- data/spec/entity_extraction_robot_spec.rb +56 -0
- data/spec/form_field_spec.rb +126 -0
- data/spec/generators/form_generator_spec.rb +60 -0
- data/spec/generators/install_generator_spec.rb +35 -0
- data/spec/google_translate_robot_spec.rb +64 -0
- data/spec/human_worker_spec.rb +118 -0
- data/spec/image_processing_robot_spec.rb +56 -0
- data/spec/input_format_spec.rb +113 -0
- data/spec/keyword_matching_and_text_extraction_robot_spec.rb +73 -0
- data/spec/line_spec.rb +338 -0
- data/spec/mailer_robot_spec.rb +62 -0
- data/spec/media_converter_robot_spec.rb +72 -0
- data/spec/media_splitting_robot_spec.rb +62 -0
- data/spec/run_spec.rb +298 -0
- data/spec/sentiment_robot_spec.rb +56 -0
- data/spec/spec_helper.rb +39 -0
- data/spec/station_spec.rb +256 -0
- data/spec/task_form_spec.rb +96 -0
- data/spec/term_extraction_robot_spec.rb +58 -0
- data/spec/text_appending_robot_spec.rb +86 -0
- metadata +472 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
module CF
|
|
5
|
+
describe CF::RobotWorker do
|
|
6
|
+
context "create a sentiment robot worker" do
|
|
7
|
+
it "should create content_scraping_robot worker for first station in Block DSL way" do
|
|
8
|
+
# WebMock.allow_net_connect!
|
|
9
|
+
VCR.use_cassette "robot_worker/sentiment_robot/block/create-worker-single-station", :record => :new_episodes do
|
|
10
|
+
line = CF::Line.create("sentiment_robot","Digitization") do |l|
|
|
11
|
+
CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
|
|
12
|
+
CF::Station.create({:line => l, :type => "work"}) do |s|
|
|
13
|
+
CF::RobotWorker.create({:station => s, :settings => {:document => ["{url}"], :sanitize => true}, :type => "sentiment_robot"})
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
run = CF::Run.create(line, "sentiment_robot_run", [{"url"=> "http://www.thehappyguy.com/happiness-self-help-book.html"}])
|
|
17
|
+
output = run.final_output
|
|
18
|
+
output.first.final_output.first.sanitize.should eql("true")
|
|
19
|
+
output.first.final_output.first.sentiment_of_url.should eql("positive")
|
|
20
|
+
output.first.final_output.first.sentiment_relevance_of_url.should eql(24.0408)
|
|
21
|
+
line.stations.first.worker.class.should eql(CF::RobotWorker)
|
|
22
|
+
line.stations.first.worker.reward.should eql(0)
|
|
23
|
+
line.stations.first.worker.number.should eql(1)
|
|
24
|
+
line.stations.first.worker.settings.should eql({:document => ["{url}"], :sanitize => true})
|
|
25
|
+
line.stations.first.worker.type.should eql("SentimentRobot")
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "should create content_scraping_robot worker for first station in plain ruby way" do
|
|
30
|
+
# WebMock.allow_net_connect!
|
|
31
|
+
VCR.use_cassette "robot_worker/sentiment_robot/plain_ruby/create-worker-single-station", :record => :new_episodes do
|
|
32
|
+
line = CF::Line.new("sentiment_robot_1","Digitization")
|
|
33
|
+
input_format = CF::InputFormat.new({:name => "url", :required => true, :valid_type => "url"})
|
|
34
|
+
line.input_formats input_format
|
|
35
|
+
|
|
36
|
+
station = CF::Station.new({:type => "work"})
|
|
37
|
+
line.stations station
|
|
38
|
+
|
|
39
|
+
worker = CF::RobotWorker.new({:settings => {:document => ["{url}"], :sanitize => true}, :type => "sentiment_robot"})
|
|
40
|
+
line.stations.first.worker = worker
|
|
41
|
+
|
|
42
|
+
run = CF::Run.create(line, "sentiment_robot_run_1", [{"url"=> "http://www.thehappyguy.com/happiness-self-help-book.html"}])
|
|
43
|
+
output = run.final_output
|
|
44
|
+
output.first.final_output.first.sanitize.should eql("true")
|
|
45
|
+
output.first.final_output.first.sentiment_of_url.should eql("positive")
|
|
46
|
+
output.first.final_output.first.sentiment_relevance_of_url.should eql(24.0408)
|
|
47
|
+
line.stations.first.worker.class.should eql(CF::RobotWorker)
|
|
48
|
+
line.stations.first.worker.reward.should eql(0)
|
|
49
|
+
line.stations.first.worker.number.should eql(1)
|
|
50
|
+
line.stations.first.worker.settings.should eql({:document => ["{url}"], :sanitize => true})
|
|
51
|
+
line.stations.first.worker.type.should eql("SentimentRobot")
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'cf'
|
|
2
|
+
require 'vcr'
|
|
3
|
+
require 'webmock'
|
|
4
|
+
|
|
5
|
+
RSpec.configure do |config|
|
|
6
|
+
config.before(:each) do
|
|
7
|
+
# Configuring the defaults
|
|
8
|
+
# Set ENV['TEST'] is true for testing against the api
|
|
9
|
+
# TEST=true bundle exec rspec spec/.....
|
|
10
|
+
if ENV['TEST']
|
|
11
|
+
require 'ruby-debug'
|
|
12
|
+
::Debugger.start
|
|
13
|
+
::Debugger.settings[:autoeval] = true if ::Debugger.respond_to?(:settings)
|
|
14
|
+
|
|
15
|
+
API_CONFIG = YAML.load_file(File.expand_path("../../fixtures/api_credentials.yml", __FILE__))
|
|
16
|
+
CF.configure do |config|
|
|
17
|
+
config.account_name = API_CONFIG['account_name']
|
|
18
|
+
config.api_version = API_CONFIG['api_version']
|
|
19
|
+
config.api_url = API_CONFIG['api_url']
|
|
20
|
+
config.api_key = API_CONFIG['api_key']
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
config.filter_run :focus => true
|
|
25
|
+
config.filter_run_excluding :broken => true
|
|
26
|
+
config.run_all_when_everything_filtered = true
|
|
27
|
+
config.extend VCR::RSpec::Macros
|
|
28
|
+
# Tenant.current = Tenant.create(:host => SANDBOX)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# WebMock.disable_net_connect!(:allow => "sprout.lvh.me")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
VCR.config do |c|
|
|
35
|
+
c.cassette_library_dir = 'fixtures/cassette_library'
|
|
36
|
+
c.stub_with :webmock
|
|
37
|
+
c.ignore_localhost = true
|
|
38
|
+
c.default_cassette_options = { :record => :none }
|
|
39
|
+
end
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe CF::Station do
|
|
4
|
+
context "create a station" do
|
|
5
|
+
it "the plain ruby way" do
|
|
6
|
+
# WebMock.allow_net_connect!
|
|
7
|
+
VCR.use_cassette "stations/plain-ruby/create", :record => :new_episodes do
|
|
8
|
+
line = CF::Line.new("Digitize--ard", "Digitization")
|
|
9
|
+
station = CF::Station.new({:type => "work"})
|
|
10
|
+
line.stations station
|
|
11
|
+
line.stations.first.type.should eql("WorkStation")
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "using the block variable" do
|
|
16
|
+
# WebMock.allow_net_connect!
|
|
17
|
+
VCR.use_cassette "stations/block/create-with-block-var", :record => :new_episodes do
|
|
18
|
+
line = CF::Line.create("igitizeard", "Digitization") do
|
|
19
|
+
CF::Station.create({:line => self, :type => "work"}) do |s|
|
|
20
|
+
CF::HumanWorker.new({:station => s, :number => 2, :reward => 20})
|
|
21
|
+
CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
|
22
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
|
|
23
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
|
|
24
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
line.stations.first.type.should eq("WorkStation")
|
|
29
|
+
line.stations.first.worker.number.should eql(2)
|
|
30
|
+
line.stations.first.worker.reward.should eql(20)
|
|
31
|
+
line.stations.first.form.title.should eq("Enter text from a business card image")
|
|
32
|
+
line.stations.first.form.instruction.should eq("Describe")
|
|
33
|
+
line.stations.first.form.form_fields[0].label.should eq("First Name")
|
|
34
|
+
line.stations.first.form.form_fields[1].label.should eq("Middle Name")
|
|
35
|
+
line.stations.first.form.form_fields[2].label.should eq("Last Name")
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
it "using without the block variable also creating instruction without block variable" do
|
|
40
|
+
# WebMock.allow_net_connect!
|
|
41
|
+
VCR.use_cassette "stations/block/create-without-block-var", :record => :new_episodes do
|
|
42
|
+
line = CF::Line.create("Digitizrd", "Digitization") do
|
|
43
|
+
CF::Station.create({:line => self, :type => "work"}) do
|
|
44
|
+
CF::HumanWorker.new({:station => self, :number => 2, :reward => 20})
|
|
45
|
+
CF::TaskForm.create({:station => self, :title => "Enter text from a business card image", :instruction => "Describe"}) do
|
|
46
|
+
CF::FormField.new({:form => self, :label => "First Name", :field_type => "SA", :required => "true"})
|
|
47
|
+
CF::FormField.new({:form => self, :label => "Middle Name", :field_type => "SA"})
|
|
48
|
+
CF::FormField.new({:form => self, :label => "Last Name", :field_type => "SA", :required => "true"})
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
line.stations.first.type.should eq("WorkStation")
|
|
53
|
+
line.stations.first.worker.number.should == 2
|
|
54
|
+
line.stations.first.worker.reward.should == 20
|
|
55
|
+
line.stations.first.form.title.should eq("Enter text from a business card image")
|
|
56
|
+
line.stations.first.form.instruction.should eq("Describe")
|
|
57
|
+
line.stations.first.form.form_fields[0].label.should eq("First Name")
|
|
58
|
+
line.stations.first.form.form_fields[1].label.should eq("Middle Name")
|
|
59
|
+
line.stations.first.form.form_fields[2].label.should eq("Last Name")
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "should create a station of Tournament station" do
|
|
64
|
+
# WebMock.allow_net_connect!
|
|
65
|
+
VCR.use_cassette "stations/block/tournament-station", :record => :new_episodes do
|
|
66
|
+
line = CF::Line.create("Digitized-9", "Digitization") do
|
|
67
|
+
CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
|
|
68
|
+
CF::Station.create({:line => self, :type => "tournament", :jury_worker=> {:max_judges => 10}, :auto_judge => {:enabled => true}}) do |s|
|
|
69
|
+
CF::HumanWorker.new({:station => s, :number => 3, :reward => 20})
|
|
70
|
+
CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
|
71
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
|
|
72
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
|
|
73
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
line.stations.first.type.should eq("TournamentStation")
|
|
78
|
+
line.stations.first.jury_worker.should eql({:max_judges => 10})
|
|
79
|
+
line.stations.first.auto_judge.should eql({:enabled => true})
|
|
80
|
+
line.stations.first.worker.number.should eql(3)
|
|
81
|
+
line.stations.first.worker.reward.should eql(20)
|
|
82
|
+
line.stations.first.form.title.should eq("Enter text from a business card image")
|
|
83
|
+
line.stations.first.form.instruction.should eq("Describe")
|
|
84
|
+
line.stations.first.form.form_fields[0].label.should eq("First Name")
|
|
85
|
+
line.stations.first.form.form_fields[1].label.should eq("Middle Name")
|
|
86
|
+
line.stations.first.form.form_fields[2].label.should eq("Last Name")
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "should create a station of Improve station as first station of line" do
|
|
91
|
+
# WebMock.allow_net_connect!
|
|
92
|
+
VCR.use_cassette "stations/block/improve-as-first-station", :record => :new_episodes do
|
|
93
|
+
line = CF::Line.new("Digitd", "Digitization")
|
|
94
|
+
station = CF::Station.new({:type => "improve"})
|
|
95
|
+
expect { line.stations station }.to raise_error(CF::ImproveStationNotAllowed)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
context "get station" do
|
|
101
|
+
it "should get information about a single station" do
|
|
102
|
+
# WebMock.allow_net_connect!
|
|
103
|
+
VCR.use_cassette "stations/plain-ruby/get-station", :record => :new_episodes do
|
|
104
|
+
line = CF::Line.new("Digitizerd1","Digitization")
|
|
105
|
+
line.title.should eq("Digitizerd1")
|
|
106
|
+
station = CF::Station.new(:type => "Work")
|
|
107
|
+
line.stations station
|
|
108
|
+
station.type.should eq("Work")
|
|
109
|
+
line.stations.first.get.type.should eq("WorkStation")
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "should get all existing stations of a line" do
|
|
114
|
+
# WebMock.allow_net_connect!
|
|
115
|
+
VCR.use_cassette "stations/plain-ruby/get-all-stations", :record => :new_episodes do
|
|
116
|
+
line = CF::Line.new("Digitizrd11","Digitization")
|
|
117
|
+
line.title.should eq("Digitizrd11")
|
|
118
|
+
station = CF::Station.new(:type => "Work")
|
|
119
|
+
line.stations station
|
|
120
|
+
stations = CF::Station.all(line)
|
|
121
|
+
stations[0].type.should eq("WorkStation")
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
context "create multiple station" do
|
|
127
|
+
xit "should create two stations with improve station" do
|
|
128
|
+
WebMock.allow_net_connect!
|
|
129
|
+
# VCR.use_cassette "stations/block/multiple-station", :record => :new_episodes do
|
|
130
|
+
line = CF::Line.create("Company Info -1","Digitization") do |l|
|
|
131
|
+
CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
|
|
132
|
+
CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
|
|
133
|
+
CF::Station.create({:line => l, :type => "work"}) do |s|
|
|
134
|
+
CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
|
|
135
|
+
CF::TaskForm.create({:station => s, :title => "Enter the name of CEO", :instruction => "Describe"}) do |i|
|
|
136
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
|
|
137
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
|
|
138
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
station = CF::Station.new({:type => "Improve"})
|
|
144
|
+
line.stations station
|
|
145
|
+
|
|
146
|
+
worker = CF::HumanWorker.new({:number => 1, :reward => 10})
|
|
147
|
+
line.stations.last.worker = worker
|
|
148
|
+
|
|
149
|
+
form = CF::TaskForm.new({:title => "Enter the address of the given Person", :instruction => "Description"})
|
|
150
|
+
line.stations.last.form = form
|
|
151
|
+
|
|
152
|
+
form_fields_1 = CF::FormField.new({:label => "Street", :field_type => "SA", :required => "true"})
|
|
153
|
+
line.stations.last.form.form_fields form_fields_1
|
|
154
|
+
form_fields_2 = CF::FormField.new({:label => "City", :field_type => "SA", :required => "true"})
|
|
155
|
+
line.stations.last.form.form_fields form_fields_2
|
|
156
|
+
form_fields_3 = CF::FormField.new({:label => "Country", :field_type => "SA", :required => "true"})
|
|
157
|
+
line.stations.last.form.form_fields form_fields_3
|
|
158
|
+
|
|
159
|
+
run = CF::Run.create(line,"Creation of Multiple Station", File.expand_path("../../fixtures/input_data/test.csv", __FILE__))
|
|
160
|
+
# debugger
|
|
161
|
+
result_of_station_1 = run.output(:station => 1)
|
|
162
|
+
result_of_station_2 = run.output(:station => 2)
|
|
163
|
+
@final_output = run.final_output
|
|
164
|
+
@final_output.first.meta_data['company'].should eql("Apple")
|
|
165
|
+
@final_output.first.final_outputs.last['street'].should eql("Kupondole")
|
|
166
|
+
@final_output.first.final_outputs.last['city'].should eql("Kathmandu")
|
|
167
|
+
@final_output.first.final_outputs.last['country'].should eql("Nepal")
|
|
168
|
+
# end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
context "create multiple station" do
|
|
173
|
+
it "should create two stations using different input format" do
|
|
174
|
+
# WebMock.allow_net_connect!
|
|
175
|
+
VCR.use_cassette "stations/block/multiple-station-adding-input-format", :record => :new_episodes do
|
|
176
|
+
line = CF::Line.create("Company-info-214","Digitization") do |l|
|
|
177
|
+
CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
|
|
178
|
+
CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
|
|
179
|
+
CF::Station.create({:line => l, :type => "work", :input_formats=> {:station_0 => [{:name => "Company"},{:name => "Website", :except => true}]}}) do |s|
|
|
180
|
+
CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
|
|
181
|
+
CF::TaskForm.create({:station => s, :title => "Enter the name of CEO", :instruction => "Describe"}) do |i|
|
|
182
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
|
|
183
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
|
|
184
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
station = CF::Station.new(
|
|
190
|
+
{:type => "work", :input_formats => {:station_0 => [{:name => "Website"}], :station_1 => [{:name => "Last Name", :except => true}]}})
|
|
191
|
+
line.stations station
|
|
192
|
+
|
|
193
|
+
worker = CF::HumanWorker.new({:number => 1, :reward => 10})
|
|
194
|
+
line.stations.last.worker = worker
|
|
195
|
+
|
|
196
|
+
form = CF::TaskForm.new({:title => "Enter the address of the given Person", :instruction => "Description"})
|
|
197
|
+
line.stations.last.form = form
|
|
198
|
+
|
|
199
|
+
form_fields_1 = CF::FormField.new({:label => "Street", :field_type => "SA", :required => "true"})
|
|
200
|
+
line.stations.last.form.form_fields form_fields_1
|
|
201
|
+
form_fields_2 = CF::FormField.new({:label => "City", :field_type => "SA", :required => "true"})
|
|
202
|
+
line.stations.last.form.form_fields form_fields_2
|
|
203
|
+
form_fields_3 = CF::FormField.new({:label => "Country", :field_type => "SA", :required => "true"})
|
|
204
|
+
line.stations.last.form.form_fields form_fields_3
|
|
205
|
+
station_1 = line.stations.first.get
|
|
206
|
+
station_1.input_formats.count.should eql(1)
|
|
207
|
+
station_1.input_formats.first.name.should eql("Company")
|
|
208
|
+
station_1.input_formats.first.required.should eql(true)
|
|
209
|
+
station_1.input_formats.first.valid_type.should eql("general")
|
|
210
|
+
station_2 = line.stations.last.get
|
|
211
|
+
station_2.input_formats.count.should eql(3)
|
|
212
|
+
station_2.input_formats.map(&:name).should include("Website")
|
|
213
|
+
station_2.input_formats.map(&:name).should include("First Name")
|
|
214
|
+
station_2.input_formats.map(&:name).should include("Middle Name")
|
|
215
|
+
station_2.input_formats.map(&:required).should include(true)
|
|
216
|
+
station_2.input_formats.map(&:required).should include(false) #how to make it true
|
|
217
|
+
station_2.input_formats.map(&:required).should include(false)
|
|
218
|
+
station_2.input_formats.map(&:valid_type).should include("url")
|
|
219
|
+
station_2.input_formats.map(&:valid_type).should include("general")
|
|
220
|
+
station_2.input_formats.map(&:valid_type).should include("general")
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
context "create a station without passing station type" do
|
|
226
|
+
it "in plain ruby way and it should display an error message" do
|
|
227
|
+
# WebMock.allow_net_connect!
|
|
228
|
+
VCR.use_cassette "stations/plain-ruby/create-without-type", :record => :new_episodes do
|
|
229
|
+
line = CF::Line.new("Digitize--ard", "Digitization")
|
|
230
|
+
station = CF::Station.new()
|
|
231
|
+
line.stations station
|
|
232
|
+
line.stations.first.errors.should eql("The Station type is invalid.")
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
it "in block DSL way and it should display an error message" do
|
|
237
|
+
# WebMock.allow_net_connect!
|
|
238
|
+
VCR.use_cassette "stations/block/create-without-type", :record => :new_episodes do
|
|
239
|
+
line = CF::Line.create("Digitize--ard1", "Digitization") do |l|
|
|
240
|
+
CF::Station.new({:line => l})
|
|
241
|
+
end
|
|
242
|
+
line.stations.first.errors.should eql("The Station type is invalid.")
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
it "in block DSL way without creating input_format it should display an error message" do
|
|
247
|
+
# WebMock.allow_net_connect!
|
|
248
|
+
VCR.use_cassette "stations/block/create-without-input_type_error", :record => :new_episodes do
|
|
249
|
+
line = CF::Line.create("Digitize--ard2", "Digitization") do |l|
|
|
250
|
+
CF::Station.new({:line => l, :type => "work"})
|
|
251
|
+
end
|
|
252
|
+
line.stations.first.errors.should eql("Input formats not assigned for the line #{line.title.downcase}")
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe CF::TaskForm do
|
|
4
|
+
context "create a task_form" do
|
|
5
|
+
it "the plain ruby way" do
|
|
6
|
+
# WebMock.allow_net_connect!
|
|
7
|
+
VCR.use_cassette "task_form/block/create", :record => :new_episodes do
|
|
8
|
+
line = CF::Line.create("Digiti-ard-2", "Digitization") do
|
|
9
|
+
CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
|
|
10
|
+
CF::Station.create({:line => self, :type => "work"}) do |station|
|
|
11
|
+
CF::HumanWorker.new({:station => station, :number => 2, :reward => 20})
|
|
12
|
+
CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
|
13
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
|
|
14
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
|
|
15
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
form = line.stations[0].form
|
|
20
|
+
form.title.should eq("Enter text from a business card image")
|
|
21
|
+
form.instruction.should eq("Describe")
|
|
22
|
+
form.form_fields.first.label.should eq("First Name")
|
|
23
|
+
form.form_fields.first.field_type.should eq("SA")
|
|
24
|
+
form.form_fields.first.required.should eq(true)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
xit "with invalid data" do
|
|
29
|
+
WebMock.allow_net_connect!
|
|
30
|
+
# VCR.use_cassette "task_form/block/create", :record => :new_episodes do
|
|
31
|
+
line = CF::Line.create("Digiti-ard-2", "Digitization") do
|
|
32
|
+
CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
|
|
33
|
+
CF::Station.create({:line => self, :type => "work"}) do |station|
|
|
34
|
+
CF::HumanWorker.new({:station => station, :number => 2, :reward => 20})
|
|
35
|
+
CF::TaskForm.new({:station => station})
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
# debugger
|
|
39
|
+
form = line.stations[0].form
|
|
40
|
+
form.instruction.should eq("Describe")
|
|
41
|
+
form.form_fields.first.label.should eq("First Name")
|
|
42
|
+
form.form_fields.first.field_type.should eq("SA")
|
|
43
|
+
form.form_fields.first.required.should eq(true)
|
|
44
|
+
# end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
context "get instruction info" do
|
|
49
|
+
it "should get all the instruction information of a station" do
|
|
50
|
+
# WebMock.allow_net_connect!
|
|
51
|
+
VCR.use_cassette "task_form/block/get-instruction", :record => :new_episodes do
|
|
52
|
+
line = CF::Line.create("Digitizerdd", "Digitization") do
|
|
53
|
+
CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
|
|
54
|
+
CF::Station.create({:line => self, :type => "work"}) do |station|
|
|
55
|
+
CF::HumanWorker.new({:station => station, :number => 2, :reward => 20})
|
|
56
|
+
CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
|
57
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
|
|
58
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
|
|
59
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
@got_instruction = line.stations.first.get_form
|
|
64
|
+
@got_instruction.title.should eq("Enter text from a business card image")
|
|
65
|
+
@got_instruction.instruction.should eq("Describe")
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context "Delete instruction" do
|
|
71
|
+
it "should delete instruction of a station" do
|
|
72
|
+
# WebMock.allow_net_connect!
|
|
73
|
+
VCR.use_cassette "task_form/block/delete-instruction", :record => :new_episodes do
|
|
74
|
+
line = CF::Line.create("Digitize-d111", "Digitization") do
|
|
75
|
+
CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
|
|
76
|
+
CF::Station.create({:line => self, :type => "work"}) do |station|
|
|
77
|
+
CF::HumanWorker.new({:station => station, :number => 2, :reward => 20})
|
|
78
|
+
CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
|
|
79
|
+
CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
|
|
80
|
+
CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "SA"})
|
|
81
|
+
CF::FormField.new({:form => i, :label => "Last Name", :field_type => "SA", :required => "true"})
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
@got_instruction = line.stations.first.get_form
|
|
86
|
+
@got_instruction.title.should eq("Enter text from a business card image")
|
|
87
|
+
@got_instruction.instruction.should eq("Describe")
|
|
88
|
+
|
|
89
|
+
station = line.stations[0]
|
|
90
|
+
deleted_response = CF::TaskForm.delete_instruction(station)
|
|
91
|
+
|
|
92
|
+
deleted_response.code.should eq(200)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|