cloudfactory 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,48 +3,31 @@ Feature: Deleting a line on CF
3
3
  As a CLI user
4
4
  I want to delete a line via cli for the line
5
5
 
6
- @announce, @too_slow_process
7
- Scenario: Creating then deleting a Line
6
+ Background:
8
7
  Given a file named ".cf_credentials" with:
9
8
  """
10
9
  ---
11
10
  :target_url: http://lvh.me:3000/api/
12
11
  :api_version: v1
12
+ :api_key: 89ceebf739adbf59d34911f4f28b2fa0e1564fb6
13
+
13
14
  """
14
- And a file named "brandiator/line.yml" with:
15
- """
16
- api_key: 89ceebf739adbf59d34911f4f28b2fa0e1564fb6
17
- title: brandiator-deletion
18
- description: Describe the line what its purpose is and what it does. You got the idea, right?
19
- department: Survey
20
- input_formats:
21
- - name: company
22
- required: true
23
- valid_type: general
24
- stations:
25
- - station:
26
- station_index: 1
27
- station_type: work
28
- worker:
29
- worker_type: human
30
- num_workers: 2
31
- reward: 5
32
- task_form:
33
- form_title: Enter text from a business card image for TASKFORM
34
- instruction: Read the business card image and the fill the fields for TASKFORM
35
- form_fields:
36
- - label: CEO Name
37
- field_type: short_answer
38
- required: true
39
- """
40
- And I cd to "brandiator"
41
- When I run `cf line create`
42
- Then the output should match:
43
- """
44
- Congrats! brandiator-deletion was successfully created.
45
- """
46
- When I run `cf line delete`
47
- Then the output should match:
48
- """
49
- The line brandiator-deletion is deleted successfully!
50
- """
15
+
16
+ @announce, @too_slow_process
17
+ Scenario: Deleting an existing a line being inside the line directory
18
+ Given a line exists with title "brandiator"
19
+ And I cd to "brandiator"
20
+ When I run `cf line delete`
21
+ Then the output should match:
22
+ """
23
+ The line brandiator deleted successfully!
24
+ """
25
+
26
+ @announce, @too_slow_process
27
+ Scenario: Deleting an existing from anywhere
28
+ Given a line exists with title "easytizer"
29
+ When I run `cf line delete -l=easytizer`
30
+ Then the output should match:
31
+ """
32
+ The line easytizer deleted successfully!
33
+ """
data/lib/cf/cli/config.rb CHANGED
@@ -45,8 +45,9 @@ module Cf # :nodoc: all
45
45
  yml[:api_key].presence || yml['api_key'].presence
46
46
  end
47
47
 
48
- def set_api_key(yaml_source)
48
+ def set_api_key(yaml_source = "")
49
49
  api_key = nil
50
+ # debugger
50
51
  api_key = get_api_key(yaml_source) if File.exists?(yaml_source)
51
52
  if api_key.blank?
52
53
 
@@ -54,19 +55,22 @@ module Cf # :nodoc: all
54
55
  if File.exist?(config_file)
55
56
  api_key = get_api_key(config_file)
56
57
  if api_key.blank?
57
- raise "Error: No valid api key found. Do login first with: cf login"
58
+ say("Error: No valid api key found. Do login first with: cf login", :red) and exit(1)
58
59
  else
59
- CF.api_key = api_key if CF.api_key.blank?
60
- raise "Error: Invalid api key => #{CF.api_key} for target #{CF.api_url}" unless CF::Account.valid?
61
- return true
60
+ CF.api_key = api_key# if CF.api_key.blank?
61
+ if CF::Account.valid?
62
+ return
63
+ else
64
+ say("Error: Invalid api key => #{CF.api_key} for target #{CF.api_url}", :red) and exit(1)
65
+ end
62
66
  end
63
67
  end
64
- raise "Error: No valid api key found. Do login first with: cf login"
68
+ say("Error: No valid api key found. Do login first with: cf login", :red) and exit(1)
65
69
  else
66
70
  CF.api_key = api_key if CF.api_key.blank?
67
71
  # Do check whether the api_key is valid by calling the CF::Account#valid?
68
72
  # Cf::CliError.new("Error: Invalid api key => #{CF.api_key}") unless CF::Account.valid?
69
- raise "Error: Invalid api key => #{CF.api_key} for target #{CF.api_url}" unless CF::Account.valid?
73
+ say("Error: Invalid api key => #{CF.api_key} for target #{CF.api_url}", :red) and exit(1) unless CF::Account.valid?
70
74
 
71
75
  # Check the file ~/.cf_credentials. If it exists, check for the api_key line. If not set, then append it.
72
76
  # This is needed for certain commands like cf line list, cf production list <line-title>
@@ -76,9 +80,9 @@ module Cf # :nodoc: all
76
80
  # open(config_file, 'a') {|f| f.puts ":api_key: #{api_key}"}
77
81
  # end
78
82
  # end
79
-
80
- return true
81
83
  end
84
+ # debugger
85
+ # puts ""
82
86
  end
83
87
 
84
88
  # Ripped from rubygems
