typingpool 0.8.11 → 0.8.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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/bin/tp-assign +5 -4
  3. data/bin/tp-collect +16 -6
  4. data/bin/tp-finish +5 -4
  5. data/bin/tp-make +5 -4
  6. data/bin/tp-review +52 -26
  7. data/lib/typingpool/test.rb +4 -126
  8. data/lib/typingpool/test/fixtures/tp_collect_id.txt +1 -1
  9. data/lib/typingpool/test/fixtures/tp_collect_sandbox-assignment.csv +7 -8
  10. data/lib/typingpool/test/fixtures/tp_review2a_id.txt +1 -0
  11. data/lib/typingpool/test/fixtures/tp_review2a_sandbox-assignment.csv +7 -0
  12. data/lib/typingpool/test/fixtures/tp_review2b_id.txt +1 -0
  13. data/lib/typingpool/test/fixtures/tp_review2b_sandbox-assignment.csv +7 -0
  14. data/lib/typingpool/test/fixtures/tp_review3_id.txt +1 -0
  15. data/lib/typingpool/test/fixtures/tp_review3_sandbox-assignment.csv +7 -0
  16. data/lib/typingpool/test/fixtures/tp_review_id.txt +1 -1
  17. data/lib/typingpool/test/fixtures/tp_review_sandbox-assignment.csv +7 -8
  18. data/lib/typingpool/test/fixtures/vcr/tp-collect-1.yml +3176 -1814
  19. data/lib/typingpool/test/fixtures/vcr/tp-collect-2.yml +116 -2641
  20. data/lib/typingpool/test/fixtures/vcr/tp-collect-3.yml +119 -2693
  21. data/lib/typingpool/test/fixtures/vcr/tp-review-1.yml +353 -355
  22. data/lib/typingpool/test/fixtures/vcr/tp-review-2.yml +161 -242
  23. data/lib/typingpool/test/fixtures/vcr/tp-review-3.yml +4716 -0
  24. data/lib/typingpool/test/fixtures/vcr/tp-review-4.yml +741 -0
  25. data/lib/typingpool/test/fixtures/vcr/tp-review-5.yml +248 -0
  26. data/lib/typingpool/test/fixtures/vcr/tp-review-6.yml +233 -0
  27. data/lib/typingpool/test/fixtures/vcr/tp-review-7.yml +4479 -0
  28. data/lib/typingpool/test/fixtures/vcr/tp-review-8.yml +188 -0
  29. data/lib/typingpool/test/fixtures/vcr/tp-review-9.yml +187 -0
  30. data/lib/typingpool/test/script.rb +13 -320
  31. data/lib/typingpool/utility/test.rb +175 -0
  32. data/lib/typingpool/utility/test/script.rb +342 -0
  33. data/lib/typingpool/version.rb +1 -1
  34. data/test/make_amazon_question_fixture.rb +1 -1
  35. data/test/make_tp_collect_fixture_1.rb +18 -19
  36. data/test/make_tp_collect_fixture_2.rb +16 -10
  37. data/test/make_tp_collect_fixture_3.rb +15 -9
  38. data/test/make_tp_collect_fixture_4.rb +19 -11
  39. data/test/make_tp_collect_fixture_5.rb +25 -0
  40. data/test/make_tp_collect_fixture_6.rb +22 -0
  41. data/test/make_tp_collect_fixture_7.rb +22 -0
  42. data/test/make_tp_collect_fixture_8.rb +26 -0
  43. data/test/make_tp_review_fixture_1.rb +18 -19
  44. data/test/make_tp_review_fixture_2.rb +43 -24
  45. data/test/make_tp_review_fixture_3.rb +35 -0
  46. data/test/make_tp_review_fixture_4.rb +56 -0
  47. data/test/test_integration_script_1_tp_config.rb +7 -7
  48. data/test/test_integration_script_2_tp_make.rb +12 -12
  49. data/test/test_integration_script_3_tp_assign.rb +23 -21
  50. data/test/test_integration_script_4_tp_review.rb +156 -23
  51. data/test/test_integration_script_5_tp_collect.rb +33 -24
  52. data/test/test_integration_script_6_tp_finish.rb +23 -20
  53. data/test/test_unit_amazon.rb +4 -2
  54. data/test/test_unit_filer.rb +6 -6
  55. data/test/test_unit_project.rb +2 -2
  56. data/test/test_unit_project_local.rb +2 -2
  57. data/test/test_unit_project_remote.rb +3 -1
  58. data/test/test_unit_template.rb +6 -6
  59. data/test/test_unit_test.rb +3 -3
  60. metadata +23 -3
  61. data/lib/typingpool/app/test.rb +0 -69
