typingpool 0.8.10 → 0.8.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/bin/tp-assign +9 -5
  4. data/bin/tp-config +6 -6
  5. data/bin/tp-finish +1 -1
  6. data/bin/tp-make +9 -3
  7. data/lib/typingpool/amazon/hit/full/fromsearchhits.rb +2 -1
  8. data/lib/typingpool/amazon/hit/full.rb +3 -2
  9. data/lib/typingpool/amazon/hit.rb +19 -1
  10. data/lib/typingpool/amazon.rb +1 -2
  11. data/lib/typingpool/app/cli.rb +3 -3
  12. data/lib/typingpool/app/friendlyexceptions.rb +1 -1
  13. data/lib/typingpool/app.rb +24 -6
  14. data/lib/typingpool/config/root.rb +1 -0
  15. data/lib/typingpool/config.rb +6 -5
  16. data/lib/typingpool/filer/audio.rb +2 -2
  17. data/lib/typingpool/filer/dir.rb +1 -1
  18. data/lib/typingpool/filer.rb +1 -1
  19. data/lib/typingpool/project/local.rb +3 -3
  20. data/lib/typingpool/project/remote.rb +4 -3
  21. data/lib/typingpool/project.rb +2 -1
  22. data/lib/typingpool/template.rb +2 -2
  23. data/lib/typingpool/test/fixtures/amazon-question-url.txt +1 -1
  24. data/lib/typingpool/test/fixtures/config-2 +1 -1
  25. data/lib/typingpool/test/fixtures/test_amazon_hit_full_time.txt +1 -1
  26. data/lib/typingpool/test/fixtures/tp_assign_1_assignment.csv +6 -6
  27. data/lib/typingpool/test/fixtures/tp_assign_1_id.txt +1 -1
  28. data/lib/typingpool/test/fixtures/tp_assign_1_time.txt +1 -1
  29. data/lib/typingpool/test/fixtures/tp_assign_3_assignment.csv +6 -6
  30. data/lib/typingpool/test/fixtures/tp_assign_3_id.txt +1 -1
  31. data/lib/typingpool/test/fixtures/tp_assign_3_time.txt +1 -1
  32. data/lib/typingpool/test/fixtures/tp_assign_4_assignment.csv +6 -6
  33. data/lib/typingpool/test/fixtures/tp_assign_4_id.txt +1 -1
  34. data/lib/typingpool/test/fixtures/tp_assign_4_time.txt +1 -1
  35. data/lib/typingpool/test/fixtures/tp_assign_6_assignment.csv +6 -6
  36. data/lib/typingpool/test/fixtures/tp_assign_6_id.txt +1 -1
  37. data/lib/typingpool/test/fixtures/tp_assign_6_time.txt +1 -1
  38. data/lib/typingpool/test/fixtures/tp_finish_3_assignment.csv +6 -6
  39. data/lib/typingpool/test/fixtures/tp_finish_3_id.txt +1 -1
  40. data/lib/typingpool/test/fixtures/tp_finish_3_time.txt +1 -1
  41. data/lib/typingpool/test/fixtures/vcr/test_amazon_hit_base.yml +35 -29
  42. data/lib/typingpool/test/fixtures/vcr/test_amazon_hit_create.yml +52 -44
  43. data/lib/typingpool/test/fixtures/vcr/test_amazon_hit_full.yml +36 -30
  44. data/lib/typingpool/test/fixtures/vcr/test_amazon_hit_full_fromsearchhits.yml +69 -57
  45. data/lib/typingpool/test/fixtures/vcr/test_amazon_hit_retrievers.yml +94 -76
  46. data/lib/typingpool/test/fixtures/vcr/test_handles_hits_with_broken_external_question.yml +51 -53
  47. data/lib/typingpool/test/fixtures/vcr/tp_assign_1.yml +628 -628
  48. data/lib/typingpool/test/fixtures/vcr/tp_assign_2.yml +265 -3044
  49. data/lib/typingpool/test/fixtures/vcr/tp_assign_3.yml +629 -629
  50. data/lib/typingpool/test/fixtures/vcr/tp_assign_4.yml +65 -62
  51. data/lib/typingpool/test/fixtures/vcr/tp_assign_5.yml +623 -623
  52. data/lib/typingpool/test/fixtures/vcr/tp_assign_6.yml +592 -588
  53. data/lib/typingpool/test/fixtures/vcr/tp_assign_7.yml +195 -195
  54. data/lib/typingpool/test/fixtures/vcr/tp_finish_1.yml +91 -91
  55. data/lib/typingpool/test/fixtures/vcr/tp_finish_2.yml +76 -3989
  56. data/lib/typingpool/test/fixtures/vcr/tp_finish_3.yml +713 -695
  57. data/lib/typingpool/test/fixtures/vcr/tp_finish_4.yml +527 -3276
  58. data/lib/typingpool/test/fixtures/vcr/tp_finish_5.yml +338 -5602
  59. data/lib/typingpool/test/fixtures/vcr/tp_finish_6.yml +91 -91
  60. data/lib/typingpool/test/fixtures/vcr/tp_finish_7.yml +86 -3999
  61. data/lib/typingpool/test/fixtures/vcr/tp_finish_8.yml +51 -0
  62. data/lib/typingpool/test/script.rb +4 -6
  63. data/lib/typingpool/test.rb +3 -2
  64. data/lib/typingpool/utility.rb +6 -5
  65. data/lib/typingpool/version.rb +1 -1
  66. data/test/test_integration_script_1_tp_config.rb +12 -12
  67. data/test/test_integration_script_2_tp_make.rb +24 -8
  68. data/test/test_integration_script_3_tp_assign.rb +34 -19
  69. data/test/test_integration_script_4_tp_review.rb +1 -1
  70. data/test/test_integration_script_6_tp_finish.rb +5 -5
  71. data/test/test_unit_amazon.rb +12 -4
  72. data/test/test_unit_config.rb +2 -2
  73. data/test/test_unit_filer.rb +14 -14
  74. data/test/test_unit_project.rb +3 -3
  75. data/test/test_unit_project_local.rb +4 -4
  76. data/test/test_unit_project_remote.rb +1 -1
  77. data/test/test_unit_test.rb +2 -2
  78. data/typingpool.gemspec +3 -2
  79. metadata +24 -8