data/lib/cf/cli/line.rb CHANGED
@@ -48,24 +48,33 @@ module Cf # :nodoc: all
48
48
  say "Title for the line is required.", :red
49
49
  end
50
50
  end
51
-
52
- desc "line delete", "delete the line at http://cloudfactory.com"
51
+
52
+ desc "line delete", "delete the current line at http://cloudfactory.com"
53
+ method_option :line, :type => :string, :aliases => "-l", :desc => "specify the line-title to delete"
53
54
  def delete
54
- line_source = Dir.pwd
55
- yaml_source = "#{line_source}/line.yml"
56
-
57
- unless File.exist?(yaml_source)
58
- say("The line.yml file does not exist in this directory", :red) and return
55
+ if options['line'].blank?
56
+ line_source = Dir.pwd
57
+ yaml_source = "#{line_source}/line.yml"
58
+ say("The line.yml file does not exist in this directory", :red) and exit(1) unless File.exist?(yaml_source)
59
+ set_target_uri(false)
60
+ set_api_key(yaml_source)
61
+ CF.account_name = CF::Account.info.name
62
+ line_dump = YAML::load(File.open(yaml_source))
63
+ line_title = line_dump['title'].parameterize
64
+ else
65
+ set_target_uri(false)
66
+ set_api_key
67
+ CF.account_name = CF::Account.info.name
68
+ line_title = options['line'].parameterize
69
+ end
70
+
71
+ line = CF::Line.find(line_title)
72
+ if line.errors.blank?
73
+ CF::Line.destroy(line_title)
74
+ say("The line #{line_title} deleted successfully!", :yellow)
75
+ else
76
+ say("The line #{line_title} doesn't exist!", :yellow)
59
77
  end
60
-
61
- set_target_uri(false)
62
- set_api_key(yaml_source)
63
- CF.account_name = CF::Account.info.name
64
- line_dump = YAML::load(File.open(yaml_source))
65
- line_title = line_dump['title'].parameterize
66
-
67
- CF::Line.destroy(line_title)
68
- say("The line #{line_title} was deleted successfully!", :yellow)
69
78
  end
70
79
 
71
80
  no_tasks {
@@ -96,5 +96,34 @@ module Cf # :nodoc: all
96
96
  end
97
97
  end
98
98
  end
99
+
100
+ desc "production list", "list the production runs"
101
+ method_option :line, :type => :string, :aliases => "-l", :desc => "the title of the line"
102
+ def list
103
+ set_target_uri(false)
104
+ set_api_key
105
+ CF.account_name = CF::Account.info.name
106
+ if options['line'].present?
107
+ runs = CF::Run.all(options['line'].parameterize)
108
+ else
109
+ runs = CF::Run.all
110
+ end
111
+
112
+ unless runs.kind_of?(Array)
113
+ if runs.error.present?
114
+ say("No Runs\n#{runs.error.message}", :red) and exit(1)
115
+ end
116
+ end
117
+
118
+ runs.sort! {|a, b| a[:name] <=> b[:name] }
119
+ runs_table = table do |t|
120
+ t.headings = ["Run Title", 'URL']
121
+ runs.each do |run|
122
+ t << [run.title, "http://#{CF.account_name}.cloudfactory.com/runs/#{CF.account_name}/#{run.title}"]
123
+ end
124
+ end
125
+ say("\n")
126
+ say(runs_table)
127
+ end
99
128
  end
100
129
  end
data/lib/cf/client.rb CHANGED
@@ -13,7 +13,11 @@ module CF # :nodoc: all
13
13
  end
14
14
 
15
15
  def post(*args)
16
- handle_response RestClient.post("#{CF.api_url}#{CF.api_version}#{args.first}", args.last.merge!(default_params), :accept => 'json'){ |response, request, result| response }
16
+ if args.length > 1
17
+ handle_response RestClient.post("#{CF.api_url}#{CF.api_version}#{args.first}", args.last.merge!(default_params), :accept => 'json'){ |response, request, result| response }
18
+ else
19
+ handle_response RestClient.post("#{CF.api_url}#{CF.api_version}#{args.first}", default_params, :accept => 'json'){ |response, request, result| response }
20
+ end
17
21
  end
18
22
 
19
23
  def put(*args)
@@ -62,5 +62,9 @@ module CF
62
62
  def self.create(form)
63
63
  instruction = CustomTaskForm.new(form)
64
64
  end
65
+
66
+ def to_s
67
+ "{:title => #{self.title}, :instruction => #{self.instruction}, :raw_html => #{self.raw_html}, :raw_css => #{self.raw_css}, :raw_javascript => #{self.raw_javascript}, :errors => #{self.errors}}"
68
+ end
65
69
  end
66
70
  end
data/lib/cf/form_field.rb CHANGED
@@ -63,5 +63,9 @@ module CF
63
63
  @form_field_params = options
64
64
  end
65
65
  end
66
+
67
+ def to_s
68
+ "{:id => => #{self.id}, :label => #{self.label}, :field_type => #{self.field_type}, :required => #{self.required}, :errors => #{self.errors}}"
69
+ end
66
70
  end
67
71
  end
@@ -155,5 +155,9 @@ module CF
155
155
  resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@station.line['title'].downcase}/stations/#{@station.index}/workers/#{self.id}/badge.json",request)
