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')
8
# create content for a question
9
>>> qn_content = QuestionContent(title='Boto no hit type question content',
10
... text='What is a boto no hit type?')
12
# create the question specification
13
>>> qn = Question(identifier=str(uuid.uuid4()),
14
... content=qn_content,
15
... answer_spec=AnswerSpecification(FreeTextAnswer()))
17
# now, create the actual HIT for the question without using a HIT type
18
# NOTE - the response_groups are specified to get back additional information for testing
19
>>> keywords=['boto', 'test', 'doctest']
20
>>> create_hit_rs = conn.create_hit(question=qn,
22
... max_assignments=2,
23
... title='Boto create_hit title',
24
... description='Boto create_hit description',
25
... keywords=keywords,
28
... approval_delay=60*60,
29
... annotation='An annotation from boto create_hit test',
30
... response_groups=['Minimal',
33
... 'HITAssignmentSummary',])
35
# this is a valid request
36
>>> create_hit_rs.status
39
# for the requested hit type id
40
# the HIT Type Id is a unicode string
41
>>> hit_type_id = create_hit_rs.HITTypeId
42
>>> hit_type_id # doctest: +ELLIPSIS
45
>>> create_hit_rs.MaxAssignments
48
>>> create_hit_rs.AutoApprovalDelayInSeconds
51
# expiration should be very close to now + the lifetime in seconds
52
>>> expected_datetime = datetime.datetime.utcnow() + datetime.timedelta(seconds=3900)
53
>>> expiration_datetime = datetime.datetime.strptime(create_hit_rs.Expiration, '%Y-%m-%dT%H:%M:%SZ')
54
>>> delta = expected_datetime - expiration_datetime
58
# duration is as specified for the HIT type
59
>>> create_hit_rs.AssignmentDurationInSeconds
62
# the reward has been set correctly (allow for float error here)
63
>>> int(create_hit_rs[0].amount * 100)
66
>>> create_hit_rs[0].formatted_price
69
# only US currency supported at present
70
>>> create_hit_rs[0].currency_code
73
# title is the HIT type title
74
>>> create_hit_rs.Title
75
u'Boto create_hit title'
77
# title is the HIT type description
78
>>> create_hit_rs.Description
79
u'Boto create_hit description'
81
# annotation is correct
82
>>> create_hit_rs.RequesterAnnotation
83
u'An annotation from boto create_hit test'
85
>>> create_hit_rs.HITReviewStatus