@@ -0,0 +1,51 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://mechanicalturk.amazonaws.com/
6
+ body:
7
+ encoding: UTF-8
8
+ base64_string: |
9
+ UGFnZVNpemU9MTAwJlBhZ2VOdW1iZXI9MSZPcGVyYXRpb249U2VhcmNoSElU
10
+ cyZTZXJ2aWNlPUFXU01lY2hhbmljYWxUdXJrUmVxdWVzdGVyJkFXU0FjY2Vz
11
+ c0tleUlkPTxBV1NfS0VZPiZUaW1lc3RhbXA9MjAxNi0xMi0zMVQwMiUzQTI1
12
+ JTNBMjlaJlZlcnNpb249MjAxMi0wMy0yNSZTaWduYXR1cmU9dkdBNWNpZU1v
13
+ cXFWWG8yVm9JOXpSeGdzekNFJTNE
14
+ headers:
15
+ Accept:
16
+ - '*/*'
17
+ Accept-Encoding:
18
+ - gzip, deflate
19
+ User-Agent:
20
+ - rest-client/2.0.0 (darwin15.6.0 x86_64) ruby/2.0.0p353
21
+ Content-Length:
22
+ - '212'
23
+ Host:
24
+ - mechanicalturk.amazonaws.com
25
+ response:
26
+ status:
27
+ code: 200
28
+ message: OK
29
+ headers:
30
+ Content-Type:
31
+ - text/xml
32
+ Transfer-Encoding:
33
+ - chunked
34
+ Date:
35
+ - Sat, 31 Dec 2016 02:25:29 GMT
36
+ Server:
37
+ - MTurk
38
+ body:
39
+ encoding: UTF-8
40
+ base64_string: |
41
+ PD94bWwgdmVyc2lvbj0iMS4wIj8+CjxTZWFyY2hISVRzUmVzcG9uc2U+PE9w
42
+ ZXJhdGlvblJlcXVlc3Q+PFJlcXVlc3RJZD4xNGE1MzhjNC01NWFlLTQyNjgt
43
+ YjljZC1mZmIwYzM5ODI3NWM8L1JlcXVlc3RJZD48L09wZXJhdGlvblJlcXVl
44
+ c3Q+PFNlYXJjaEhJVHNSZXN1bHQ+PFJlcXVlc3Q+PElzVmFsaWQ+VHJ1ZTwv
45
+ SXNWYWxpZD48L1JlcXVlc3Q+PE51bVJlc3VsdHM+MDwvTnVtUmVzdWx0cz48
46
+ VG90YWxOdW1SZXN1bHRzPjA8L1RvdGFsTnVtUmVzdWx0cz48UGFnZU51bWJl
47
+ cj4xPC9QYWdlTnVtYmVyPjwvU2VhcmNoSElUc1Jlc3VsdD48L1NlYXJjaEhJ
48
+ VHNSZXNwb25zZT4=
49
+ http_version:
50
+ recorded_at: Sat, 31 Dec 2016 02:25:29 GMT
51
+ recorded_with: VCR 3.0.3
@@ -32,7 +32,6 @@ module Typingpool
32
32
  end
33
33
 
34
34
  def copy_readymade_project_into(config_path)
35
- config = Typingpool::Config.file(config_path)
36
35
  FileUtils.cp_r(File.join(@@readymade_project_path, '.'), File.dirname(config_path))
37
36
  end
38
37
 
@@ -42,7 +41,6 @@ module Typingpool
42
41
  project = Project.new(project_default[:title], Config.file(config_path))
43
42
  File.delete(project.local.file('data', 'id.txt'))
44
43
  project.local.create_id
45
- id = project.local.id
46
44
  reconfigure_project_csv_in(config_path)
47
45
  end
48
46
 
@@ -288,7 +286,7 @@ module Typingpool
288
286
 
289
287
  def make_fixture_project_dir(name)
290
288
  dir = fixture_project_dir(name)
291
- if File.exists? dir
289
+ if File.exist? dir
292
290
  raise Error::Test, "Fixture project already exists for #{name} at #{dir}"
293
291
  end
294
292
  Dir.mkdir(dir)
@@ -312,7 +310,7 @@ module Typingpool
312
310
  def copy_fixtures_to_transcripts_dir(dir, fixture_prefix)
313
311
  copies = 0
314
312
  with_fixtures_in_transcripts_dir(dir, fixture_prefix) do |fixture_path, project_path|
315
- if File.exists? project_path
313
+ if File.exist? project_path
316
314
  FileUtils.mv(project_path, File.join(File.dirname(project_path), "orig_#{File.basename(project_path)}"))
317
315
  end
318
316
  FileUtils.cp(fixture_path, project_path)