156
156
  self.skill_badges << resp.parsed_response['skill_badges']
157
157
  end
158
+
159
+ def to_s
160
+ "{:id => => #{self.id}, :number => #{self.number}, :reward => #{self.reward}, :stat_badge => #{self.stat_badge}, :skill_badges => #{self.skill_badges}, :errors => #{self.errors}}"
161
+ end
158
162
  end
159
163
  end
@@ -39,6 +39,9 @@ module CF
39
39
  if !@station.nil? or !@line.nil?
40
40
  line_title = @station.nil? ? @line.title : @station.line_title
41
41
  resp = self.class.post("/lines/#{CF.account_name}/#{@line.title.downcase}/input_formats.json", :input_format => {:name => @name, :required => @required, :valid_type => @valid_type})
42
+ resp.to_hash.each_pair do |k,v|
43
+ self.send("#{k}=",v) if self.respond_to?(k)
44
+ end
42
45
  if resp.code != 200
43
46
  self.errors = resp.error.message
44
47
  end
@@ -78,5 +81,9 @@ module CF
78
81
  def self.all(line)
79
82
  get("/lines/#{CF.account_name}/#{line.title.downcase}/input_formats.json")
80
83
  end
84
+
85
+ def to_s
86
+ "{:id => #{self.id}, :name => #{self.name}, :required => #{self.required}, :valid_type => #{self.valid_type}, :errors => #{self.errors}}"
87
+ end
81
88
  end
82
89
  end
@@ -88,5 +88,9 @@ module CF
88
88
  def self.create(options)
89
89
  RobotWorker.new(options)
90
90
  end
91
+
92
+ def to_s
93
+ "{:number => #{self.number}, :reward => #{self.reward}, :type => #{self.type}, :settings => #{self.settings}, :errors => #{self.errors}}"
94
+ end
91
95
  end
92
96
  end
data/lib/cf/run.rb CHANGED
@@ -133,5 +133,35 @@ module CF
133
133
  end
134
134
  return resp
135
135
  end
136
+
137
+ def self.progress(run_title)
138
+ get("/runs/#{CF.account_name}/#{run_title}/progress.json")
139
+ end
140
+
141
+ def progress
142
+ self.class.get("/runs/#{CF.account_name}/#{self.title}/progress.json")
143
+ end
144
+
145
+ def self.progress_details(run_title)
146
+ resp = get("/runs/#{CF.account_name}/#{run_title}/details.json")
147
+ return resp['progress_details']
148
+ end
149
+
150
+ def progress_details
151
+ resp = self.class.get("/runs/#{CF.account_name}/#{self.title}/details.json")
152
+ return resp['progress_details']
153
+ end
154
+
155
+ def self.all(line_title=nil)
156
+ if line_title.blank?
157
+ get("/runs/#{CF.account_name}.json")
158
+ else
159
+ get("/lines/#{CF.account_name}/#{line_title}/list_runs.json")
160
+ end
161
+ end
162
+
163
+ def self.resume(run_title)
164
+ post("/runs/#{CF.account_name}/#{run_title}/resume.json")
165
+ end
136
166
  end
137
167
  end
data/lib/cf/station.rb CHANGED
@@ -274,5 +274,13 @@ module CF
274
274
  def delete
275
275
  self.class.delete("/lines/#{CF.account_name}/#{self.line_title.downcase}/stations/#{self.index}.json")
276
276
  end
277
+
278
+ def to_s
279
+ if self.type == "TournamentStation"
280
+ "{:type => #{self.type}, :index => #{self.index}, :line_title => #{self.line_title}, :station_input_formats => #{self.station_input_formats}, :jury_worker => #{self.jury_worker}, auto_judge => #{self.auto_judge}, :errors => #{self.errors}}"
281
+ else
282
+ "{:type => #{self.type}, :index => #{self.index}, :line_title => #{self.line_title}, :station_input_formats => #{self.station_input_formats}, :errors => #{self.errors}}"
283
+ end
284
+ end
277
285
  end
278
286
  end
data/lib/cf/task_form.rb CHANGED
@@ -101,8 +101,13 @@ module CF
101
101
  @form_fields
102
102
  end
103
103
  end
104
+
104
105
  def form_fields=(form_fields) # :nodoc:
105
106
  @form_fields << form_fields
106
107
  end
108
+
109
+ def to_s
110
+ "{:title => #{self.title}, :instruction => #{self.instruction}, :form_fields => #{self.form_fields}, :errors => #{self.errors}}"
111
+ end
107
112
  end
108
113
  end
data/lib/cf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CF # :nodoc: all
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
@@ -122,5 +122,22 @@ describe CF::FormField do
122
122
  end
123
123
  end
124
124
 
