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, RegExConstraint |
| 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 no hit type?') |
| 12 |
| 13 # create a free text answer that is not quite so free! |
| 14 >>> constraints = [ |
| 15 ... RegExConstraint( |
| 16 ... "^[12][0-9]{3}-[01]?\d-[0-3]?\d$", |
| 17 ... error_text="You must enter a date with the format yyyy-mm-dd.", |
| 18 ... flags='i', |
| 19 ... )] |
| 20 >>> ft_answer = FreeTextAnswer(constraints=constraints, |
| 21 ... default="This is not a valid format") |
| 22 |
| 23 # create the question specification |
| 24 >>> qn = Question(identifier=str(uuid.uuid4()), |
| 25 ... content=qn_content, |
| 26 ... answer_spec=AnswerSpecification(ft_answer)) |
| 27 |
| 28 # now, create the actual HIT for the question without using a HIT type |
| 29 # NOTE - the response_groups are specified to get back additional information fo
r testing |
| 30 >>> keywords=['boto', 'test', 'doctest'] |
| 31 >>> create_hit_rs = conn.create_hit(question=qn, |
| 32 ... lifetime=60*65, |
| 33 ... max_assignments=2, |
| 34 ... title='Boto create_hit title', |
| 35 ... description='Boto create_hit description', |
| 36 ... keywords=keywords, |
| 37 ... reward=0.23, |
| 38 ... duration=60*6, |
| 39 ... approval_delay=60*60, |
| 40 ... annotation='An annotation from boto create_h
it test', |
| 41 ... response_groups=['Minimal', |
| 42 ... 'HITDetail', |
| 43 ... 'HITQuestion', |
| 44 ... 'HITAssignmentSummary',]) |
| 45 |
| 46 # this is a valid request |
| 47 >>> create_hit_rs.status |
| 48 True |
| 49 |
| 50 # for the requested hit type id |
| 51 # the HIT Type Id is a unicode string |
| 52 >>> len(create_hit_rs) |
| 53 1 |
| 54 >>> hit = create_hit_rs[0] |
| 55 >>> hit_type_id = hit.HITTypeId |
| 56 >>> hit_type_id # doctest: +ELLIPSIS |
| 57 u'...' |
| 58 |
| 59 >>> hit.MaxAssignments |
| 60 u'2' |
| 61 |
| 62 >>> hit.AutoApprovalDelayInSeconds |
| 63 u'3600' |
| 64 |
| 65 # expiration should be very close to now + the lifetime in seconds |
| 66 >>> expected_datetime = datetime.datetime.utcnow() + datetime.timedelta(seconds=
3900) |
| 67 >>> expiration_datetime = datetime.datetime.strptime(hit.Expiration, '%Y-%m-%dT%
H:%M:%SZ') |
| 68 >>> delta = expected_datetime - expiration_datetime |
| 69 >>> abs(delta).seconds < 5 |
| 70 True |
| 71 |
| 72 # duration is as specified for the HIT type |
| 73 >>> hit.AssignmentDurationInSeconds |
| 74 u'360' |
| 75 |
| 76 # the reward has been set correctly (allow for float error here) |
| 77 >>> int(float(hit.Amount) * 100) |
| 78 23 |
| 79 |
| 80 >>> hit.FormattedPrice |
| 81 u'$0.23' |
| 82 |
| 83 # only US currency supported at present |
| 84 >>> hit.CurrencyCode |
| 85 u'USD' |
| 86 |
| 87 # title is the HIT type title |
| 88 >>> hit.Title |
| 89 u'Boto create_hit title' |
| 90 |
| 91 # title is the HIT type description |
| 92 >>> hit.Description |
| 93 u'Boto create_hit description' |
| 94 |
| 95 # annotation is correct |
| 96 >>> hit.RequesterAnnotation |
| 97 u'An annotation from boto create_hit test' |
| 98 |
| 99 >>> hit.HITReviewStatus |
| 100 u'NotReviewed' |
OLD | NEW |