@@ -326,7 +324,7 @@ module Typingpool
326
324
  with_fixtures_in_transcripts_dir(dir, fixture_prefix) do |fixture_path, project_path|
327
325
  FileUtils.rm(project_path)
328
326
  path_to_orig = File.join(File.dirname(project_path), "orig_#{File.basename(project_path)}")
329
- if File.exists?(path_to_orig)
327
+ if File.exist?(path_to_orig)
330
328
  FileUtils.mv(path_to_orig, project_path)
331
329
  end
332
330
  end
@@ -334,7 +332,7 @@ module Typingpool
334
332
 
335
333
  def assert_has_transcript(dir, transcript_file='transcript.html')
336
334
  transcript_path = File.join(transcripts_dir_project(dir).local, transcript_file)
337
- assert(File.exists?(transcript_path))
335
+ assert(File.exist?(transcript_path))
338
336
  assert(not((transcript = IO.read(transcript_path)).empty?))
339
337
  transcript
340
338
  end
@@ -1,6 +1,7 @@
1
1
  module Typingpool
2
2
  require 'minitest'
3
3
  require 'typingpool/app/test'
4
+
4
5
  class Test < Minitest::Test
5
6
  class << self
6
7
  attr_accessor :live
@@ -29,7 +30,7 @@ module Typingpool
29
30
 
30
31
  def delete_vcr_fixture(fixture_name)
31
32
  fixture_path = File.join(vcr_dir, [fixture_name, '.yml'].join)
32
- File.delete(fixture_path) if File.exists? fixture_path
33
+ File.delete(fixture_path) if File.exist? fixture_path
33
34
  end
34
35
 
35
36
  def cleared_vcr_fixture_path_for(fixture_name)
@@ -54,7 +55,7 @@ module Typingpool
54
55
  end
55
56
 
56
57
  def config
57
- if File.exists?(File.expand_path(Config.default_file))
58
+ if File.exist?(File.expand_path(Config.default_file))
58
59
  Config.file
59
60
  else
60
61
  Config.from_bundled_template
@@ -5,7 +5,8 @@ module Typingpool
5
5
  require 'tmpdir'
6
6
  require 'set'
7
7
  require 'net/http'
8
-
8
+ require 'fcntl'
9
+
9
10
  class << self
10
11
  #Much like Kernel#system, except it doesn't spew STDERR and
11
12
  #STDOUT all over your screen (when called with multiple args,
@@ -158,8 +159,8 @@ module Typingpool
158
159
  #following redirects). False if the HTTP response code indicates
159
160
  #an error (e.g. 4XX and 5XX response codes).
160
161
  def working_url?(url, max_redirects=6)
161
- response = request_url_with(url, max_redirects) do |url, http|
162
- http.request_head(url.path)
162
+ response = request_url_with(url, max_redirects) do |current_url, http|
163
+ http.request_head(current_url.path)
163
164
  end #request_url_with... do |url|
164
165
  response.kind_of?(Net::HTTPSuccess)
165
166
  end
@@ -177,8 +178,8 @@ module Typingpool
177
178
  # ==== Returns
178
179
  #A Net::HTTPResponse instance, if the request was successful.
179
180
  def fetch_url(url, max_redirects=6)
180
- response = request_url_with(url, max_redirects) do |url, http|
181
- http.request_get(url.path)
181
+ response = request_url_with(url, max_redirects) do |current_url, http|
182
+ http.request_get(current_url.path)
182
183
  end
183
184
  if response.kind_of?(Net::HTTPSuccess)
184
185
  return response
@@ -1,3 +1,3 @@
1
1
  module Typingpool
2
- VERSION = '0.8.10'
2
+ VERSION = '0.8.11'
3
3
  end #Typingpool
@@ -17,7 +17,7 @@ end
17
17
 
18
18
  def test_abort_with_directory_path
19
19
  dir = File.join(fixtures_dir, 'vcr')
20
- assert(File.exists? dir)
20
+ assert(File.exist? dir)
21
21
  assert(File.directory? dir)
22
22
  exception = assert_raises(Typingpool::Error::Shell) do
23
23
  tp_config(dir)
@@ -27,7 +27,7 @@ end
27
27
 
28
28
  def test_abort_with_invalid_path
29
29
  path = '/jksdljs/euwiroeuw'
30
- refute(File.exists? path)
30
+ refute(File.exist? path)
31
31
  exception = assert_raises(Typingpool::Error::Shell) do
32
32
  tp_config(path)
33
33
  end
@@ -35,7 +35,7 @@ def test_abort_with_invalid_path
35
35
  end
36
36
 
37
37
  def test_usage_message
38
- out, err = tp_config('--help')
38
+ out, _ = tp_config('--help')
39
39
  assert(out)
40
40
  assert_match(/\bUSAGE:/, out)
41
41
  end
@@ -46,10 +46,10 @@ def test_new_config_creation
46
46
  :config => File.join(dir, 'config.yml'),
47
47
  :transcript_dir => File.join(dir, 'transcriptionz')
48
48
  }
49
- path.values.each{|path| refute(File.exists? path) }
49
+ path.values.each{|a_path| refute(File.exist? a_path) }
50
50
  assert(output = tp_config_with_input([path[:config], '--test'], ['keykey', 'secretsecret', path[:transcript_dir]]))
51
51
  assert_match(/wrote config to/i, output[:err])
52
- path.values.each{|path| assert(File.exists? path) }
52
+ path.values.each{|a_path| assert(File.exist? a_path) }
53
53
  assert(File.file? path[:config] )