125
+ it "should only display the attributes which are mentioned in to_s method" do
126
+ VCR.use_cassette "form-fields/block/display-to_s", :record => :new_episodes do
127
+ # WebMock.allow_net_connect!
128
+ line = CF::Line.create("Display_form_fields", "Digitization") do
129
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
130
+ CF::Station.create({:line => self, :type => "work"}) do |station|
131
+ CF::HumanWorker.new({:station => station, :number => 2, :reward => 20})
132
+ CF::TaskForm.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
133
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
134
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
135
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
136
+ end
137
+ end
138
+ end
139
+ line.stations.first.form.form_fields.first.to_s.should eql("{:id => => #{line.stations.first.form.form_fields.first.id}, :label => First Name, :field_type => short_answer, :required => true, :errors => }")
140
+ end
141
+ end
125
142
  end
126
143
  end
@@ -49,6 +49,19 @@ module CF
49
49
  line.stations.first.worker.errors.should eql("[\"Reward is not a number\", \"Reward must not contain decimal places\"]")
50
50
  end
51
51
  end
52
+
53
+ it "should only display the attributes which are mentioned in to_s method" do
54
+ VCR.use_cassette "human_worker/block/display-to_s", :record => :new_episodes do
55
+ # WebMock.allow_net_connect!
56
+ line = CF::Line.create("Display_human_worker", "Digitization") do
57
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
58
+ CF::Station.create({:line => self, :type => "work"}) do |station|
59
+ CF::HumanWorker.new({:station => station, :number => 2, :reward => 20})
60
+ end
61
+ end
62
+ line.stations.first.worker.to_s.should eql("{:id => => #{line.stations.first.worker.id}, :number => 2, :reward => 20, :stat_badge => {\"approval_rating\"=>80, \"assignment_duration\"=>3600, \"abandonment_rate\"=>30, \"country\"=>nil}, :skill_badges => [nil], :errors => }")
63
+ end
64
+ end
52
65
  end
53
66
 
54
67
  context "create a worker with skill_badge and skill_test" do
@@ -63,6 +63,19 @@ describe CF::InputFormat do
63
63
  line.input_formats[1].name.should eq("image")
64
64
  end
65
65
  end
66
+
67
+ it "should only display the attributes which are mentioned in to_s method" do
68
+ VCR.use_cassette "input_formats/block/display-to_s", :record => :new_episodes do
69
+ # WebMock.allow_net_connect!
70
+ line = CF::Line.create("Display_input_format", "Digitization") do
71
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
72
+ CF::Station.create({:line => self, :type => "work"}) do |station|
73
+ CF::HumanWorker.new({:station => station, :number => 2, :reward => 20})
74
+ end
75
+ end
76
+ line.input_formats.first.to_s.should eql("{:id => #{line.input_formats.first.id}, :name => image_url, :required => true, :valid_type => url, :errors => }")
77
+ end
78
+ end
66
79
  end
67
80
 
68
81
  context "return all the input headers" do
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe CF::RobotWorker do
4
+ context "create a robot worker" do
5
+ it "should only display the attributes which are mentioned in to_s method" do
6
+ VCR.use_cassette "robot_worker/block/display-to_s", :record => :new_episodes do
7
+ # WebMock.allow_net_connect!
8
+ line = CF::Line.create("display_entity_extraction_robot","Digitization") do |l|
9
+ CF::InputFormat.new({:line => l, :name => "text", :valid_type => "general", :required => "true"})
10
+ CF::Station.create({:line => l, :type => "work"}) do |s|
11
+ CF::RobotWorker.create({:station => s, :type => "entity_extraction_robot", :settings => {:document => ["Franz Kafka and George Orwell are authors. Ludwig Von Beethoven and Mozart are musicians. China and Japan are countries"]}})
12
+ end
13
+ end
14
+ line.stations.first.worker.to_s.should eql("{:number => #{line.stations.first.worker.number}, :reward => #{line.stations.first.worker.reward}, :type => EntityExtractionRobot, :settings => #{line.stations.first.worker.settings}, :errors => }")
15
+ end
16
+ end
17
+ end
18
+ end
data/spec/run_spec.rb CHANGED
@@ -84,7 +84,7 @@ module CF
84
84
 
85
85
  end
86
86
  end
87
-
87
+
88
88
  it "just using line title" do
89
89
  VCR.use_cassette "run/block/create-run-using-line-title", :record => :new_episodes do
90
90
  line = CF::Line.create("line_title_run","Digitization") do |l|
@@ -252,14 +252,14 @@ module CF
252
252
  it "should create production run with invalid data" do
253
253
  WebMock.allow_net_connect!
254
254
  # VCR.use_cassette "run/block/create-run-invalid-file", :record => :new_episodes do
255
- line = CF::Line.create("media_splitting_robot_4","Digitization") do |l|
256
- CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
257
- CF::Station.create({:line => l, :type => "work"}) do |s|
258
- CF::RobotWorker.create({:station => s, :type => "media_splitting_robot", :settings => {:url => ["http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"], :split_duration => "2", :overlapping_time => "1"}})
259
- end
255
+ line = CF::Line.create("media_splitting_robot_4","Digitization") do |l|
256
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
257
+ CF::Station.create({:line => l, :type => "work"}) do |s|
258
+ CF::RobotWorker.create({:station => s, :type => "media_splitting_robot", :settings => {:url => ["http://media-robot.s3.amazonaws.com/media_robot/media/upload/8/ten.mov"], :split_duration => "2", :overlapping_time => "1"}})
260
259
  end
