typingpool 0.8.10 → 0.8.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/bin/tp-assign +9 -5
- data/bin/tp-config +6 -6
- data/bin/tp-finish +1 -1
- data/bin/tp-make +9 -3
- data/lib/typingpool/amazon/hit/full/fromsearchhits.rb +2 -1
- data/lib/typingpool/amazon/hit/full.rb +3 -2
- data/lib/typingpool/amazon/hit.rb +19 -1
- data/lib/typingpool/amazon.rb +1 -2
- data/lib/typingpool/app/cli.rb +3 -3
- data/lib/typingpool/app/friendlyexceptions.rb +1 -1
- data/lib/typingpool/app.rb +24 -6
- data/lib/typingpool/config/root.rb +1 -0
- data/lib/typingpool/config.rb +6 -5
- data/lib/typingpool/filer/audio.rb +2 -2
- data/lib/typingpool/filer/dir.rb +1 -1
- data/lib/typingpool/filer.rb +1 -1
- data/lib/typingpool/project/local.rb +3 -3
- data/lib/typingpool/project/remote.rb +4 -3
- data/lib/typingpool/project.rb +2 -1
- data/lib/typingpool/template.rb +2 -2
- data/lib/typingpool/test/fixtures/amazon-question-url.txt +1 -1
- data/lib/typingpool/test/fixtures/config-2 +1 -1
- data/lib/typingpool/test/fixtures/test_amazon_hit_full_time.txt +1 -1
- data/lib/typingpool/test/fixtures/tp_assign_1_assignment.csv +6 -6
- data/lib/typingpool/test/fixtures/tp_assign_1_id.txt +1 -1
- data/lib/typingpool/test/fixtures/tp_assign_1_time.txt +1 -1
- data/lib/typingpool/test/fixtures/tp_assign_3_assignment.csv +6 -6
- data/lib/typingpool/test/fixtures/tp_assign_3_id.txt +1 -1
- data/lib/typingpool/test/fixtures/tp_assign_3_time.txt +1 -1
- data/lib/typingpool/test/fixtures/tp_assign_4_assignment.csv +6 -6
- data/lib/typingpool/test/fixtures/tp_assign_4_id.txt +1 -1
- data/lib/typingpool/test/fixtures/tp_assign_4_time.txt +1 -1
- data/lib/typingpool/test/fixtures/tp_assign_6_assignment.csv +6 -6
- data/lib/typingpool/test/fixtures/tp_assign_6_id.txt +1 -1
- data/lib/typingpool/test/fixtures/tp_assign_6_time.txt +1 -1
- data/lib/typingpool/test/fixtures/tp_finish_3_assignment.csv +6 -6
- data/lib/typingpool/test/fixtures/tp_finish_3_id.txt +1 -1
- data/lib/typingpool/test/fixtures/tp_finish_3_time.txt +1 -1
- data/lib/typingpool/test/fixtures/vcr/test_amazon_hit_base.yml +35 -29
- data/lib/typingpool/test/fixtures/vcr/test_amazon_hit_create.yml +52 -44
- data/lib/typingpool/test/fixtures/vcr/test_amazon_hit_full.yml +36 -30
- data/lib/typingpool/test/fixtures/vcr/test_amazon_hit_full_fromsearchhits.yml +69 -57
- data/lib/typingpool/test/fixtures/vcr/test_amazon_hit_retrievers.yml +94 -76
- data/lib/typingpool/test/fixtures/vcr/test_handles_hits_with_broken_external_question.yml +51 -53
- data/lib/typingpool/test/fixtures/vcr/tp_assign_1.yml +628 -628
- data/lib/typingpool/test/fixtures/vcr/tp_assign_2.yml +265 -3044
- data/lib/typingpool/test/fixtures/vcr/tp_assign_3.yml +629 -629
- data/lib/typingpool/test/fixtures/vcr/tp_assign_4.yml +65 -62
- data/lib/typingpool/test/fixtures/vcr/tp_assign_5.yml +623 -623
- data/lib/typingpool/test/fixtures/vcr/tp_assign_6.yml +592 -588
- data/lib/typingpool/test/fixtures/vcr/tp_assign_7.yml +195 -195
- data/lib/typingpool/test/fixtures/vcr/tp_finish_1.yml +91 -91
- data/lib/typingpool/test/fixtures/vcr/tp_finish_2.yml +76 -3989
- data/lib/typingpool/test/fixtures/vcr/tp_finish_3.yml +713 -695
- data/lib/typingpool/test/fixtures/vcr/tp_finish_4.yml +527 -3276
- data/lib/typingpool/test/fixtures/vcr/tp_finish_5.yml +338 -5602
- data/lib/typingpool/test/fixtures/vcr/tp_finish_6.yml +91 -91
- data/lib/typingpool/test/fixtures/vcr/tp_finish_7.yml +86 -3999
- data/lib/typingpool/test/fixtures/vcr/tp_finish_8.yml +51 -0
- data/lib/typingpool/test/script.rb +4 -6
- data/lib/typingpool/test.rb +3 -2
- data/lib/typingpool/utility.rb +6 -5
- data/lib/typingpool/version.rb +1 -1
- data/test/test_integration_script_1_tp_config.rb +12 -12
- data/test/test_integration_script_2_tp_make.rb +24 -8
- data/test/test_integration_script_3_tp_assign.rb +34 -19
- data/test/test_integration_script_4_tp_review.rb +1 -1
- data/test/test_integration_script_6_tp_finish.rb +5 -5
- data/test/test_unit_amazon.rb +12 -4
- data/test/test_unit_config.rb +2 -2
- data/test/test_unit_filer.rb +14 -14
- data/test/test_unit_project.rb +3 -3
- data/test/test_unit_project_local.rb +4 -4
- data/test/test_unit_project_remote.rb +1 -1
- data/test/test_unit_test.rb +2 -2
- data/typingpool.gemspec +3 -2
- 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.
|
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.
|
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.
|
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.
|
335
|
+
assert(File.exist?(transcript_path))
|
338
336
|
assert(not((transcript = IO.read(transcript_path)).empty?))
|
339
337
|
transcript
|
340
338
|
end
|
data/lib/typingpool/test.rb
CHANGED
@@ -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.
|
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.
|
58
|
+
if File.exist?(File.expand_path(Config.default_file))
|
58
59
|
Config.file
|
59
60
|
else
|
60
61
|
Config.from_bundled_template
|
data/lib/typingpool/utility.rb
CHANGED
@@ -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 |
|
162
|
-
http.request_head(
|
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 |
|
181
|
-
http.request_get(
|
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
|
data/lib/typingpool/version.rb
CHANGED
@@ -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.
|
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.
|
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,
|
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{|
|
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{|
|
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.
|
72
|
-
refute(File.
|
71
|
+
assert(File.exist? path[:fixture])
|
72
|
+
refute(File.exist? path[:config])
|
73
73
|
FileUtils.cp(path[:fixture], path[:config])
|
74
|
-
assert(File.
|
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(
|
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.
|
98
|
-
refute(File.
|
97
|
+
assert(File.exist? path[:fixture])
|
98
|
+
refute(File.exist? path[:config])
|
99
99
|
FileUtils.cp(path[:fixture], path[:config])
|
100
|
-
assert(File.
|
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 |
|
30
|
-
call_tp_make(*
|
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.
|
138
|
+
assert(File.exist? project_dir)
|
123
139
|
assert(File.directory? project_dir)
|
124
|
-
assert(File.
|
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.
|
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,
|
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{|
|
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 |
|
37
|
-
call_tp_assign(*
|
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,
|
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
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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{|
|
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
|
-
|
182
|
-
assert_match(/would cost \$((0\.
|
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
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
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.
|
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){|
|
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){|
|
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){|
|
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.
|
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
|
-
|
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...
|
data/test/test_unit_amazon.rb
CHANGED
@@ -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.
|
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,
|
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 = '
|
187
|
-
config.assign.lifetime = '
|
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]
|
data/test/test_unit_config.rb
CHANGED
@@ -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('
|
40
|
-
assert_equal('
|
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
|
data/test/test_unit_filer.rb
CHANGED
@@ -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.
|
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.
|
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.
|
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.
|
168
|
+
assert(not(File.exist? dir2_path))
|
169
169
|
assert(dir2 = Typingpool::Filer::Dir.new(dir2_path))
|
170
|
-
in_temp_dir do |
|
171
|
-
dir3_path = File.join(
|
172
|
-
assert(not(File.
|
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.
|
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(
|
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.
|
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.
|
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.
|
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.
|
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.
|
200
|
+
assert(File.exist? dir5.path)
|
201
201
|
assert_instance_of(Typingpool::Filer::Dir, dir5)
|
202
202
|
end
|
203
203
|
end #TestFiler
|
data/test/test_unit_project.rb
CHANGED
@@ -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 '
|
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.
|
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/',
|
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.
|
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.
|
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,
|
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.
|
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)
|