54
54
  assert(File.directory? path[:transcript_dir] )
55
55
  assert(config = Typingpool::Config.file(path[:config]))
@@ -68,14 +68,14 @@ def test_config_editing
68
68
  :fixture => File.join(fixtures_dir, 'config-1'),
69
69
  :transcript_dir => File.join(dir, 'transcriptionz')
70
70
  }
71
- assert(File.exists? path[:fixture])
72
- refute(File.exists? path[:config])
71
+ assert(File.exist? path[:fixture])
72
+ refute(File.exist? path[:config])
73
73
  FileUtils.cp(path[:fixture], path[:config])
74
- assert(File.exists? path[:config])
74
+ assert(File.exist? path[:config])
75
75
  assert(original_config = Typingpool::Config.file(path[:config]))
76
76
  [:key, :secret, :bucket].each{|param| refute_empty(original_config.amazon.send(param).to_s) }
77
77
  [:transcripts, :templates, :cache].each{|param| refute_empty(original_config.send(param).to_s) }
78
- assert(output = tp_config_with_input([path[:config], '--test'], ['keykey', 'secretsecret', path[:transcript_dir]]))
78
+ assert(tp_config_with_input([path[:config], '--test'], ['keykey', 'secretsecret', path[:transcript_dir]]))
79
79
  assert(edited_config = Typingpool::Config.file(path[:config]))
80
80
  [:key, :secret].each{|param| refute_equal(original_config.amazon.send(param), edited_config.amazon.send(param)) }
81
81
  assert_equal(original_config.amazon.bucket, edited_config.amazon.bucket)
@@ -94,10 +94,10 @@ def test_skips_bucket_when_sftp_params_exist
94
94
  :fixture => File.join(fixtures_dir, 'config-2'),
95
95
  :transcript_dir => File.join(dir, 'transcriptionz')
96
96
  }
97
- assert(File.exists? path[:fixture])
98
- refute(File.exists? path[:config])
97
+ assert(File.exist? path[:fixture])
98
+ refute(File.exist? path[:config])
99
99
  FileUtils.cp(path[:fixture], path[:config])
100
- assert(File.exists? path[:config])
100
+ assert(File.exist? path[:config])
101
101
  assert(original_config = Typingpool::Config.file(path[:config]))
102
102
  assert_empty(original_config.amazon.bucket.to_s)
103
103
  assert(output = tp_config_with_input([path[:config], '--test'], ['keykey', 'secretsecret', path[:transcript_dir]]))
@@ -24,10 +24,26 @@ class TestTpMake < Typingpool::Test::Script
24
24
  assert_tp_make_abort_match([], /\bUSAGE:/)
25
25
  end
26
26
 
27
+ def test_abort_with_sftp_http_url
28
+ with_temp_transcripts_dir do |dir|
29
+ config = Typingpool::Config.file(config_path(dir))
30
+ config.to_hash['sftp'] = {
31
+ 'user' => 'test',
32
+ 'host' => 'example.com',
33
+ 'url' => 'http://example.com/foobar'
34
+ }
35
+ write_config(config, dir)
36
+ exception = assert_raises(Typingpool::Error::Shell) do
37
+ call_tp_make('--file', audio_files[0], '--title', 'Foo', '--config', config_path(dir), '--testnoupload')
38
+ end
39
+ assert_match(/must begin with 'https'/i, exception.message)
40
+ end #with_temp_transcripts_dir do...
41
+ end
42
+
27
43
  def assert_tp_make_abort_match(args, regex)
28
44
  args.push('--testnoupload')
29
- assert_script_abort_match(args, regex) do |args|
30
- call_tp_make(*args)
45
+ assert_script_abort_match(args, regex) do |new_args|
46
+ call_tp_make(*new_args)
31
47
  end
32
48
  end
33
49
 
@@ -90,7 +106,7 @@ class TestTpMake < Typingpool::Test::Script
90
106
  assert_all_assets_have_upload_status(project.local.file('data', 'assignment.csv').as(:csv), 'audio', 'no')
91
107
  end #with_temp_transcripts_dir do...
92
108
  end
93
-
109
+
94
110
  def test_tp_make_s3
95
111
  with_temp_transcripts_dir do |dir|
96
112
  skip_if_no_s3_credentials('tp-make S3 integration test', config)
@@ -119,9 +135,9 @@ class TestTpMake < Typingpool::Test::Script
119
135
  end
120
136
  assert(project = transcripts_dir_project(dir))
121
137
  project_dir = project.local.path
122
- assert(File.exists? project_dir)
138
+ assert(File.exist? project_dir)
123
139
  assert(File.directory? project_dir)
124
- assert(File.exists? File.join(project_dir, 'data', 'assignment.csv'))
140
+ assert(File.exist? File.join(project_dir, 'data', 'assignment.csv'))
125
141
  originals_dir = File.join(project_dir, 'audio', 'originals')
126
142
  refute_empty(Dir.entries(originals_dir).reject{|entry| entry.match(/^\./) }.map{|entry| File.join(originals_dir, entry) }.select{|path| File.file? path })
127
143
  assert(assignment_csv = project.local.file('data', 'assignment.csv').as(:csv))
@@ -156,20 +172,20 @@ class TestTpMake < Typingpool::Test::Script
156
172
  assert(project = transcripts_dir_project(dir))
157
173
  check_project_files(project)
158
174
  assert(merged_audio_file = project.local.subdir('audio','originals').files.detect{|filer| filer.path.match(/.\.all\../)})