261
- run = CF::Run.create(line, "media_splitting_robot_run_4", File.expand_path("../../fixtures/input_data/media_converter_robot.csv", __FILE__))
262
- run.errors.should eql(["Extra Headers in file: [url_1]", "Insufficient Headers in file: [url]"])
260
+ end
261
+ run = CF::Run.create(line, "media_splitting_robot_run_4", File.expand_path("../../fixtures/input_data/media_converter_robot.csv", __FILE__))
262
+ run.errors.should eql(["Extra Headers in file: [url_1]", "Insufficient Headers in file: [url]"])
263
263
 
264
264
  # end
265
265
  end
@@ -314,5 +314,149 @@ module CF
314
314
  end
315
315
  end
316
316
  end
317
+
318
+ context "check run progress and resume run" do
319
+ it "should check the progress" do
320
+ VCR.use_cassette "run/block/run-progress", :record => :new_episodes do
321
+ # WebMock.allow_net_connect!
322
+ line = CF::Line.create("progress_run_line","Digitization") do |l|
323
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
324
+ CF::Station.create({:line => l, :type => "work"}) do |s|
325
+ CF::RobotWorker.create({:station => s, :settings => {:url => ["{{url}}"], :max_retrieve => 5, :show_source_text => true}, :type => "term_extraction_robot"})
326
+ end
327
+ end
328
+ run = CF::Run.create(line, "progress_run", [{"url"=> "http://www.sprout-technology.com"}])
329
+ progress = run.progress
330
+ progress_1 = CF::Run.progress("progress_run")
331
+ progress.should eql(progress_1)
332
+ progress.progress.should eql(100)
333
+ end
334
+ end
335
+
336
+ it "should get the progress details" do
337
+ VCR.use_cassette "run/block/run-progress-detail", :record => :new_episodes do
338
+ # WebMock.allow_net_connect!
339
+ line = CF::Line.create("progress_run_line_1","Digitization") do |l|
340
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
341
+ CF::Station.create({:line => l, :type => "work"}) do |s|
342
+ CF::RobotWorker.create({:station => s, :settings => {:url => ["{{url}}"], :max_retrieve => 5, :show_source_text => true}, :type => "term_extraction_robot"})
343
+ end
344
+ end
345
+ run = CF::Run.create(line, "progress_run_1", [{"url"=> "http://www.sprout-technology.com"}])
346
+ progress = run.progress_details
347
+ progress_1 = CF::Run.progress_details("progress_run_1")
348
+ progress.should eql(progress_1)
349
+ progress.total.progress.should eql(100)
350
+ progress.total.units.should eql(1)
351
+ end
352
+ end
353
+
354
+ it "should get the progress details for multiple stations" do
355
+ VCR.use_cassette "run/block/run-progress-detail-for-multiple-station", :record => :new_episodes do
356
+ # WebMock.allow_net_connect!
357
+ line = CF::Line.create("progress_run_line_2","Digitization") do |l|
358
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
359
+ CF::Station.create({:line => l, :type => "work"}) do |s|
360
+ CF::RobotWorker.create({:station => s, :type => "text_extraction_robot", :settings => {:url => ["{{url}}"]}})
361
+ end
362
+ CF::Station.create({:line => l, :type => "work"}) do |s1|
363
+ CF::RobotWorker.create({:station => s1, :type => "keyword_matching_robot", :settings => {:content => ["{{contents_of_url}}"], :keywords => ["SaaS","see","additional","deepak","saroj"]}})
364
+ end
365
+ end
366
+ run = CF::Run.create(line, "progress_run_2", [{"url"=> "http://techcrunch.com/2011/07/26/with-v2-0-assistly-brings-a-simple-pricing-model-rewards-and-a-bit-of-free-to-customer-service-software"}])
367
+ progress = run.progress_details
368
+ progress_1 = CF::Run.progress_details("progress_run_2")
369
+ progress.should eql(progress_1)
370
+ progress.total.progress.should eql(100)
371
+ progress.total.units.should eql(1)
372
+ end
373
+ end
374
+ end
375
+
376
+ context "get run" do
377
+ it "should return all the runs for an account" do
378
+ VCR.use_cassette "run/block/get-run-account", :record => :new_episodes do
379
+ # WebMock.allow_net_connect!
380
+ line = CF::Line.create("progress_run_line_3","Digitization") do |l|
381
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
382
+ CF::Station.create({:line => l, :type => "work"}) do |s|
383
+ CF::RobotWorker.create({:station => s, :settings => {:url => ["{{url}}"], :max_retrieve => 5, :show_source_text => true}, :type => "term_extraction_robot"})
384
+ end
385
+ end
386
+ run = CF::Run.create(line, "progress_run_3", [{"url"=> "http://www.sprout-technology.com"}])
387
+
388
+ line_1 = CF::Line.create("progress_run_line_31","Digitization") do |l|
389
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
390
+ CF::Station.create({:line => l, :type => "work"}) do |s|
391
+ CF::RobotWorker.create({:station => s, :settings => {:url => ["{{url}}"], :max_retrieve => 5, :show_source_text => true}, :type => "term_extraction_robot"})
392
+ end
393
+ end
394
+ run_1 = CF::Run.create(line_1, "progress_run_31", [{"url"=> "http://www.sprout-technology.com"}])
395
+
396
+ line_2 = CF::Line.create("progress_run_line_32","Digitization") do |l|
397
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
398
+ CF::Station.create({:line => l, :type => "work"}) do |s|
399
+ CF::RobotWorker.create({:station => s, :settings => {:url => ["{{url}}"], :max_retrieve => 5, :show_source_text => true}, :type => "term_extraction_robot"})
400
+ end
401
+ end
402
+ run_2 = CF::Run.create(line_2, "progress_run_32", [{"url"=> "http://www.sprout-technology.com"}])
403
+
404
+ got_run = CF::Run.all
405
+ got_run[0].line.title.should eql("progress_run_line_3")
406
+ got_run[0].title.should eql("progress_run_3")
407
+ got_run[1].line.title.should eql("progress_run_line_31")
408
+ got_run[1].title.should eql("progress_run_31")
409
+ got_run[2].line.title.should eql("progress_run_line_32")
410
+ got_run[2].title.should eql("progress_run_32")
411
+ end
412
+ end
413
+
414
+ it "should return all the runs for a line" do
415
+ VCR.use_cassette "run/block/get-run-line", :record => :new_episodes do
416
+ # WebMock.allow_net_connect!
417
+ line = CF::Line.create("progress_run_line_11","Digitization") do |l|
418
+ CF::InputFormat.new({:line => l, :name => "url", :valid_type => "url", :required => "true"})
419
+ CF::Station.create({:line => l, :type => "work"}) do |s|
420
+ CF::RobotWorker.create({:station => s, :settings => {:url => ["{{url}}"], :max_retrieve => 5, :show_source_text => true}, :type => "term_extraction_robot"})
421
+ end
422
+ end
423
+ run = CF::Run.create(line, "progress_run_11", [{"url"=> "http://www.sprout-technology.com"}])
424
+ run_1 = CF::Run.create(line, "progress_run_12", [{"url"=> "http://www.sprout-technology.com"}])
425
+ run_2 = CF::Run.create(line, "progress_run_13", [{"url"=> "http://www.sprout-technology.com"}])
426
+ got_run = CF::Run.all("progress_run_line_11")
427
+ got_run[0].title.should eql("progress_run_11")
428
+ got_run[1].title.should eql("progress_run_12")
429
+ got_run[2].title.should eql("progress_run_13")
430
+ end
431
+ end
432
+ end
433
+
434
+ context "create a run with insufficient balance and" do
435
+ it "should resume run" do
436
+ VCR.use_cassette "run/block/resume-run", :record => :new_episodes do
437
+ # WebMock.allow_net_connect!
438
+ # change account available_balance to 10 cents
439
+ line = CF::Line.create("resume_run_line","Digitization") do |l|
440
+ CF::InputFormat.new({:line => l, :name => "Company", :required => true, :valid_type => "general"})
441
+ CF::InputFormat.new({:line => l, :name => "Website", :required => true, :valid_type => "url"})
442
+ CF::Station.create({:line => l, :type => "work"}) do |s|
443
+ CF::HumanWorker.new({:station => s, :number => 1, :reward => 20})
444
+ CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
445
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
446
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
447
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
448
+ end
449
+ end
450
+ end
451
+ run = CF::Run.create(line, "resume_run", [{"Company"=>"Apple,Inc","Website"=>"Apple.com"},{"Company"=>"Google","Website"=>"google.com"}])
452
+ # debugger
453
+ # Change account available_balance to 200000 cents
454
+ resumed_run = CF::Run.resume("resume_run")
455
+ resumed_run.code.should eql(200)
456
+ resumed_run.status.should eql("resumed")
457
+ resumed_run.title.should eql("resume_run")
458
+ end
459
+ end
460
+ end
317
461
  end
