$: << File.dirname(__FILE__) + "/../lib" require 'crowdflower' require 'json' CONFIG = YAML::load(File.read("config/account_info.yml")) API_KEY = CONFIG["API_KEY"] PROJECT_NUM = CONFIG["PROJECT_NUM"] DOMAIN_BASE = "https://api.crowdflower.com" || "https://api.localdev.crowdflower.com:8443" CrowdFlower::Job.connect! API_KEY, DOMAIN_BASE unless API_KEY && API_KEY.size > 3 puts < 'Job_2: CrowdShopping', :project_number => PROJECT_NUM, :instructions => '

There are six questions to this task. In this order, the questions ask if you were able to find a pair of Lita shoes for sale in red glitter, gold glitter, multi glitter, silver glitter, black glitter, or other color of glitter.

There is a photo of the shoe in correlating color as the question right below the question. It will give you a better idea of what to look for.

', :cml => '

Example Photo:



'}) ################################################# # ADD/ UPDATE/ REMOVE TAGS ################################################# say "Checking if tags exist." assert job_2.tags.empty? say "Adding 'shoes' and 'glitter' to tags." job_2.add_tags ["shoes", "glitter"] assert job_2.tags.map{|t| t["name"]}.sort == ["glitter", "shoes"] say "Removing 'shoes' tag." job_2.remove_tags ["shoes"] assert job_2.tags.map{|t| t["name"]} == ["glitter"] say "Updating tags to 'fashion' 'fun' and 'glitter'." job_2.update_tags ["fashion", "fun", "glitter"] assert job_2.tags.map{|t| t["name"]} == ["fashion", "fun", "glitter"] ################################################# # CHECK JOB_2 CHANNELS ################################################# say "Checking that channels are turned on." assert !job_2.channels["enabled_channels"].empty? p "job_2 enabled_channels: #{job_2.channels["enabled_channels"]}" ################################################# # ORDER JOB ################################################# say "Ordering (launching) job_2 with 12 units." order = CrowdFlower::Order.new(job_2) order.debit(12, ["4x4bux_com", "bitcoinget", "cf_internal"]) wait_until { job_2.get["state"].casecmp('running') == 0} # turning channels from on_demand work force adds "on_demand" to enabled_channels assert job_2.channels["enabled_channels"] == ["4x4bux_com", "bitcoinget", "cf_internal", "on_demand"] ################################################# # DISABLE A CHANNEL ################################################# say "Disabling 'bitcoinget' channel." job_2.disable_channel("bitcoinget") assert job_2.channels["enabled_channels"] == ["4x4bux_com", "cf_internal", "on_demand"] ################################################# # UNIT METHODS ################################################# say "Setting up units." unit_1 = job_2.units.all.to_a[0][0] unit_2 = job_2.units.all.to_a[1][0] unit = CrowdFlower::Unit.new(job_2) wait_until { unit.get(unit_1)["state"] == "judgable" } p "unit_1 id: #{unit_1}" wait_until { unit.get(unit_1)["state"] == "judgable" } p "unit_2 id: #{unit_2}" say "Making unit_1 a test question (gold)." unit.make_gold(unit_1) assert unit.get(unit_1)["state"] == "golden" say "Copying unit_2." unit.copy(unit_2, job_2_id, "glitter_color"=>"blue") assert job_2.get["units_count"] == 13 say "Creating a new test question unit." unit.create({"glitter_color"=>"white"}, true) assert job_2.get["units_count"] == 14 assert job_2.get["golds_count"] == 2 say "Canceling unit_2." unit.cancel(unit_2) assert unit.get(unit_2)["state"] == "canceled" ################################################# # PAUSE/ RESUME/ CANCEL JOB ################################################# say "Pausing job_2." job_2.pause assert job_2.get["state"] == "paused" p "job_2 state: #{job_2.get["state"]}" say "Resuming job_2." job_2.resume assert job_2.get["state"] == "running" p "job_2 state: #{job_2.get["state"]}" say "Canceling job_2." job_2.cancel assert job_2.get["state"] == "canceled" p "job_2 state: #{job_2.get["state"]}" say "Deleting job_1." job_1.delete assert job_1.get["state"] == "unordered" ################################################# # JOB LEGEND ################################################# say "Checking job_2 legend." assert !job_2.legend.empty? ################################################# # COPY JOB_2 ################################################# say "Copying job_2." job_3 = job_2.copy(:all_units => true) say "Updating job_3 title." job_3.update(:title => 'Job_3: Copy of Job_2') assert job_3.get["title"] == "Job_3: Copy of Job_2" say "-- Waiting for CrowdFlower to process the data." wait_until { job_3.get["units_count"] == 14 } assert job_3.get["units_count"] == 14 ################################################# # WORKER METHODS ################################################# # Worker tests run against an existing job with an internal CF worker_id number say "Starting Worker tests for job #422830." job = CrowdFlower::Job.new(422830) worker = CrowdFlower::Worker.new(job) worker_id = 23542619 say "Notifying worker." worker.notify(worker_id, "Testing notify method.") say "Bonusing a worker." worker.bonus(worker_id, 1, "Here's a bonus for your awesome work!") say "Flagging worker from one of my jobs." worker.flag(worker_id, "Testing flag method.", :persist => false) say "Flagging worker from all my jobs." worker.flag(worker_id, "Testing flag method across all jobs.", :persist => true) say "Deflagging worker." worker.deflag(worker_id, "Testing deflag method.") ################################################# # JUDGMENT METHODS ################################################# # Judgment tests run against the same job as Worker tests say "Starting Judgment tests for job #422830." judgment = CrowdFlower::Judgment.new(job) unit = CrowdFlower::Unit.new(job) say "Getting all judgments." assert judgment.all.count == job.get["judgments_count"] say "Checking the judgment number to test judgment.get method." assert judgment.get(1243027889)["judgment"] == 1 say "Checking the number of judgments for a unit to see if a unit's judgment info can be returned." assert job.units.judgments(447664267).count == unit.get(447664267)["judgments_count"] ################################################# # DOWNLOAD REPORTS - missing assetions ################################################# # These run against the completed job from readme examples; they print status codes as they go say "Startiing report tests for job #418404." job = CrowdFlower::Job.new(418404) say "Downloading Full CSV" job.download_csv(:full, "full_report.zip") say "Downloading Aggregated CSV" job.download_csv(:aggregated, "agg_report.zip") say "Downloading Source CSV" job.download_csv(:source, "source_report.zip") say "Downloading Test Questions CSV" job.download_csv(:gold_report, "gold_report.zip") say "Downloading Worker CSV" job.download_csv(:workset, "workset_report.zip") say "Downloading JSON" job.download_csv(:json, "json_report.zip") ################################################# # END OF TESTS ################################################# say ">-< Tests complete. >-<"