OLD | NEW |
(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 >>> create_hit_rs = conn.create_hit(question=qn, |
| 22 ... lifetime=60*65, |
| 23 ... max_assignments=1, |
| 24 ... title='Boto Hit to be Reviewed', |
| 25 ... description='Boto reviewable_hits descriptio
n', |
| 26 ... keywords=keywords, |
| 27 ... reward=0.23, |
| 28 ... duration=60*6, |
| 29 ... approval_delay=60*60, |
| 30 ... annotation='An annotation from boto create_h
it test', |
| 31 ... response_groups=['Minimal', |
| 32 ... 'HITDetail', |
| 33 ... 'HITQuestion', |
| 34 ... 'HITAssignmentSummary',]) |
| 35 |
| 36 # this is a valid request |
| 37 >>> create_hit_rs.status |
| 38 True |
| 39 |
| 40 >>> len(create_hit_rs) |
| 41 1 |
| 42 >>> hit = create_hit_rs[0] |
| 43 |
| 44 # for the requested hit type id |
| 45 # the HIT Type Id is a unicode string |
| 46 >>> hit_type_id = hit.HITTypeId |
| 47 >>> hit_type_id # doctest: +ELLIPSIS |
| 48 u'...' |
| 49 |
| 50 >>> from selenium_support import complete_hit, has_selenium |
| 51 >>> if has_selenium(): complete_hit(hit_type_id, response='reviewable_hits_test'
) |
| 52 >>> import time |
| 53 |
| 54 Give mechanical turk some time to process the hit |
| 55 >>> if has_selenium(): time.sleep(10) |
| 56 |
| 57 # should have some reviewable HIT's returned, especially if returning all HIT ty
pe's |
| 58 # NOTE: but only if your account has existing HIT's in the reviewable state |
| 59 >>> reviewable_rs = conn.get_reviewable_hits() |
| 60 |
| 61 # this is a valid request |
| 62 >>> reviewable_rs.status |
| 63 True |
| 64 |
| 65 >>> len(reviewable_rs) >= 1 |
| 66 True |
| 67 |
| 68 # should contain at least one HIT object |
| 69 >>> reviewable_rs # doctest: +ELLIPSIS |
| 70 [<boto.mturk.connection.HIT instance at ...] |
| 71 |
| 72 >>> hit_id = reviewable_rs[0].HITId |
| 73 |
| 74 # check that we can retrieve the assignments for a HIT |
| 75 >>> assignments_rs = conn.get_assignments(hit_id) |
| 76 |
| 77 # this is a valid request |
| 78 >>> assignments_rs.status |
| 79 True |
| 80 |
| 81 >>> int(assignments_rs.NumResults) >= 1 |
| 82 True |
| 83 |
| 84 >>> len(assignments_rs) == int(assignments_rs.NumResults) |
| 85 True |
| 86 |
| 87 >>> assignments_rs.PageNumber |
| 88 u'1' |
| 89 |
| 90 >>> assignments_rs.TotalNumResults >= 1 |
| 91 True |
| 92 |
| 93 # should contain at least one Assignment object |
| 94 >>> assignments_rs # doctest: +ELLIPSIS |
| 95 [<boto.mturk.connection.Assignment instance at ...] |
| 96 |
| 97 # should have returned assignments for the requested HIT id |
| 98 >>> assignment = assignments_rs[0] |
| 99 |
| 100 >>> assignment.HITId == hit_id |
| 101 True |
| 102 |
| 103 # should have a valid status |
| 104 >>> assignment.AssignmentStatus in ['Submitted', 'Approved', 'Rejected'] |
| 105 True |
| 106 |
| 107 # should have returned at least one answer |
| 108 >>> len(assignment.answers) > 0 |
| 109 True |
| 110 |
| 111 # should contain at least one set of QuestionFormAnswer objects |
| 112 >>> assignment.answers # doctest: +ELLIPSIS |
| 113 [[<boto.mturk.connection.QuestionFormAnswer instance at ...]] |
| 114 |
| 115 >>> answer = assignment.answers[0][0] |
| 116 |
| 117 # the answer should have exactly one field |
| 118 >>> len(answer.fields) |
| 119 1 |
| 120 |
| 121 >>> qid, text = answer.fields[0] |
| 122 |
| 123 >>> text # doctest: +ELLIPSIS |
| 124 u'...' |
| 125 |
| 126 # question identifier should be a unicode string |
| 127 >>> qid # doctest: +ELLIPSIS |
| 128 u'...' |
| 129 |
OLD | NEW |