OLD | NEW |
(Empty) | |
| 1 >>> import uuid |
| 2 >>> import datetime |
| 3 >>> from _init_environment import MTurkConnection, mturk_host |
| 4 >>> from boto.mturk.question import Question, QuestionContent, AnswerSpecificati
on, FreeTextAnswer, Binary |
| 5 |
| 6 >>> conn = MTurkConnection(host=mturk_host) |
| 7 |
| 8 # create content for a question |
| 9 >>> qn_content = QuestionContent() |
| 10 >>> qn_content.append_field('Title','Boto no hit type question content') |
| 11 >>> qn_content.append_field('Text', 'What is a boto binary hit type?') |
| 12 >>> binary_content = Binary('image', 'jpeg', 'http://www.example.com/test1.jpg',
alt_text='image is missing') |
| 13 >>> qn_content.append(binary_content) |
| 14 |
| 15 # create the question specification |
| 16 >>> qn = Question(identifier=str(uuid.uuid4()), |
| 17 ... content=qn_content, |
| 18 ... answer_spec=AnswerSpecification(FreeTextAnswer())) |
| 19 |
| 20 # now, create the actual HIT for the question without using a HIT type |
| 21 # NOTE - the response_groups are specified to get back additional information fo
r testing |
| 22 >>> keywords=['boto', 'test', 'doctest'] |
| 23 >>> lifetime = datetime.timedelta(minutes=65) |
| 24 >>> create_hit_rs = conn.create_hit(question=qn, |
| 25 ... lifetime=lifetime, |
| 26 ... max_assignments=2, |
| 27 ... title='Boto create_hit title', |
| 28 ... description='Boto create_hit description', |
| 29 ... keywords=keywords, |
| 30 ... reward=0.23, |
| 31 ... duration=60*6, |
| 32 ... approval_delay=60*60, |
| 33 ... annotation='An annotation from boto create_h
it test', |
| 34 ... response_groups=['Minimal', |
| 35 ... 'HITDetail', |
| 36 ... 'HITQuestion', |
| 37 ... 'HITAssignmentSummary',]) |
| 38 |
| 39 # this is a valid request |
| 40 >>> create_hit_rs.status |
| 41 True |
| 42 |
| 43 >>> len(create_hit_rs) |
| 44 1 |
| 45 >>> hit = create_hit_rs[0] |
| 46 |
| 47 # for the requested hit type id |
| 48 # the HIT Type Id is a unicode string |
| 49 >>> hit_type_id = hit.HITTypeId |
| 50 >>> hit_type_id # doctest: +ELLIPSIS |
| 51 u'...' |
| 52 |
| 53 >>> hit.MaxAssignments |
| 54 u'2' |
| 55 |
| 56 >>> hit.AutoApprovalDelayInSeconds |
| 57 u'3600' |
| 58 |
| 59 # expiration should be very close to now + the lifetime |
| 60 >>> expected_datetime = datetime.datetime.utcnow() + lifetime |
| 61 >>> expiration_datetime = datetime.datetime.strptime(hit.Expiration, '%Y-%m-%dT%
H:%M:%SZ') |
| 62 >>> delta = expected_datetime - expiration_datetime |
| 63 >>> abs(delta).seconds < 5 |
| 64 True |
| 65 |
| 66 # duration is as specified for the HIT type |
| 67 >>> hit.AssignmentDurationInSeconds |
| 68 u'360' |
| 69 |
| 70 # the reward has been set correctly (allow for float error here) |
| 71 >>> int(float(hit.Amount) * 100) |
| 72 23 |
| 73 |
| 74 >>> hit.FormattedPrice |
| 75 u'$0.23' |
| 76 |
| 77 # only US currency supported at present |
| 78 >>> hit.CurrencyCode |
| 79 u'USD' |
| 80 |
| 81 # title is the HIT type title |
| 82 >>> hit.Title |
| 83 u'Boto create_hit title' |
| 84 |
| 85 # title is the HIT type description |
| 86 >>> hit.Description |
| 87 u'Boto create_hit description' |
| 88 |
| 89 # annotation is correct |
| 90 >>> hit.RequesterAnnotation |
| 91 u'An annotation from boto create_hit test' |
| 92 |
| 93 >>> hit.HITReviewStatus |
| 94 u'NotReviewed' |
OLD | NEW |