159
- assert(File.exists? merged_audio_file)
175
+ assert(File.exist? merged_audio_file)
160
176
  actually_ordered_paths = originals_from_merged_audio_file(merged_audio_file)
161
177
  assert_equal(correctly_ordered_paths.map{|path| File.basename(path) }, actually_ordered_paths.map{|path| File.basename(path) })
162
178
  end #with_temp_transcripts_dir
163
179
  end
164
180
 
165
181
  def originals_from_merged_audio_file(path)
166
- out, err, status = Open3.capture3('mp3splt', '-l', path)
182
+ out, _, _ = Open3.capture3('mp3splt', '-l', path)
167
183
  refute_nil(out)
168
184
  refute_empty(out)
169
185
  paths = out.scan(/^\/.+\.mp3$/i)
170
186
  refute_empty(paths)
171
187
  assert(paths.count > 1)
172
- paths.each{|path| assert(File.exists? path) }
188
+ paths.each{|a_path| assert(File.exist? a_path) }
173
189
  paths
174
190
  end
175
191
 
@@ -32,9 +32,26 @@ class TestTpAssign < Typingpool::Test::Script
32
32
  assert_tp_assign_abort_match([project_default[:title], assign_default[:template], '--reward', 'foo'], /sense of --reward/i)
33
33
  end
34
34
 
35
+
36
+ def test_abort_with_sftp_http_url
37
+ with_temp_readymade_project do |dir|
38
+ config = Typingpool::Config.file(config_path(dir))
39
+ config.to_hash['sftp'] = {
40
+ 'user' => 'test',
41
+ 'host' => 'example.com',
42
+ 'url' => 'http://example.com/foobar'
43
+ }
44
+ write_config(config, dir)
45
+ exception = assert_raises(Typingpool::Error::Shell) do
46
+ call_tp_assign(project_default[:title], assign_default[:template], '--config', config_path(dir))
47
+ end
48
+ assert_match(/must begin with 'https'/i, exception.message)
49
+ end #with_temp_readymade_project do |dir|
50
+ end
51
+
35
52
  def assert_tp_assign_abort_match(args, regex)
36
- assert_script_abort_match(args, regex) do |args|
37
- call_tp_assign(*args)
53
+ assert_script_abort_match(args, regex) do |new_args|
54
+ call_tp_assign(*new_args)
38
55
  end
39
56
  end
40
57
 
@@ -45,7 +62,6 @@ class TestTpAssign < Typingpool::Test::Script
45
62
  project = transcripts_dir_project(dir)
46
63
  vcr_names = ['tp_assign_1', 'tp_assign_2']
47
64
  copy_tp_assign_fixtures(dir, vcr_names[0])
48
- assign_time = (Typingpool::Test.record || Typingpool::Test.live) ? Time.now : project_time(project)
49
65
  config = Typingpool::Config.file(config_path(dir))
50
66
  Typingpool::Amazon.setup(:sandbox => true, :config => Typingpool::Config.file(config_path(dir)))
51
67
  with_vcr(vcr_names[1], config, {
@@ -53,6 +69,7 @@ class TestTpAssign < Typingpool::Test::Script
53
69
  :match_requests_on => [:method, Typingpool::App.vcr_core_host_matcher]
54
70
  }) do
55
71
  begin
72
+ assign_time = (Typingpool::Test.record || Typingpool::Test.live) ? Time.now : project_time(project)
56
73
  tp_assign_with_vcr(dir, vcr_names[0])
57
74
  results = nil
58
75
  refute_empty(results = Typingpool::Amazon::HIT.all_for_project(project.local.id))
@@ -60,7 +77,7 @@ class TestTpAssign < Typingpool::Test::Script
60
77
  assert_equal(Typingpool::Utility.timespec_to_seconds(assign_default[:deadline]), results[0].full.assignments_duration.to_i)
61
78
  #These numbers will be apart due to clock differences and
62
79
  #timing vagaries of the assignment.
63
- assert_in_delta((assign_time + Typingpool::Utility.timespec_to_seconds(assign_default[:lifetime])).to_f, results[0].full.expires_at.to_f, 60) if Typingpool::Test.live
80
+ assert_in_delta((assign_time + Typingpool::Utility.timespec_to_seconds(assign_default[:lifetime])).to_f, results[0].full.expires_at.to_f, 360) if Typingpool::Test.live
64
81
  keywords = results[0].at_amazon.keywords
65
82
  assign_default[:keyword].each{|keyword| assert_includes(keywords, keyword)}
66
83
  sandbox_csv = project.local.file('data', 'sandbox-assignment.csv').as(:csv)
@@ -68,10 +85,10 @@ class TestTpAssign < Typingpool::Test::Script
68
85
  assert(assignment_html = fetch_url(assignment_urls.first).body)
69
86
  assert_match(/\b22[\s-]+second\b/, assignment_html)
70
87
  assert_all_assets_have_upload_status(sandbox_csv, 'assignment', 'yes')
71
- ensure
72
- tp_finish(dir) if (Typingpool::Test.record || Typingpool::Test.live)
73
- end #begin
74
- assert_empty(Typingpool::Amazon::HIT.all_for_project(project.local.id))
88
+ ensure
89
+ tp_finish(dir) if (Typingpool::Test.record || Typingpool::Test.live)
90
+ end #begin
91
+ assert_empty(Typingpool::Amazon::HIT.all_for_project(project.local.id))
75
92
  end #with_vcr do...
