diff --git a/lib/coursemology/evaluator.rb b/lib/coursemology/evaluator.rb index 58c2984..9ae0ae7 100644 --- a/lib/coursemology/evaluator.rb +++ b/lib/coursemology/evaluator.rb @@ -17,6 +17,7 @@ module Coursemology::Evaluator autoload :Logging autoload :Models autoload :Services + autoload :StringIO # The logger to use for the client. mattr_reader(:logger) { ActiveSupport::Logger.new(STDOUT) } diff --git a/lib/coursemology/evaluator/models/programming_evaluation.rb b/lib/coursemology/evaluator/models/programming_evaluation.rb index df5f117..814b121 100644 --- a/lib/coursemology/evaluator/models/programming_evaluation.rb +++ b/lib/coursemology/evaluator/models/programming_evaluation.rb @@ -30,7 +30,7 @@ def language=(language) def package @package ||= begin body = plain_request('courses/assessment/programming_evaluations/:id/package', id: id) - Package.new(StringIO.new(body)) + Package.new(Coursemology::Evaluator::StringIO.new(body)) end end diff --git a/lib/coursemology/evaluator/string_io.rb b/lib/coursemology/evaluator/string_io.rb new file mode 100644 index 0000000..6661210 --- /dev/null +++ b/lib/coursemology/evaluator/string_io.rb @@ -0,0 +1,13 @@ +# Adapter for StringIO for compatibility with RubyZip. +# +# StringIO does not inherit from IO, so RubyZip does not accept StringIO in place of IO. +class Coursemology::Evaluator::StringIO < ::StringIO + def is_a?(klass) + klass == IO || super + end + + # RubyZip assumes all IO objects respond to path. + def path + self + end +end diff --git a/spec/coursemology/evaluator/cli_spec.rb b/spec/coursemology/evaluator/cli_spec.rb index f1e3f56..881ec92 100644 --- a/spec/coursemology/evaluator/cli_spec.rb +++ b/spec/coursemology/evaluator/cli_spec.rb @@ -46,6 +46,12 @@ subject end end + + it 'evaluates the package' do + VCR.use_cassette('client/pending_evaluation') do + subject + end + end end end diff --git a/spec/fixtures/vcr/cassettes/client/pending_evaluation.yml b/spec/fixtures/vcr/cassettes/client/pending_evaluation.yml new file mode 100644 index 0000000..2fcbe47 --- /dev/null +++ b/spec/fixtures/vcr/cassettes/client/pending_evaluation.yml @@ -0,0 +1,165 @@ +--- +http_interactions: +- request: + method: post + uri: http://localhost:3000/courses/assessment/programming_evaluations/allocate + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - ActiveRestClient/1.2.0 + Connection: + - Keep-Alive + Accept: + - application/hal+json, application/json;q=0.5 + X-User-Email: + - test@example.org + X-User-Token: + - YOUR_TOKEN_HERE + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: + headers: + x-frame-options: + - SAMEORIGIN + x-xss-protection: + - 1; mode=block + x-content-type-options: + - nosniff + content-type: + - application/json; charset=utf-8 + etag: + - W/"ebabb61a52d69a09e40e6cc6b70a3506" + cache-control: + - max-age=0, private, must-revalidate + x-request-id: + - 09c81730-af3d-4626-9c90-a86569eec7f0 + x-runtime: + - '1.151567' + server: + - WEBrick/1.3.1 (Ruby/2.2.4/2015-10-28) + date: + - Wed, 20 Jan 2016 14:15:30 GMT + content-length: + - '113' + connection: + - Keep-Alive + body: + encoding: UTF-8 + string: '[{"id":1,"language":"Coursemology::Polyglot::Language::Python::Python2Point7","memory_limit":32,"time_limit":10}]' + http_version: + recorded_at: Wed, 20 Jan 2016 14:15:31 GMT +- request: + method: get + uri: http://localhost:3000/courses/assessment/programming_evaluations/1/package + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - ActiveRestClient/1.2.0 + Connection: + - Keep-Alive + Accept: + - application/hal+json, application/json;q=0.5 + X-User-Email: + - test@example.org + X-User-Token: + - YOUR_TOKEN_HERE + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 302 + message: + headers: + x-frame-options: + - SAMEORIGIN + x-xss-protection: + - 1; mode=block + x-content-type-options: + - nosniff + location: + - http://localhost:3000/downloads/d20151214-14316-19zacic/programming-import20151214-14316-l6y6yg + content-type: + - text/html; charset=utf-8 + cache-control: + - no-cache + x-request-id: + - b3094756-62c4-4ef2-950f-dd36c84a5286 + x-runtime: + - '0.395076' + server: + - WEBrick/1.3.1 (Ruby/2.2.4/2015-10-28) + date: + - Wed, 20 Jan 2016 14:15:32 GMT + content-length: + - '161' + connection: + - Keep-Alive + body: + encoding: UTF-8 + string:
You are being redirected. + http_version: + recorded_at: Wed, 20 Jan 2016 14:15:32 GMT +- request: + method: get + uri: http://localhost:3000/downloads/d20151214-14316-19zacic/programming-import20151214-14316-l6y6yg + body: + encoding: US-ASCII + string: '' + headers: + User-Agent: + - ActiveRestClient/1.2.0 + Connection: + - Keep-Alive + Accept: + - application/hal+json, application/json;q=0.5 + X-User-Email: + - test@example.org + X-User-Token: + - YOUR_TOKEN_HERE + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: + headers: + last-modified: + - Wed, 20 Jan 2016 09:06:59 GMT + content-type: + - text/plain + content-length: + - '669' + server: + - WEBrick/1.3.1 (Ruby/2.2.4/2015-10-28) + date: + - Wed, 20 Jan 2016 14:15:33 GMT + connection: + - Keep-Alive + body: + encoding: ASCII-8BIT + string: !binary |- + UEsDBBQAAAAIAOKQMkhX5T3waQAAAIIAAAAIAAAATWFrZWZpbGVVjDsKgDAQ + BWsF77CksfLXifjpPIEeQOKiAZMNSRSPb4KFWL0p5o02qBeDTRInMSepxfGy + Q+s8RMh3grQdbnnAhcYKUh2r8pIBKk6rUFvH5mnMajb0KfTgc2Rc7vXvHFr2 + FH6gCNLfegBQSwMEFAAAAAAAs3uIRwAAAAAAAAAAAAAAAAsAAABzdWJtaXNz + aW9uL1BLAwQKAAAAAAC1e4hHAAAAAAAAAAAAAAAAFgAAAHN1Ym1pc3Npb24v + X19pbml0X18ucHlQSwMEFAAAAAAAsHuIRwAAAAAAAAAAAAAAAAYAAAB0ZXN0 + cy9QSwECPwAUAAAACADikDJIV+U98GkAAACCAAAACAAkAAAAAAAAACAAAAAA + AAAATWFrZWZpbGUKACAAAAAAAAEAGAALns/611HRAUNtut/XUdEBQ22639dR + 0QFQSwECPwAUAAAAAACze4hHAAAAAAAAAAAAAAAACwAkAAAAAAAAABAAAACP + AAAAc3VibWlzc2lvbi8KACAAAAAAAAEAGAAg0+MwijHRASDT4zCKMdEBINPj + MIox0QFQSwECPwAKAAAAAAC1e4hHAAAAAAAAAAAAAAAAFgAkAAAAAAAAACAA + AAC4AAAAc3VibWlzc2lvbi9fX2luaXRfXy5weQoAIAAAAAAAAQAYANf2ATSK + MdEB1/YBNIox0QHX9gE0ijHRAVBLAQI/ABQAAAAAALB7iEcAAAAAAAAAAAAA + AAAGACQAAAAAAAAAEAAAAOwAAAB0ZXN0cy8KACAAAAAAAAEAGADwz2UtijHR + AfDPZS2KMdEB8M9lLYox0QFQSwUGAAAAAAQABAB3AQAAEAEAAAAA + http_version: + recorded_at: Wed, 20 Jan 2016 14:15:33 GMT +recorded_with: VCR 3.0.0