1>>> import uuid 2>>> import datetime 3>>> from _init_environment import MTurkConnection, mturk_host 4>>> from boto.mturk.question import Question, QuestionContent, AnswerSpecification, FreeTextAnswer 5>>> 6>>> conn = MTurkConnection(host=mturk_host) 7>>> keywords=['boto', 'test', 'doctest'] 8>>> hit_type_rs = conn.register_hit_type('Boto Test HIT type', 9... 'HIT Type for testing Boto', 10... 0.12, 11... 60*6, 12... keywords=keywords, 13... approval_delay=60*60) 14 15# this was a valid request 16>>> hit_type_rs.status 17True 18 19# the HIT Type Id is a unicode string 20>>> hit_type_id = hit_type_rs.HITTypeId 21>>> hit_type_id # doctest: +ELLIPSIS 22u'...' 23 24# create content for a question 25>>> qn_content = QuestionContent() 26>>> qn_content.append_field('Title', 'Boto question content create_hit_from_hit_type') 27>>> qn_content.append_field('Text', 'What is a boto create_hit_from_hit_type?') 28 29# create the question specification 30>>> qn = Question(identifier=str(uuid.uuid4()), 31... content=qn_content, 32... answer_spec=AnswerSpecification(FreeTextAnswer())) 33 34# now, create the actual HIT for the question using the HIT type 35# NOTE - the response_groups are specified to get back additional information for testing 36>>> create_hit_rs = conn.create_hit(hit_type=hit_type_rs.HITTypeId, 37... question=qn, 38... lifetime=60*65, 39... max_assignments=2, 40... annotation='An annotation from boto create_hit_from_hit_type test', 41... response_groups=['Minimal', 42... 'HITDetail', 43... 'HITQuestion', 44... 'HITAssignmentSummary',]) 45 46# this is a valid request 47>>> create_hit_rs.status 48True 49 50>>> len(create_hit_rs) 511 52 53>>> hit = create_hit_rs[0] 54 55# for the requested hit type id 56>>> hit.HITTypeId == hit_type_id 57True 58 59# with the correct number of maximum assignments 60>>> hit.MaxAssignments 61u'2' 62 63# and the approval delay 64>>> hit.AutoApprovalDelayInSeconds 65u'3600' 66 67# expiration should be very close to now + the lifetime in seconds 68>>> expected_datetime = datetime.datetime.utcnow() + datetime.timedelta(seconds=3900) 69>>> expiration_datetime = datetime.datetime.strptime(hit.Expiration, '%Y-%m-%dT%H:%M:%SZ') 70>>> delta = expected_datetime - expiration_datetime 71>>> abs(delta).seconds < 5 72True 73 74# duration is as specified for the HIT type 75>>> hit.AssignmentDurationInSeconds 76u'360' 77 78# the reward has been set correctly 79>>> float(hit.Amount) == 0.12 80True 81 82>>> hit.FormattedPrice 83u'$0.12' 84 85# only US currency supported at present 86>>> hit.CurrencyCode 87u'USD' 88 89# title is the HIT type title 90>>> hit.Title 91u'Boto Test HIT type' 92 93# title is the HIT type description 94>>> hit.Description 95u'HIT Type for testing Boto' 96 97# annotation is correct 98>>> hit.RequesterAnnotation 99u'An annotation from boto create_hit_from_hit_type test' 100 101# not reviewed yet 102>>> hit.HITReviewStatus 103u'NotReviewed' 104