76
93
  end #with_temp_readymade_project do...
77
94
  end
@@ -114,7 +131,7 @@ class TestTpAssign < Typingpool::Test::Script
114
131
  csv = project.local.file('data', 'assignment.csv').as(:csv)
115
132
  csv.each!{|a| a['audio_uploaded'] = 'yes'}
116
133
  bad_config_path = setup_s3_config_with_bad_password(dir)
117
- get_assignment_urls = lambda{|csv| csv.map{|assignment| assignment['assignment_url'] }.select{|url| url } }
134
+ get_assignment_urls = lambda{|assignments| assignments.map{|assignment| assignment['assignment_url'] }.select{|url| url } }
118
135
  assert_empty(get_assignment_urls.call(csv))
119
136
  begin
120
137
  exception = assert_raises(Typingpool::Error::Shell) do
@@ -178,16 +195,14 @@ class TestTpAssign < Typingpool::Test::Script
178
195
  :match_requests_on => [:method, Typingpool::App.vcr_core_host_matcher]
179
196
  }) do
180
197
  begin
181
- out, err = tp_assign_with_vcr(dir, vcr_names[0])
182
- assert_match(/would cost \$((0\.40)||(0\.47))\./, err)
198
+ _, err = tp_assign_with_vcr(dir, vcr_names[0])
199
+ assert_match(/would cost \$((0\.44)||(0\.51))\./, err)
183
200
  refute_empty(results = Typingpool::Amazon::HIT.all_for_project(project.local.id))
184
201
  assert_equal('0.06', results.first.at_amazon.reward_amount.to_s)
185
- ensure
186
- tp_finish(dir) if (Typingpool::Test.record || Typingpool::Test.live)
187
- end #begin
188
- end #with_temp_readymade_project do...
189
- end #with_vcr...
190
- end
191
-
192
-
202
+ ensure
203
+ tp_finish(dir) if (Typingpool::Test.record || Typingpool::Test.live)
204
+ end #begin
205
+ end #with_temp_readymade_project do...
206
+ end #with_vcr...
207
+ end
193
208
  end #TestTpAssign
@@ -14,7 +14,7 @@ class TestTpReview < Typingpool::Test::Script
14
14
  skip_if_no_amazon_credentials('tp-review integration test')
15
15
  copy_fixtures_to_transcripts_dir(dir, 'tp_review_')
16
16
  project = transcripts_dir_project(dir)