@@ -10,7 +10,7 @@ class TestTpConfig < Typingpool::Test::Script
10
10
 
11
11
  def test_abort_with_invalid_file
12
12
  exception = assert_raises(Typingpool::Error::Shell) do
13
- tp_config(File.join(fixtures_dir, 'not_yaml.txt'))
13
+ call_script('tp-config', File.join(fixtures_dir, 'not_yaml.txt'))
14
14
  end
15
15
  assert_match(/not valid yaml/i, exception.message)
16
16
  end
@@ -20,7 +20,7 @@ def test_abort_with_directory_path
20
20
  assert(File.exist? dir)
21
21
  assert(File.directory? dir)
22
22
  exception = assert_raises(Typingpool::Error::Shell) do
23
- tp_config(dir)
23
+ call_script('tp-config', dir)
24
24
  end
25
25
  assert_match(/not a file/i, exception.message)
26
26
  end
@@ -29,19 +29,19 @@ def test_abort_with_invalid_path
29
29
  path = '/jksdljs/euwiroeuw'
30
30
  refute(File.exist? path)
31
31
  exception = assert_raises(Typingpool::Error::Shell) do
32
- tp_config(path)
32
+ call_script('tp-config', path)
33
33
  end
34
34
  assert_match(/valid path/i, exception.message)
35
35
  end
36
36
 
37
37
  def test_usage_message
38
- out, _ = tp_config('--help')
38
+ out, _ = call_script('tp-config', '--help')
39
39
  assert(out)
40
40
  assert_match(/\bUSAGE:/, out)
41
41
  end
42
42
 
43
43
  def test_new_config_creation
