~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/boto/boto/mturk/test/create_hit.doctest

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
>>> import uuid
 
2
>>> import datetime
 
3
>>> from boto.mturk.connection import MTurkConnection
 
4
>>> from boto.mturk.question import Question, QuestionContent, AnswerSpecification, FreeTextAnswer
 
5
 
 
6
>>> conn = MTurkConnection(host='mechanicalturk.sandbox.amazonaws.com')
 
7
 
 
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?')
 
11
 
 
12
# create the question specification
 
13
>>> qn = Question(identifier=str(uuid.uuid4()),
 
14
...               content=qn_content,
 
15
...               answer_spec=AnswerSpecification(FreeTextAnswer()))
 
16
 
 
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,
 
21
...                                 lifetime=60*65,
 
22
...                                 max_assignments=2,
 
23
...                                 title='Boto create_hit title',
 
24
...                                 description='Boto create_hit description',
 
25
...                                 keywords=keywords,
 
26
...                                 reward=0.23,
 
27
...                                 duration=60*6,
 
28
...                                 approval_delay=60*60,
 
29
...                                 annotation='An annotation from boto create_hit test',
 
30
...                                 response_groups=['Minimal',
 
31
...                                                  'HITDetail',
 
32
...                                                  'HITQuestion',
 
33
...                                                  'HITAssignmentSummary',])
 
34
 
 
35
# this is a valid request
 
36
>>> create_hit_rs.status
 
37
True
 
38
 
 
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
 
43
u'...'
 
44
 
 
45
>>> create_hit_rs.MaxAssignments
 
46
u'2'
 
47
 
 
48
>>> create_hit_rs.AutoApprovalDelayInSeconds
 
49
u'3600'
 
50
 
 
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
 
55
>>> delta.seconds < 5
 
56
True
 
57
 
 
58
# duration is as specified for the HIT type
 
59
>>> create_hit_rs.AssignmentDurationInSeconds
 
60
u'360'
 
61
 
 
62
# the reward has been set correctly (allow for float error here)
 
63
>>> int(create_hit_rs[0].amount * 100)
 
64
23
 
65
 
 
66
>>> create_hit_rs[0].formatted_price
 
67
u'$0.23'
 
68
 
 
69
# only US currency supported at present
 
70
>>> create_hit_rs[0].currency_code
 
71
u'USD'
 
72
 
 
73
# title is the HIT type title
 
74
>>> create_hit_rs.Title
 
75
u'Boto create_hit title'
 
76
 
 
77
# title is the HIT type description
 
78
>>> create_hit_rs.Description
 
79
u'Boto create_hit description'
 
80
 
 
81
# annotation is correct
 
82
>>> create_hit_rs.RequesterAnnotation
 
83
u'An annotation from boto create_hit test'
 
84
 
 
85
>>> create_hit_rs.HITReviewStatus
 
86
u'NotReviewed'