318
462
  end
data/spec/station_spec.rb CHANGED
@@ -95,6 +95,32 @@ describe CF::Station do
95
95
  expect { line.stations station }.to raise_error(CF::ImproveStationNotAllowed)
96
96
  end
97
97
  end
98
+
99
+ it "should only display the attributes which are mentioned in to_s method" do
100
+ VCR.use_cassette "stations/block/display-to_s", :record => :new_episodes do
101
+ # WebMock.allow_net_connect!
102
+ line = CF::Line.create("Display_station", "Digitization") do
103
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
104
+ CF::Station.create({:line => self, :type => "work"}) do |station|
105
+ CF::HumanWorker.new({:station => station, :number => 2, :reward => 20})
106
+ end
107
+ end
108
+ line.stations.first.to_s.should eql("{:type => WorkStation, :index => 1, :line_title => Display_station, :station_input_formats => , :errors => }")
109
+ end
110
+ end
111
+
112
+ it "should only display the attributes which are mentioned in to_s method for tournament station" do
113
+ VCR.use_cassette "stations/block/display-to_s-tournament", :record => :new_episodes do
114
+ # WebMock.allow_net_connect!
115
+ line = CF::Line.create("Display_station_tournament", "Digitization") do
116
+ CF::InputFormat.new({:line => self, :name => "image_url", :required => true, :valid_type => "url"})
117
+ CF::Station.create({:line => self, :type => "tournament", :jury_worker=> {:max_judges => 10, :reward => 5}, :auto_judge => {:enabled => true}}) do |s|
118
+ CF::HumanWorker.new({:station => s, :number => 2, :reward => 20})
119
+ end
120
+ end
121
+ line.stations.first.to_s.should eql("{:type => TournamentStation, :index => 1, :line_title => Display_station_tournament, :station_input_formats => , :jury_worker => {:max_judges=>10, :reward=>5}, auto_judge => {:enabled=>true}, :errors => }")
122
+ end
123
+ end
98
124
  end