44
- in_temp_dir do |dir|
44
+ Typingpool::Utility.in_temp_dir do |dir|
45
45
  path = {
46
46
  :config => File.join(dir, 'config.yml'),
47
47
  :transcript_dir => File.join(dir, 'transcriptionz')
@@ -62,7 +62,7 @@ def test_new_config_creation
62
62
  end
63
63
 
64
64
  def test_config_editing
65
- in_temp_dir do |dir|
65
+ Typingpool::Utility.in_temp_dir do |dir|
66
66
  path = {
67
67
  :config => File.join(dir, 'config.yml'),
68
68
  :fixture => File.join(fixtures_dir, 'config-1'),
@@ -88,7 +88,7 @@ def test_config_editing
88
88
  end
89
89
 
90
90
  def test_skips_bucket_when_sftp_params_exist
91
- in_temp_dir do |dir|
91
+ Typingpool::Utility.in_temp_dir do |dir|
92
92
  path = {
93
93
  :config => File.join(dir, 'config.yml'),
94
94
  :fixture => File.join(fixtures_dir, 'config-2'),
@@ -32,9 +32,9 @@ class TestTpMake < Typingpool::Test::Script
32
32
  'host' => 'example.com',
33
33
  'url' => 'http://example.com/foobar'
34
34
  }
35
- write_config(config, dir)
35
+ write_config(dir, config)
36
36
  exception = assert_raises(Typingpool::Error::Shell) do
37
- call_tp_make('--file', audio_files[0], '--title', 'Foo', '--config', config_path(dir), '--testnoupload')
37
+ call_script('tp-make', '--file', audio_files[0], '--title', 'Foo', '--config', config_path(dir), '--testnoupload')
38
38
  end
39
39
  assert_match(/must begin with 'https'/i, exception.message)
40
40
  end #with_temp_transcripts_dir do...
@@ -43,7 +43,7 @@ class TestTpMake < Typingpool::Test::Script
43
43
  def assert_tp_make_abort_match(args, regex)
44
44
  args.push('--testnoupload')
45
45
  assert_script_abort_match(args, regex) do |new_args|
46
- call_tp_make(*new_args)
46
+ call_script('tp-make', *new_args)
47
47
  end
48
48
  end
49
49
 
@@ -85,7 +85,7 @@ class TestTpMake < Typingpool::Test::Script
85
85
  config_path = self.config_path(dir)
86
86
  skip_if_no_upload_credentials('tp-make audio handling test', Typingpool::Config.file(config_path))
87
87
  tp_make(dir, config_path, subdir, true)
88
- assert(project = transcripts_dir_project(dir, Typingpool::Config.file(config_path)))
88
+ assert(project = Typingpool::Project.new(project_default[:title], Typingpool::Config.file(config_path)))
89
89
  check_project_files(project)
90
90
  end #with_temp_transcripts_dir
91
91
  end #Dir.entries
@@ -97,7 +97,7 @@ class TestTpMake < Typingpool::Test::Script
97
97
  skip_if_no_sftp_credentials('tp-make SFTP upload test', config)
98
98
  begin
99
99
  tp_make(dir)
100
- assert(project = transcripts_dir_project(dir))
100
+ assert(project = Typingpool::Project.new(project_default[:title], Typingpool::Config.file(config_path(dir))))
101
101
  check_project_files(project)
102
102
  check_project_uploads(project)
103
103
  ensure
@@ -110,10 +110,10 @@ class TestTpMake < Typingpool::Test::Script
110
110
  def test_tp_make_s3
111
111
  with_temp_transcripts_dir do |dir|
112
112
  skip_if_no_s3_credentials('tp-make S3 integration test', config)
113
- config_path = setup_s3_config(dir)
113
+ config_path = write_config(dir, reconfigure_for_s3(Typingpool::Config.file(config_path(dir))))
114
114
  begin
115
115
  tp_make_with_vcr(dir, 'tp_make_1', config_path)
116
- assert(project = transcripts_dir_project(dir, Typingpool::Config.file(config_path)))
116
+ assert(project = Typingpool::Project.new(project_default[:title], Typingpool::Config.file(config_path)))
117
117
  check_project_files(project)
118
118
  check_project_uploads(project, (Typingpool::Test.live || Typingpool::Test.record))
119
119
  ensure
@@ -128,12 +128,12 @@ class TestTpMake < Typingpool::Test::Script
128
128
  with_temp_transcripts_dir do |dir|
129
129
  config = Typingpool::Config.file(config_path(dir))
130
130
  skip_if_no_s3_credentials('tp-make failed upload integration test', config)
131
- good_config_path = setup_s3_config(dir)
132
- bad_config_path = setup_s3_config_with_bad_password(dir)
131
+ good_config_path = write_config(dir, reconfigure_for_s3(config))
132
+ bad_config_path = write_s3_config_with_bad_password(dir)
133
133
  assert_raises(Typingpool::Error::Shell) do
134
134
  tp_make(dir, bad_config_path, 'mp3')
135
135
  end
136
- assert(project = transcripts_dir_project(dir))
136
+ assert(project = Typingpool::Project.new(project_default[:title], Typingpool::Config.file(config_path(dir))))
137
137
  project_dir = project.local.path
138
138
  assert(File.exist? project_dir)
139
139
  assert(File.directory? project_dir)
@@ -145,7 +145,7 @@ class TestTpMake < Typingpool::Test::Script
145
145
  assert_all_assets_have_upload_status(assignment_csv, 'audio', 'maybe')
146
146
  assert(audio_urls = assignment_csv.map{|assignment| assignment['audio_url'] })
147
147
  refute_empty(audio_urls)
148
- assert_empty(audio_urls.select{|url| working_url? url })
148
+ assert_empty(audio_urls.select{|url| Typingpool::Utility.working_url? url })
149
149
  begin
150
150
  tp_make_with_vcr(dir, 'tp_make_2', good_config_path)
151
151
  refute_empty(assignment_csv.read)
@@ -169,7 +169,7 @@ class TestTpMake < Typingpool::Test::Script
169
169
  assert(audio_files('mp3').count > 1)
170
170
  correctly_ordered_paths = audio_files('mp3').sort
171
171
  tp_make(dir, config_path, 'mp3', true)
172
- assert(project = transcripts_dir_project(dir))
172
+ assert(project = Typingpool::Project.new(project_default[:title], Typingpool::Config.file(config_path(dir))))
173
173
  check_project_files(project)
174
174
  assert(merged_audio_file = project.local.subdir('audio','originals').files.detect{|filer| filer.path.match(/.\.all\../)})
175
175
  assert(File.exist? merged_audio_file)
@@ -5,6 +5,8 @@ $LOAD_PATH.unshift File.join(File.dirname(File.dirname(__FILE__)), 'lib')
5
5
  require 'minitest/autorun'
6
6
  require 'typingpool'
7
7
  require 'typingpool/test'
8
+ require 'typingpool/utility/test'
9
+ include Typingpool::Utility::Test
8
10
 
9
11
  class TestTpAssign < Typingpool::Test::Script
10
12
 
@@ -12,7 +14,7 @@ class TestTpAssign < Typingpool::Test::Script
12
14
  #(or at least some xml parsing) since rturk doesn't provide an
13
15
  #easy way to look at HIT qualifications)
14
16
  def test_abort_with_no_input
15
- assert_raises(Typingpool::Error::Shell){call_tp_assign}
17
+ assert_raises(Typingpool::Error::Shell){call_script('tp-assign','--sandbox')}
16
18
  end
17
19
 
18
20
  def test_abort_with_no_template
@@ -41,9 +43,9 @@ class TestTpAssign < Typingpool::Test::Script
41
43
  'host' => 'example.com',
42
44
  'url' => 'http://example.com/foobar'
43
45
  }
44
- write_config(config, dir)
46
+ write_config(dir, config)
45
47
  exception = assert_raises(Typingpool::Error::Shell) do
46
- call_tp_assign(project_default[:title], assign_default[:template], '--config', config_path(dir))
48
+ call_script('tp-assign','--sandbox', project_default[:title], assign_default[:template], '--config', config_path(dir))
47
49
  end
48
50
  assert_match(/must begin with 'https'/i, exception.message)
49
51
  end #with_temp_readymade_project do |dir|
@@ -51,7 +53,7 @@ class TestTpAssign < Typingpool::Test::Script
51
53
 
52
54
  def assert_tp_assign_abort_match(args, regex)
53
55
  assert_script_abort_match(args, regex) do |new_args|
54
- call_tp_assign(*new_args)
56
+ call_script('tp-assign', '--sandbox', *new_args)
55
57
  end
56
58
  end
57
59
 
@@ -59,14 +61,14 @@ class TestTpAssign < Typingpool::Test::Script
59
61
  skip_if_no_amazon_credentials('tp-assign integration test')
60
62
  skip_if_no_s3_credentials('tp-assign integration test')
61
63
  with_temp_readymade_project do |dir|
62
- project = transcripts_dir_project(dir)
64
+ project = Typingpool::Project.new(project_default[:title], Typingpool::Config.file(config_path(dir)))
63
65
  vcr_names = ['tp_assign_1', 'tp_assign_2']
64
66
  copy_tp_assign_fixtures(dir, vcr_names[0])
65
67
  config = Typingpool::Config.file(config_path(dir))
66
68
  Typingpool::Amazon.setup(:sandbox => true, :config => Typingpool::Config.file(config_path(dir)))
67
69
  with_vcr(vcr_names[1], config, {
68
70
  :preserve_exact_body_bytes => true,
69
- :match_requests_on => [:method, Typingpool::App.vcr_core_host_matcher]
71
+ :match_requests_on => [:method, vcr_core_host_matcher]
70
72
  }) do
71
73
  begin
72
74
  assign_time = (Typingpool::Test.record || Typingpool::Test.live) ? Time.now : project_time(project)
@@ -82,7 +84,7 @@ class TestTpAssign < Typingpool::Test::Script
82
84
  assign_default[:keyword].each{|keyword| assert_includes(keywords, keyword)}
83
85
  sandbox_csv = project.local.file('data', 'sandbox-assignment.csv').as(:csv)
84
86
  refute_empty(assignment_urls = sandbox_csv.map{|assignment| assignment['assignment_url'] })
85
- assert(assignment_html = fetch_url(assignment_urls.first).body)
87
+ assert(assignment_html = Typingpool::Utility.fetch_url(assignment_urls.first).body)
86
88
  assert_match(/\b22[\s-]+second\b/, assignment_html)
87
89
  assert_all_assets_have_upload_status(sandbox_csv, 'assignment', 'yes')
88
90
  ensure
@@ -97,12 +99,12 @@ class TestTpAssign < Typingpool::Test::Script
97
99
  skip_if_no_amazon_credentials('tp-assign unuploaded audio integration test')
98
100
  skip_if_no_s3_credentials('tp-assign unuploaded audio integration test')
99
101
  with_temp_readymade_project do |dir|
100
- project = transcripts_dir_project(dir)
102
+ project = Typingpool::Project.new(project_default[:title], Typingpool::Config.file(config_path(dir)))
101
103
  vcr_name = 'tp_assign_3'
102
104
  copy_tp_assign_fixtures(dir, vcr_name)
103
105
  csv = project.local.file('data', 'assignment.csv').as(:csv)
104
106
  if (Typingpool::Test.record || Typingpool::Test.live)
105
- assert_empty(csv.select{|assignment| working_url? assignment['audio_url']})
107
+ assert_empty(csv.select{|assignment| Typingpool::Utility.working_url? assignment['audio_url']})
106
108
  end
107
109
  csv.each{|assignment| assert_empty(assignment['audio_uploaded'].to_s) }
108
110
  begin
@@ -123,14 +125,14 @@ class TestTpAssign < Typingpool::Test::Script
123
125
  skip_if_no_amazon_credentials('tp-assign failed assignment upload integration test')
124
126
  skip_if_no_s3_credentials('tp-assign failed assignment upload integration test')
125
127
  with_temp_readymade_project do |dir|
126
- good_config_path = setup_s3_config(dir)
127
- reconfigure_readymade_project_in(good_config_path)
128
- project = transcripts_dir_project(dir, Typingpool::Config.file(good_config_path))
128
+ config = reconfigure_for_s3(Typingpool::Config.file(config_path(dir)))
129
+ good_config_path = write_config(dir, config)
130
+ project = Typingpool::Project.new(project_default[:title], config)
129
131
  vcr_names = ['tp_assign_4', 'tp_assign_5']
130
132
  copy_tp_assign_fixtures(dir, vcr_names[0], good_config_path)
131
133
  csv = project.local.file('data', 'assignment.csv').as(:csv)
132
134
  csv.each!{|a| a['audio_uploaded'] = 'yes'}
133
- bad_config_path = setup_s3_config_with_bad_password(dir)
135
+ bad_config_path = write_s3_config_with_bad_password(dir)
134
136
  get_assignment_urls = lambda{|assignments| assignments.map{|assignment| assignment['assignment_url'] }.select{|url| url } }
135
137
  assert_empty(get_assignment_urls.call(csv))
136
138
  begin
@@ -141,7 +143,7 @@ class TestTpAssign < Typingpool::Test::Script
141
143
  sandbox_csv = project.local.file('data', 'sandbox-assignment.csv').as(:csv)
142
144
  refute_empty(get_assignment_urls.call(sandbox_csv))
143
145
  if (Typingpool::Test.record || Typingpool::Test.live)
144
- get_assignment_urls.call(sandbox_csv).each{|url| refute(working_url? url) }
146
+ get_assignment_urls.call(sandbox_csv).each{|url| refute(Typingpool::Utility.working_url? url) }
145
147
  end
146
148
  assert_all_assets_have_upload_status(sandbox_csv, 'assignment', 'maybe')
147
149
  tp_assign_with_vcr(dir, vcr_names[1], good_config_path)
@@ -158,14 +160,14 @@ class TestTpAssign < Typingpool::Test::Script
158
160
  def test_abort_on_config_mismatch
159
161
  skip_if_no_s3_credentials('tp-assign abort on config mismatch test')
160
162
  with_temp_readymade_project do |dir|
161
- config = Typingpool::Config.file(config_path(dir))
162
- good_config_path = setup_s3_config(dir, config, '.config_s3_good')
163
- reconfigure_readymade_project_in(good_config_path)
163
+ config = reconfigure_for_s3(Typingpool::Config.file(config_path(dir)))
164
+ good_config_path = write_config(dir, config, '.config_s3_good')
165
+ reconfigure_project(Typingpool::Project.new(project_default[:title], config))
164
166
  assert(config.amazon.bucket)
165
167
  new_bucket = 'configmismatch-test'
166
168
  refute_equal(new_bucket, config.amazon.bucket)
167
169
  config.amazon.bucket = new_bucket
168
- bad_config_path = setup_s3_config(dir, config, '.config_s3_bad')
170
+ bad_config_path = write_config(dir, config, '.config_s3_bad')
169
171
  success = false
170
172
  begin
171
173
  exception = assert_raises(Typingpool::Error::Shell) do
@@ -181,10 +183,10 @@ class TestTpAssign < Typingpool::Test::Script
181
183
 
182
184
  def test_displays_and_uses_correct_reward_default
183
185
  with_temp_readymade_project do |dir|
184
- project = transcripts_dir_project(dir)
186
+ project = Typingpool::Project.new(project_default[:title], Typingpool::Config.file(config_path(dir)))
185
187
  config = Typingpool::Config.file(config_path(dir))
186
188
  config.assign.reward = '0.06'
187
- write_config(config, File.dirname(config_path(dir)), File.basename(config_path(dir)))
189
+ write_config(dir, config)
188
190
  vcr_names = ['tp_assign_6', 'tp_assign_7']
189
191
  copy_tp_assign_fixtures(dir, vcr_names[0])
190
192
  config = Typingpool::Config.file(config_path(dir))
@@ -192,7 +194,7 @@ class TestTpAssign < Typingpool::Test::Script
192
194
  Typingpool::Amazon.setup(:sandbox => true, :config => config)
193
195
  with_vcr(vcr_names[1], config, {
194
196
  :preserve_exact_body_bytes => true,
195
- :match_requests_on => [:method, Typingpool::App.vcr_core_host_matcher]
197
+ :match_requests_on => [:method, vcr_core_host_matcher]
196
198
  }) do
197
199
  begin
198
200
  _, err = tp_assign_with_vcr(dir, vcr_names[0])
@@ -8,59 +8,192 @@ require 'typingpool/test'
8
8
 
9
9
  class TestTpReview < Typingpool::Test::Script
10
10
 
11
- def test_tp_review
11
+ def test_tp_review_with_project_specified
12
12
  with_temp_readymade_project do |dir|
13
13
  skip_if_no_upload_credentials('tp-review integration test')
14
14
  skip_if_no_amazon_credentials('tp-review integration test')
15
- copy_fixtures_to_transcripts_dir(dir, 'tp_review_')
16
- project = transcripts_dir_project(dir)
15
+ copy_fixtures_to_project_dir('tp_review_', File.join(dir, project_default[:title]))
16
+ project = Typingpool::Project.new(project_default[:title], Typingpool::Config.file(config_path(dir)))
17
17
  assert(File.exist? File.join(project.local, 'data','sandbox-assignment.csv'))
18
- assert_equal(7, project.local.file('data','sandbox-assignment.csv').as(:csv).reject{|assignment| assignment['hit_id'].to_s.empty? }.count)
18
+ assert_equal(6, project.local.file('data','sandbox-assignment.csv').as(:csv).reject{|assignment| assignment['hit_id'].to_s.empty? }.count)
19
19
  begin
20
20
  output = nil
21
- output = tp_review_with_fixture(dir, File.join(fixtures_dir, 'vcr', 'tp-review-1'), %w(a r a r s q))
21
+ output = tp_review_with_fixture(dir, 'tp-review-1', %w(a r a r s q), false, project_default[:title])
22
22
  assert_equal(0, output[:status].to_i, "Bad exit code: #{output[:status]} err: #{output[:err]}")
23
- assert_equal(5, project.local.file('data','sandbox-assignment.csv').as(:csv).reject{|assignment| assignment['hit_id'].to_s.empty? }.count)
23
+ assert_equal(2, project_hits_approved(project).count)
24
+ assert_equal(2, project_hits_rejected(project).count)
25
+ assert_equal(2, project_hits_pending(project).count)
24
26
  reviews = split_reviews(output[:out])
25
27
  assert_match(/Interview\.00\.00/, reviews[1])
26
28
  #we can't specify leading \b boundaries because the ansi
27
29
  #escape sequences mess that up
28
30
  assert_match(/Approved\b/i, reviews[1])
29
- assert_match(/Interview\.00\.20/, reviews[2])
31
+ assert_match(/Interview\.00\.22/, reviews[2])
30
32
  assert_match(/reason\b/i, reviews[2])
31
33
  assert_match(/Rejected\b/i, reviews[2])
32
- assert_match(/Interview\.00\.40/, reviews[3])
34
+ assert_match(/Interview\.00\.44/, reviews[3])
33
35
  assert_match(/Approved\b/i, reviews[3])
34
- assert_match(/Interview\.01\.00/, reviews[4])
36
+ assert_match(/Interview\.01\.06/, reviews[4])
35
37
  assert_match(/reason\b/i, reviews[4])
36
38
  assert_match(/Rejected\b/i, reviews[4])
37
- assert_match(/Interview\.01\.20/, reviews[5])
39
+ assert_match(/Interview\.01\.28/, reviews[5])
38
40
  assert_match(/Skipping\b/i, reviews[5])
39
- assert_match(/Interview\.02\.00/, reviews[6])
41
+ assert_match(/Interview\.01\.50/, reviews[6])
40
42
  assert_match(/Quitting\b/i, reviews[6])
41
- transcript = assert_has_partial_transcript(dir)
43
+ transcript = assert_has_partial_transcript(project)
42
44
  assert_html_has_audio_count(2, transcript)
43
45
  assert_assignment_csv_has_transcription_count(2, project, 'sandbox-assignment.csv')
44
- output = tp_review_with_fixture(dir, File.join(fixtures_dir, 'vcr', 'tp-review-2'), %w(a r))
46
+
47
+ output = tp_review_with_fixture(dir, 'tp-review-2', %w(a q), false, project_default[:title])
45
48
  assert_equal(0, output[:status].to_i, "Bad exit code: #{output[:status]} err: #{output[:err]}")
46
- assert_equal(4, project.local.file('data','sandbox-assignment.csv').as(:csv).reject{|assignment| assignment['hit_id'].to_s.empty? }.count)
49
+ assert_equal(3, project_hits_approved(project).count)
50
+ assert_equal(2, project_hits_rejected(project).count)
51
+ assert_equal(1, project_hits_pending(project).count)
47
52
  reviews = split_reviews(output[:out])
48
- assert_match(/Interview\.01\.20/, reviews[1])
53
+ assert_match(/Interview\.01\.28/, reviews[1])
49
54
  assert_match(/Approved\b/i, reviews[1])
50
- assert_match(/Interview\.02\.00/, reviews[2])
51
- assert_match(/reason\b/i, reviews[2])
52
- assert_match(/Rejected\b/i, reviews[2])
53
- transcript = assert_has_partial_transcript(dir)
55
+ assert_match(/Interview\.01\.50/, reviews[2])
56
+ assert_match(/Quitting\b/i, reviews[2])
57
+ transcript = assert_has_partial_transcript(project)
54
58
  assert_html_has_audio_count(3, transcript)
55
59
  assert_assignment_csv_has_transcription_count(3, project, 'sandbox-assignment.csv')
60
+
61
+ output = tp_review_with_fixture(dir, 'tp-review-6', %w(q), false, project_default[:title])
62
+ assert_equal(4, project_hits_approved(project).count)
63
+ assert_equal(2, project_hits_rejected(project).count)
64
+ assert_equal(0, project_hits_pending(project).count)
65
+ assert_equal(0, output[:status].to_i, "Bad exit code: #{output[:status]} err: #{output[:err]}")
66
+ transcript = assert_has_partial_transcript(project)
67
+ assert_html_has_audio_count(4, transcript)
68
+ assert_assignment_csv_has_transcription_count(4, project, 'sandbox-assignment.csv')
56
69
  ensure
57
- rm_fixtures_from_transcripts_dir(dir, 'tp_review_')
70
+ restore_project_dir_from_fixtures('tp_review_', File.join(dir, project_default[:title]))
58
71
  end #begin
59
72
  end #with_temp_readymade_project do...
60
73
  end
61
74
 
62
- def split_reviews(output)
63
- output.split(/Transcript for\b/)
75
+ def test_tp_review_without_project_specified
76
+ skip_if_no_upload_credentials('tp-review integration test')
77
+ skip_if_no_amazon_credentials('tp-review integration test')
78
+ with_temp_readymade_project do |transcripts_dir|
79
+ project_title = [ project_default[:title], "Second #{project_default[:title]}" ]
80
+ FileUtils.cp_r(File.join(transcripts_dir, project_title[0]), File.join(transcripts_dir, project_title[1]))
81
+ copy_fixtures_to_project_dir('tp_review2a_', File.join(transcripts_dir, project_title[0]))
82
+ copy_fixtures_to_project_dir('tp_review2b_', File.join(transcripts_dir, project_title[1]))
83
+ project = project_title.sort.map{|title| Typingpool::Project.new(title, Typingpool::Config.file(config_path(transcripts_dir))) }
84
+ project.each do |project|
85
+ assert(File.exist? File.join(project.local, 'data','sandbox-assignment.csv'))
86
+ assert_equal(6, project_hits_pending(project).count)
87
+ end
88
+ begin
89
+ output = tp_review_with_fixture(transcripts_dir, 'tp-review-3', %w(a r a r s s r a a s a q), false)
90
+ assert_equal(0, output[:status].to_i, "Bad exit code: #{output[:status]} err: #{output[:err]}")
91
+ reviews = split_reviews(output[:out])
92
+
93
+ assert_equal(2, project_hits_approved(project[0]).count)
94
+ assert_equal(2, project_hits_rejected(project[0]).count)
95
+ assert_equal(2, project_hits_pending(project[0]).count)
96
+ assert_match(/Interview\.00\.00/, reviews[1])
97
+ #we can't specify leading \b boundaries because the ansi
98
+ #escape sequences mess that up
99
+ assert_match(/Approved\b/i, reviews[1])
100
+ assert_match(/Interview\.00\.22/, reviews[2])
101
+ assert_match(/reason\b/i, reviews[2])
102
+ assert_match(/Rejected\b/i, reviews[2])
103
+ assert_match(/Interview\.00\.44/, reviews[3])
104
+ assert_match(/Approved\b/i, reviews[3])
105
+ assert_match(/Interview\.01\.06/, reviews[4])
106
+ assert_match(/reason\b/i, reviews[4])
107
+ assert_match(/Rejected\b/i, reviews[4])
108
+ assert_match(/Interview\.01\.28/, reviews[5])
109
+ assert_match(/Skipping\b/i, reviews[5])
110
+ assert_match(/Interview\.01\.50/, reviews[6])
111
+ assert_match(/Skipping/i, reviews[6])
112
+ transcript = assert_has_partial_transcript(project[0])
113
+ assert_html_has_audio_count(2, transcript)
114
+ assert_assignment_csv_has_transcription_count(2, project[0], 'sandbox-assignment.csv')
115
+
116
+ assert_equal(3, project_hits_approved(project[1]).count)
117
+ assert_equal(1, project_hits_rejected(project[1]).count)
118
+ assert_equal(2, project_hits_pending(project[1]).count)
119
+ assert_match(/Interview\.00\.00/, reviews[7])
120
+ assert_match(/Rejected\b/i, reviews[7])
121
+ assert_match(/reason\b/i, reviews[7])
122
+ assert_match(/Interview\.00\.22/, reviews[8])
123
+ assert_match(/Approved\b/i, reviews[8])
124
+ assert_match(/Interview\.00\.44/, reviews[9])
125
+ assert_match(/Approved\b/i, reviews[9])
126
+ assert_match(/Interview\.01\.06/, reviews[10])
127
+ assert_match(/Skipping\b/i, reviews[10])
128
+ assert_match(/Interview\.01\.28/, reviews[11])
129
+ assert_match(/Approved\b/i, reviews[11])
130
+ assert_match(/Interview\.01\.50/, reviews[12])
131
+ assert_match(/Quitting\b/i, reviews[12])
132
+ transcript = assert_has_partial_transcript(project[1])
133
+ assert_html_has_audio_count(3, transcript)
134
+ assert_assignment_csv_has_transcription_count(3, project[1], 'sandbox-assignment.csv')
135
+
136
+ output = tp_review_with_fixture(transcripts_dir, 'tp-review-4', %w(a r s a), false)
137
+ assert_equal(0, output[:status].to_i, "Bad exit code: #{output[:status]} err: #{output[:err]}")
138
+ reviews = split_reviews(output[:out])
139
+
140
+ assert_equal(3, project_hits_approved(project[0]).count)
141
+ assert_equal(3, project_hits_rejected(project[0]).count)
142
+ assert_equal(0, project_hits_pending(project[0]).count)
143
+ assert_match(/Interview\.01\.28/, reviews[1])
144
+ assert_match(/Approved\b/i, reviews[1])
145
+ assert_match(/Interview\.01\.50/, reviews[2])
146
+ assert_match(/reason\b/i, reviews[2])
147
+ assert_match(/Rejected\b/i, reviews[2])
148
+ transcript = assert_has_partial_transcript(project[0])
149
+ assert_html_has_audio_count(3, transcript)
150
+ assert_assignment_csv_has_transcription_count(3, project[0], 'sandbox-assignment.csv')
151
+
152
+ assert_equal(4, project_hits_approved(project[1]).count)
153
+ assert_equal(1, project_hits_rejected(project[1]).count)
154
+ assert_equal(1, project_hits_pending(project[1]).count)
155
+ assert_match(/Interview\.01\.06/, reviews[3])
156
+ assert_match(/Skipping\b/i, reviews[3])
157
+ assert_match(/Interview\.01\.50/, reviews[4])
158
+ assert_match(/Approved\b/i, reviews[4])
159
+ transcript = assert_has_partial_transcript(project[1])
160
+ assert_html_has_audio_count(4, transcript)
161
+ assert_assignment_csv_has_transcription_count(4, project[1], 'sandbox-assignment.csv')
162
+
163
+ output = tp_review_with_fixture(transcripts_dir, 'tp-review-5', %w(q), false)
164
+ assert_equal(0, output[:status].to_i, "Bad exit code: #{output[:status]} err: #{output[:err]}")
165
+ assert_equal(5, project_hits_approved(project[1]).count)
166
+ assert_equal(1, project_hits_rejected(project[1]).count)
167
+ assert_equal(0, project_hits_pending(project[1]).count)
168
+ transcript = assert_has_partial_transcript(project[1])
169
+ assert_html_has_audio_count(5, transcript)
170
+ assert_assignment_csv_has_transcription_count(5, project[1], 'sandbox-assignment.csv')
171
+ ensure
172
+ restore_project_dir_from_fixtures('tp_review2a_', File.join(transcripts_dir, project_title[0]))
173
+ restore_project_dir_from_fixtures('tp_review2b_', File.join(transcripts_dir, project_title[1]))
174
+ end #begin
175
+ end #with_temp_readymade_project
64
176
  end
177
+
178
+
179
+ def project_hits_rejected(project)
180
+ project.local.file('data','sandbox-assignment.csv').as(:csv).select{|assignment| assignment_rejected?(assignment) }
181
+ end
182
+
183
+ def project_hits_approved(project)
184
+ project.local.file('data','sandbox-assignment.csv').as(:csv).select{|assignment| assignment_approved?(assignment) }
185
+ end
186
+
187
+ def project_hits_pending(project)
188
+ project.local.file('data','sandbox-assignment.csv').as(:csv).reject{|assignment| assignment_approved?(assignment) || assignment_rejected?(assignment)}
189
+ end
190
+
191
+ def assignment_rejected?(assignment)
192
+ assignment['hit_id'].to_s.empty?
193
+ end
65
194
 
66
- end #class TestTpReview
195
+ def assignment_approved?(assignment)
196
+ assignment['transcript'].to_s.match(/\S/)
197
+ end
198
+
199
+ end #class TestTpReview