3
>>> from boto.mturk.connection import MTurkConnection
4
>>> from boto.mturk.question import Question, QuestionContent, AnswerSpecification, FreeTextAnswer
6
>>> conn = MTurkConnection(host='mechanicalturk.sandbox.amazonaws.com')
7
>>> keywords=['boto', 'test', 'doctest']
8
>>> hit_type_rs = conn.register_hit_type('Boto Test HIT type',
9
... 'HIT Type for testing Boto',
12
... keywords=keywords,
13
... approval_delay=60*60)
15
# this was a valid request
16
>>> hit_type_rs.status
19
# the HIT Type Id is a unicode string
20
>>> hit_type_id = hit_type_rs.HITTypeId
21
>>> hit_type_id # doctest: +ELLIPSIS
24
# create content for a question
25
>>> qn_content = QuestionContent(title='Boto question content create_hit_from_hit_type',
26
... text='What is a boto create_hit_from_hit_type?')
28
# create the question specification
29
>>> qn = Question(identifier=str(uuid.uuid4()),
30
... content=qn_content,
31
... answer_spec=AnswerSpecification(FreeTextAnswer()))
33
# now, create the actual HIT for the question using the HIT type
34
# NOTE - the response_groups are specified to get back additional information for testing
35
>>> create_hit_rs = conn.create_hit(hit_type=hit_type_rs.HITTypeId,
38
... max_assignments=2,
39
... annotation='An annotation from boto create_hit_from_hit_type test',
40
... response_groups=['Minimal',
43
... 'HITAssignmentSummary',])
45
# this is a valid request
46
>>> create_hit_rs.status
49
# for the requested hit type id
50
>>> create_hit_rs.HITTypeId == hit_type_id
53
# with the correct number of maximum assignments
54
>>> create_hit_rs.MaxAssignments
57
# and the approval delay
58
>>> create_hit_rs.AutoApprovalDelayInSeconds
61
# expiration should be very close to now + the lifetime in seconds
62
>>> expected_datetime = datetime.datetime.utcnow() + datetime.timedelta(seconds=3900)
63
>>> expiration_datetime = datetime.datetime.strptime(create_hit_rs.Expiration, '%Y-%m-%dT%H:%M:%SZ')
64
>>> delta = expected_datetime - expiration_datetime
68
# duration is as specified for the HIT type
69
>>> create_hit_rs.AssignmentDurationInSeconds
72
# the reward has been set correctly
73
>>> create_hit_rs[0].amount
76
>>> create_hit_rs[0].formatted_price
79
# only US currency supported at present
80
>>> create_hit_rs[0].currency_code
83
# title is the HIT type title
84
>>> create_hit_rs.Title
87
# title is the HIT type description
88
>>> create_hit_rs.Description
89
u'HIT Type for testing Boto'
91
# annotation is correct
92
>>> create_hit_rs.RequesterAnnotation
93
u'An annotation from boto create_hit_from_hit_type test'
96
>>> create_hit_rs.HITReviewStatus