99
125
 
100
126
  context "get station" do
@@ -24,6 +24,24 @@ describe CF::TaskForm do
24
24
  form.form_fields.first.required.should eq(true)
25
25
  end
26
26
  end
27
+
28
+ it "should only display the attributes which are mentioned in to_s method" do
29
+ VCR.use_cassette "task_form/block/display-to_s", :record => :new_episodes do
30
+ # WebMock.allow_net_connect!
31
+ line = CF::Line.create("Display_task_form", "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.create({:station => station, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
36
+ CF::FormField.new({:form => i, :label => "First Name", :field_type => "short_answer", :required => "true"})
37
+ CF::FormField.new({:form => i, :label => "Middle Name", :field_type => "short_answer"})
38
+ CF::FormField.new({:form => i, :label => "Last Name", :field_type => "short_answer", :required => "true"})
39
+ end
40
+ end
41
+ end
42
+ line.stations.first.form.to_s.should eql("{:title => Enter text from a business card image, :instruction => Describe, :form_fields => #{line.stations.first.form.form_fields}, :errors => }")
43
+ end
44
+ end
27
45
 
28
46
  it "with blank data" do
29
47
  WebMock.allow_net_connect!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudfactory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-12 00:00:00.000000000Z
12
+ date: 2011-08-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
16
- requirement: &2154512680 !ruby/object:Gem::Requirement
16
+ requirement: &2153983200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2154512680
24
+ version_requirements: *2153983200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &2154540320 !ruby/object:Gem::Requirement
27
+ requirement: &2153982700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.0.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2154540320
35
+ version_requirements: *2153982700
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hashie
38
- requirement: &2154539820 !ruby/object:Gem::Requirement
38
+ requirement: &2153982200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2154539820
46
+ version_requirements: *2153982200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rest-client
49
- requirement: &2154539440 !ruby/object:Gem::Requirement
49
+ requirement: &2153981820 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *2154539440
57
+ version_requirements: *2153981820
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: json
60
- requirement: &2154538980 !ruby/object:Gem::Requirement
60
+ requirement: &2153981360 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *2154538980
68
+ version_requirements: *2153981360
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thor
71
- requirement: &2154538480 !ruby/object:Gem::Requirement
71
+ requirement: &2153980860 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.14.6
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *2154538480
79
+ version_requirements: *2153980860
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: highline
82
- requirement: &2154538060 !ruby/object:Gem::Requirement
82
+ requirement: &2153980440 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *2154538060
90
+ version_requirements: *2153980440
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: httparty
93
- requirement: &2154537520 !ruby/object:Gem::Requirement
93
+ requirement: &2153979900 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 0.7.8
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *2154537520
101
+ version_requirements: *2153979900
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: terminal-table
104
- requirement: &2154537020 !ruby/object:Gem::Requirement
104
+ requirement: &2153979400 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ~>
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 1.4.2
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *2154537020
112
+ version_requirements: *2153979400
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: millisami-csv-hash
115
- requirement: &2154536640 !ruby/object:Gem::Requirement
115
+ requirement: &2153979020 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *2154536640
123
+ version_requirements: *2153979020
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: ruby-debug19
126
- requirement: &2154536180 !ruby/object:Gem::Requirement
126
+ requirement: &2153978560 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *2154536180
134
+ version_requirements: *2153978560
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: aruba
137
- requirement: &2154535760 !ruby/object:Gem::Requirement
137
+ requirement: &2153978140 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *2154535760
145
+ version_requirements: *2153978140
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: rails
148
- requirement: &2154535260 !ruby/object:Gem::Requirement
148
+ requirement: &2153977640 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ~>
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: 3.0.3
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *2154535260
156
+ version_requirements: *2153977640
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: bundler
159
- requirement: &2154534760 !ruby/object:Gem::Requirement
159
+ requirement: &2153977140 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ~>
@@ -164,10 +164,10 @@ dependencies:
164
164
  version: 1.0.0
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *2154534760
167
+ version_requirements: *2153977140
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: generator_spec
170
- requirement: &2154534300 !ruby/object:Gem::Requirement
170
+ requirement: &2153976680 !ruby/object:Gem::Requirement
171
171
  none: false
172
172
  requirements:
173
173
  - - ~>
@@ -175,10 +175,10 @@ dependencies:
175
175
  version: 0.8.3
176
176
  type: :development
177
177
  prerelease: false
178
- version_requirements: *2154534300
178
+ version_requirements: *2153976680
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: rspec-rails
181
- requirement: &2154533920 !ruby/object:Gem::Requirement
181
+ requirement: &2153976300 !ruby/object:Gem::Requirement
182
182
  none: false
183
183
  requirements:
184
184
  - - ! '>='
@@ -186,10 +186,10 @@ dependencies:
186
186
  version: '0'
187
187
  type: :development
188
188
  prerelease: false
189
- version_requirements: *2154533920
189
+ version_requirements: *2153976300
190
190
  - !ruby/object:Gem::Dependency
191
191
  name: cucumber
192
- requirement: &2154533460 !ruby/object:Gem::Requirement
192
+ requirement: &2153992200 !ruby/object:Gem::Requirement
193
193
  none: false
194
194
  requirements:
195
195
  - - ! '>='
@@ -197,10 +197,10 @@ dependencies:
197
197
  version: '0'
198
198
  type: :development
199
199
  prerelease: false
200
- version_requirements: *2154533460
200
+ version_requirements: *2153992200
201
201
  - !ruby/object:Gem::Dependency
202
202
  name: rdoc
203
- requirement: &2154532960 !ruby/object:Gem::Requirement
203
+ requirement: &2153991700 !ruby/object:Gem::Requirement
204
204
  none: false
205
205
  requirements:
206
206
  - - ~>
@@ -208,10 +208,10 @@ dependencies:
208
208
  version: 3.5.3
209
209
  type: :development
210
210
  prerelease: false
211
- version_requirements: *2154532960
211
+ version_requirements: *2153991700
212
212
  - !ruby/object:Gem::Dependency
213
213
  name: vcr
214
- requirement: &2154532540 !ruby/object:Gem::Requirement
214
+ requirement: &2153991280 !ruby/object:Gem::Requirement
215
215
  none: false
216
216
  requirements:
217
217
  - - ! '>='
@@ -219,10 +219,10 @@ dependencies:
219
219
  version: '0'
220
220
  type: :development
221
221
  prerelease: false
222
- version_requirements: *2154532540
222
+ version_requirements: *2153991280
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: rake
225
- requirement: &2154548440 !ruby/object:Gem::Requirement
225
+ requirement: &2153990820 !ruby/object:Gem::Requirement
226
226
  none: false
227
227
  requirements:
228
228
  - - ! '>='
@@ -230,10 +230,10 @@ dependencies:
230
230
  version: '0'
231
231
  type: :development
232
232
  prerelease: false
233
- version_requirements: *2154548440
233
+ version_requirements: *2153990820
234
234
  - !ruby/object:Gem::Dependency
235
235
  name: webmock
236
- requirement: &2154548020 !ruby/object:Gem::Requirement
236
+ requirement: &2153990400 !ruby/object:Gem::Requirement
237
237
  none: false
238
238
  requirements:
239
239
  - - ! '>='
@@ -241,10 +241,10 @@ dependencies:
241
241
  version: '0'
242
242
  type: :development
243
243
  prerelease: false
244
- version_requirements: *2154548020
244
+ version_requirements: *2153990400
245
245
  - !ruby/object:Gem::Dependency
246
246
  name: timecop
247
- requirement: &2154547600 !ruby/object:Gem::Requirement
247
+ requirement: &2153989980 !ruby/object:Gem::Requirement
248
248
  none: false
249
249
  requirements:
250
250
  - - ! '>='
@@ -252,7 +252,7 @@ dependencies:
252
252
  version: '0'
253
253
  type: :development
254
254
  prerelease: false
255
- version_requirements: *2154547600
255
+ version_requirements: *2153989980
256
256
  description: A Ruby wrapper and CLI for to interact with Cloudfactory.com REST API
257
257
  email:
258
258
  - info@cloudfactory.com
@@ -340,6 +340,7 @@ files:
340
340
  - spec/mailer_robot_spec.rb
341
341
  - spec/media_converter_robot_spec.rb
342
342
  - spec/media_splitting_robot_spec.rb
343
+ - spec/robot_worker_spec.rb
343
344
  - spec/run_spec.rb
344
345
  - spec/sentiment_robot_spec.rb
345
346
  - spec/spec_helper.rb
@@ -421,6 +422,7 @@ test_files:
421
422
  - spec/mailer_robot_spec.rb
422
423
  - spec/media_converter_robot_spec.rb
423
424
  - spec/media_splitting_robot_spec.rb
425
+ - spec/robot_worker_spec.rb
424
426
  - spec/run_spec.rb
425
427
  - spec/sentiment_robot_spec.rb
426
428
  - spec/spec_helper.rb