~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/boto/boto/mturk/test/create_hit_from_hit_type.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
>>> keywords=['boto', 'test', 'doctest']
 
8
>>> hit_type_rs = conn.register_hit_type('Boto Test HIT type',
 
9
...                                      'HIT Type for testing Boto',
 
10
...                                      0.12,
 
11
...                                      60*6,
 
12
...                                      keywords=keywords,
 
13
...                                      approval_delay=60*60)
 
14
 
 
15
# this was a valid request
 
16
>>> hit_type_rs.status
 
17
True
 
18
 
 
19
# the HIT Type Id is a unicode string
 
20
>>> hit_type_id = hit_type_rs.HITTypeId
 
21
>>> hit_type_id # doctest: +ELLIPSIS
 
22
u'...'
 
23
 
 
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?')
 
27
 
 
28
# create the question specification
 
29
>>> qn = Question(identifier=str(uuid.uuid4()),
 
30
...               content=qn_content,
 
31
...               answer_spec=AnswerSpecification(FreeTextAnswer()))
 
32
 
 
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,
 
36
...                                 question=qn,
 
37
...                                 lifetime=60*65,
 
38
...                                 max_assignments=2,
 
39
...                                 annotation='An annotation from boto create_hit_from_hit_type test',
 
40
...                                 response_groups=['Minimal',
 
41
...                                                  'HITDetail',
 
42
...                                                  'HITQuestion',
 
43
...                                                  'HITAssignmentSummary',])
 
44
 
 
45
# this is a valid request
 
46
>>> create_hit_rs.status
 
47
True
 
48
 
 
49
# for the requested hit type id
 
50
>>> create_hit_rs.HITTypeId == hit_type_id
 
51
True
 
52
 
 
53
# with the correct number of maximum assignments
 
54
>>> create_hit_rs.MaxAssignments
 
55
u'2'
 
56
 
 
57
# and the approval delay
 
58
>>> create_hit_rs.AutoApprovalDelayInSeconds
 
59
u'3600'
 
60
 
 
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
 
65
>>> delta.seconds < 5
 
66
True
 
67
 
 
68
# duration is as specified for the HIT type
 
69
>>> create_hit_rs.AssignmentDurationInSeconds
 
70
u'360'
 
71
 
 
72
# the reward has been set correctly
 
73
>>> create_hit_rs[0].amount
 
74
0.12
 
75
 
 
76
>>> create_hit_rs[0].formatted_price
 
77
u'$0.12'
 
78
 
 
79
# only US currency supported at present
 
80
>>> create_hit_rs[0].currency_code
 
81
u'USD'
 
82
 
 
83
# title is the HIT type title
 
84
>>> create_hit_rs.Title
 
85
u'Boto Test HIT type'
 
86
 
 
87
# title is the HIT type description
 
88
>>> create_hit_rs.Description
 
89
u'HIT Type for testing Boto'
 
90
 
 
91
# annotation is correct
 
92
>>> create_hit_rs.RequesterAnnotation
 
93
u'An annotation from boto create_hit_from_hit_type test'
 
94
 
 
95
# not reviewed yet
 
96
>>> create_hit_rs.HITReviewStatus
 
97
u'NotReviewed'