Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/gsutil/boto/tests/mturk/create_hit.doctest

Issue 12317103: Added gsutil to depot tools (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: added readme Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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
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 the question specification
14 >>> qn = Question(identifier=str(uuid.uuid4()),
15 ... content=qn_content,
16 ... answer_spec=AnswerSpecification(FreeTextAnswer()))
17
18 # now, create the actual HIT for the question without using a HIT type
19 # NOTE - the response_groups are specified to get back additional information fo r testing
20 >>> keywords=['boto', 'test', 'doctest']
21 >>> lifetime = datetime.timedelta(minutes=65)
22 >>> create_hit_rs = conn.create_hit(question=qn,
23 ... lifetime=lifetime,
24 ... max_assignments=2,
25 ... title='Boto create_hit title',
26 ... description='Boto create_hit description',
27 ... keywords=keywords,
28 ... reward=0.23,
29 ... duration=60*6,
30 ... approval_delay=60*60,
31 ... annotation='An annotation from boto create_h it test',
32 ... response_groups=['Minimal',
33 ... 'HITDetail',
34 ... 'HITQuestion',
35 ... 'HITAssignmentSummary',])
36
37 # this is a valid request
38 >>> create_hit_rs.status
39 True
40
41 >>> len(create_hit_rs)
42 1
43 >>> hit = create_hit_rs[0]
44
45 # for the requested hit type id
46 # the HIT Type Id is a unicode string
47 >>> hit_type_id = hit.HITTypeId
48 >>> hit_type_id # doctest: +ELLIPSIS
49 u'...'
50
51 >>> hit.MaxAssignments
52 u'2'
53
54 >>> hit.AutoApprovalDelayInSeconds
55 u'3600'
56
57 # expiration should be very close to now + the lifetime
58 >>> expected_datetime = datetime.datetime.utcnow() + lifetime
59 >>> expiration_datetime = datetime.datetime.strptime(hit.Expiration, '%Y-%m-%dT% H:%M:%SZ')
60 >>> delta = expected_datetime - expiration_datetime
61 >>> abs(delta).seconds < 5
62 True
63
64 # duration is as specified for the HIT type
65 >>> hit.AssignmentDurationInSeconds
66 u'360'
67
68 # the reward has been set correctly (allow for float error here)
69 >>> int(float(hit.Amount) * 100)
70 23
71
72 >>> hit.FormattedPrice
73 u'$0.23'
74
75 # only US currency supported at present
76 >>> hit.CurrencyCode
77 u'USD'
78
79 # title is the HIT type title
80 >>> hit.Title
81 u'Boto create_hit title'
82
83 # title is the HIT type description
84 >>> hit.Description
85 u'Boto create_hit description'
86
87 # annotation is correct
88 >>> hit.RequesterAnnotation
89 u'An annotation from boto create_hit test'
90
91 >>> hit.HITReviewStatus
92 u'NotReviewed'
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698