17
- assert(File.exists? File.join(project.local, 'data','sandbox-assignment.csv'))
17
+ assert(File.exist? File.join(project.local, 'data','sandbox-assignment.csv'))
18
18
  assert_equal(7, 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
@@ -60,15 +60,15 @@ class TestTpFinish < Typingpool::Test::Script
60
60
  end
61
61
 
62
62
  def tp_finish_with_vcr(*args)
63
- script_with_vcr(*args){|args| tp_finish(*args) }
63
+ script_with_vcr(*args){|new_args| tp_finish(*new_args) }
64
64
  end
65
65
 
66
66
  def tp_finish_outside_sandbox_with_vcr(*args)
67
- script_with_vcr(*args){|args| tp_finish_outside_sandbox(*args) }
67
+ script_with_vcr(*args){|new_args| tp_finish_outside_sandbox(*new_args) }
68
68
  end
69
69
 
70
70
  def tp_finish_inside_sandbox_with_vcr(*args)
71
- script_with_vcr(*args){|args| tp_finish_inside_sandbox(*args) }
71
+ script_with_vcr(*args){|new_args| tp_finish_inside_sandbox(*new_args) }
72
72
  end
73
73
 
74
74
  def test_tp_finish_on_amazon_hits
@@ -111,7 +111,7 @@ class TestTpFinish < Typingpool::Test::Script
111
111
  end #begin
112
112
  end #results.each...
113
113
  end #with_vcr do...
114
- refute(File.exists? sandbox_csv)
114
+ refute(File.exist? sandbox_csv)
115
115
  assert_all_assets_have_upload_status(csv, 'audio', 'no')
116
116
  end #with_temp_readymade_project do...
117
117
  end
@@ -163,7 +163,7 @@ class TestTpFinish < Typingpool::Test::Script
163
163
  config.amazon.bucket = new_bucket
164
164
  bad_config_path = setup_s3_config(dir, config, '.config_s3_bad')
165
165
  exception = assert_raises(Typingpool::Error::Shell) do
166
- tp_finish_outside_sandbox(dir, bad_config_path)
166
+ tp_finish_outside_sandbox_with_vcr(dir, 'tp_finish_8', bad_config_path)
167
167
  end #assert_raises...
168
168
  assert_match(/\burls don't look right\b/i, exception.message)
169
169
  end #with_temp_readymade_project do...
@@ -112,7 +112,7 @@ class TestAmazon < Typingpool::Test
112
112
  if Typingpool::Test.record
113
113
  File.write(time_path, Time.now.to_i.to_s)
114
114
  elsif not(Typingpool::Test.live)
115
- File.exists? time_path or raise Typingpool::Error, "No time file at '#{time_path}'"
115
+ File.exist? time_path or raise Typingpool::Error, "No time file at '#{time_path}'"
116
116
  Timecop.travel(Time.at(File.read(time_path).to_i))
117
117
  end
118
118
  end
@@ -153,13 +153,21 @@ class TestAmazon < Typingpool::Test
153
153
  dummy_project = Typingpool::Project.new('dummy', config)
154
154
  url = dummy_project.remote.file_to_url(Typingpool::Project::Remote::S3.random_bucket_name(16,'dummy-missing-file-'))
155
155
  refute(working_url? url) if (Typingpool::Test.live || Typingpool::Test.record)
156
- with_dummy_typingpool_hit_or_skip('test_handles_hits_with_broken_external_question', url) do |hit, config|
156
+ with_dummy_typingpool_hit_or_skip('test_handles_hits_with_broken_external_question', url) do |hit, dummy_config|
157
157
  assert_equal(hit.full.external_question_url, url) if (Typingpool::Test.live || Typingpool::Test.record)
158
158
  refute(hit.full.external_question)
159
159
  refute(hit.full.external_question_param(hit.class.url_at))
160
160
  end #with_dummy....
161
161
  end
162
162
 
163
+
164
+ def test_calculates_hit_commission
165
+ assert_equal(0.072, Typingpool::Amazon::HIT.reward_to_total_cost(0.06))
166
+ assert_equal(0.02, Typingpool::Amazon::HIT.reward_to_total_cost(0.01))
167
+ assert_equal(1.212, Typingpool::Amazon::HIT.reward_to_total_cost(1.01))
168
+ assert_equal(1.2, Typingpool::Amazon::HIT.reward_to_total_cost(1))
169
+ end
170
+
163
171
  #Lacks test for HIT::Assignment - needs VCR fixture (TODO)
164
172
 
165
173
  def question_html
@@ -183,8 +191,8 @@ class TestAmazon < Typingpool::Test
183
191
  config = self.config
184
192
  skip_if_no_amazon_credentials(test_handle, config)
185
193
  config.assign.reward = '0.01'
186
- config.assign.deadline = '1m'
187
- config.assign.lifetime = '2m'
194
+ config.assign.deadline = '10m'
195
+ config.assign.lifetime = '20m'
188
196
  cache = Tempfile.new('typingpool_cache')
189
197
  with_vcr(test_handle, config, {
190
198
  :match_requests_on => [:method, Typingpool::App.vcr_core_host_matcher]
@@ -36,8 +36,8 @@ class TestConfig < Typingpool::Test
36
36
  assert_equal('ryan', config.sftp.user)
37
37
  assert_equal('public_html/transfer/', config.sftp['path'])
38
38
  assert_equal('public_html/transfer', config.sftp.path)
39
- assert_equal('http://example.com/mturk/', config.sftp['url'])
40
- assert_equal('http://example.com/mturk', config.sftp.url)
39
+ assert_equal('https://example.com/mturk/', config.sftp['url'])
40
+ assert_equal('https://example.com/mturk', config.sftp.url)
41
41
  end
42
42
 
43
43
  def test_config_screwy_file
@@ -28,7 +28,7 @@ class TestFiler < Typingpool::Test
28
28
  assert(filer.write(data))
29
29
  assert_equal(data, filer.read)
30
30
  assert(path = filer.mv!(File.join(dir, 'filer-temp-2')))
31
- assert(File.exists? filer.path)
31
+ assert(File.exist? filer.path)
32
32
  assert_equal('filer-temp-2', File.basename(filer.path))
33
33
  end #in_temp_dir
34
34
  end
@@ -110,7 +110,7 @@ class TestFiler < Typingpool::Test
110
110
  assert(chunks = mp3.split('0.25', 'filer-temp', Typingpool::Filer::Dir.new(dir)))
111
111
  assert(not(chunks.to_a.empty?))
112
112
  assert_equal(3, chunks.count)
113
- chunks.each{|chunk| assert(File.exists? chunk) }
113
+ chunks.each{|chunk| assert(File.exist? chunk) }
114
114
  assert(chunks.first.offset)
115
115
  assert_match(/0\.00\b/, chunks.first.offset)
116
116
  assert_match(/0\.25\b/, chunks.to_a[1].offset)
@@ -149,7 +149,7 @@ class TestFiler < Typingpool::Test
149
149
  dest_filer = Typingpool::Filer::Dir.new(dir)
150
150
  assert(filer_conversion = filer_wma.to_mp3(dest_filer))
151
151
  assert_equal(filer_wma.files.count, filer_conversion.files.count)
152
- assert_equal(filer_wma.files.count, filer_conversion.select{|file| File.exists? file }.count)
152
+ assert_equal(filer_wma.files.count, filer_conversion.select{|file| File.exist? file }.count)
153
153
  assert_equal(filer_wma.files.count, filer_conversion.select{|file| file.mp3? }.count)
154
154
  assert_equal(filer_conversion.files.count, dest_filer.files.count)
155
155
  temp_path = File.join(dir, 'temp.mp3')
@@ -165,39 +165,39 @@ class TestFiler < Typingpool::Test
165
165
  assert(dir = Typingpool::Filer::Dir.new(fixtures_dir))
166
166
  assert_equal(fixtures_dir, dir.path)
167
167
  dir2_path = File.join(fixtures_dir, 'doesntexist')
168
- assert(not(File.exists? dir2_path))
168
+ assert(not(File.exist? dir2_path))
169
169
  assert(dir2 = Typingpool::Filer::Dir.new(dir2_path))
170
- in_temp_dir do |dir|
171
- dir3_path = File.join(dir, 'filer-dir-temp')
172
- assert(not(File.exists? dir3_path))
170
+ in_temp_dir do |temp_dir|
171
+ dir3_path = File.join(temp_dir, 'filer-dir-temp')
172
+ assert(not(File.exist? dir3_path))
173
173
  assert(dir3 = Typingpool::Filer::Dir.create(dir3_path))
174
- assert(File.exists? dir3_path)
174
+ assert(File.exist? dir3_path)
175
175
  assert_instance_of(Typingpool::Filer::Dir, dir3)
176
176
  assert_nil(dir2 = Typingpool::Filer::Dir.named(File.basename(dir2_path), File.dirname(dir2_path)))
177
177
  assert(dir3 = Typingpool::Filer::Dir.named(File.basename(dir3_path), File.dirname(dir3_path)))
178
178
  assert_instance_of(Typingpool::Filer::Dir, dir3)
179
179
  assert_equal(dir3_path, dir3.to_s)
180
180
  assert_equal(dir3_path, dir3.to_str)
181
- assert(filer = dir3.file('doesntexist'))
181
+ assert(dir3.file('doesntexist'))
182
182
  end #in_temp_dir
183
183
  assert(filer = dir.file('vcr', 'tp-collect-1.yml'))
184
- assert(File.exists? filer.path)
184
+ assert(File.exist? filer.path)
185
185
  assert_instance_of(Typingpool::Filer, filer)
186
186
  assert(csv = dir.file('tp_collect_sandbox-assignment.csv').as(:csv))
187
- assert(File.exists? csv.path)
187
+ assert(File.exist? csv.path)
188
188
  assert_instance_of(Typingpool::Filer::CSV, csv)
189
189
  dir4 = Typingpool::Filer::Dir.new(audio_dir)
190
190
  assert(audio = dir4.file('mp3', 'interview.1.mp3').as(:audio))
191
- assert(File.exists? audio.path)
191
+ assert(File.exist? audio.path)
192
192
  assert_instance_of(Typingpool::Filer::Audio, audio)
193
193
  assert(filers = dir.files)
194
194
  assert(not(filers.empty?))
195
195
  assert_kind_of(Typingpool::Filer, filers.first)
196
- assert(File.exists? filers.first.path)
196
+ assert(File.exist? filers.first.path)
197
197
  dir_files = Dir.entries(dir.path).map{|entry| File.join(dir.path, entry)}.select{|path| File.file?(path) }.reject{|path| File.basename(path).match(/^\./) }
198
198
  assert_equal(dir_files.count, filers.count)
199
199
  assert(dir5 = dir.subdir('vcr'))
200
- assert(File.exists? dir5.path)
200
+ assert(File.exist? dir5.path)
201
201
  assert_instance_of(Typingpool::Filer::Dir, dir5)
202
202
  end
203
203
  end #TestFiler
@@ -5,7 +5,7 @@ $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 'uri'
8
+ require 'erb'
9
9
 
10
10
  class TestProject < Typingpool::Test
11
11
  def test_project_base_new
@@ -131,7 +131,7 @@ class TestProject < Typingpool::Test
131
131
  assert(result = project.create_assignment_csv(:path => relative_path, :urls => dummy_remote_files, :unusual => project_default[:unusual], :voices => voices, ))
132
132
  assert_includes(result, dir)
133
133
  csv_file = File.join(dir, project_default[:title], *relative_path)
134
- assert(File.exists? csv_file)
134
+ assert(File.exist? csv_file)
135
135
  assert(File.file? csv_file)
136
136
  assert(parsed = CSV.read(csv_file))
137
137
  assignment_headers = parsed.shift
@@ -150,7 +150,7 @@ class TestProject < Typingpool::Test
150
150
  end
151
151
 
152
152
  def test_local_basename_from_url
153
- url = ['http://example.com/dir/', URI.escape('Example Title With Spaces & Ampersand.html')].join
153
+ url = ['http://example.com/dir/', ERB::Util.url_encode('Example Title With Spaces & Ampersand.html')].join
154
154
  assert_match(/%20/, url)
155
155
  #assert(basename = Typingpool::Project.local_basename_from_url.u)
156
156
  end
@@ -8,16 +8,16 @@ require 'typingpool/test'
8
8
 
9
9
  class TestProjectLocal < Typingpool::Test
10
10
  def test_project_local_ours
11
- assert(File.exists?(non_project_dir))
11
+ assert(File.exist?(non_project_dir))
12
12
  assert(File.directory?(non_project_dir))
13
13
  refute(Typingpool::Project::Local.ours?(Typingpool::Filer::Dir.new(non_project_dir)))
14
- assert(File.exists?(project_template_dir))
14
+ assert(File.exist?(project_template_dir))
15
15
  assert(Typingpool::Project::Local.ours?(Typingpool::Filer::Dir.new(project_template_dir)))
16
16
  end
17
17
 
18
18
  def test_project_local_named
19
19
  assert_nil(Typingpool::Project::Local.named(project_default[:title], fixtures_dir))
20
- assert_kind_of(Typingpool::Project::Local, local = Typingpool::Project::Local.named('project', project_template_dir_parent))
20
+ assert_kind_of(Typingpool::Project::Local, Typingpool::Project::Local.named('project', project_template_dir_parent))
21
21
  end
22
22
 
23
23
  def test_project_local_valid_name
@@ -28,7 +28,7 @@ class TestProjectLocal < Typingpool::Test
28
28
  def test_project_local_create
29
29
  in_temp_dir do |dir|
30
30
  assert(local = create_project_local(dir))
31
- assert(File.exists?(local.path))
31
+ assert(File.exist?(local.path))
32
32
  assert(File.directory?(local.path))
33
33
  assert_kind_of(Typingpool::Project::Local, local)
34
34
  refute_nil(local.id)