def test_create_qualification_type_raises_on_duplicate_name( self, with_mock): error = MTurkRequestError( 1, u'already created a QualificationType with this name') error.message = error.reason with_mock.mturk.configure_mock( **{ 'create_qualification_type.side_effect': error, }) with pytest.raises(DuplicateQualificationNameError): with_mock.create_qualification_type('name', 'desc', 'status')
def test_approve_assignment_wraps_exception_helpfully(self, with_mock): with_mock.mturk.configure_mock( ** {'approve_assignment.side_effect': MTurkRequestError(1, "Boom!")}) with pytest.raises(MTurkServiceException) as execinfo: with_mock.approve_assignment('fake_id') assert execinfo.match("Failed to approve assignment fake_id")
def test_extend_hit_wraps_exception_helpfully(self, with_mock): with_mock.mturk.configure_mock( **{ 'extend_hit.side_effect': MTurkRequestError(1, "Boom!"), }) with pytest.raises(MTurkServiceException) as execinfo: with_mock.extend_hit(hit_id='hit1', number=2, duration_hours=1.0) assert execinfo.match("Failed to extend time until expiration of HIT")
def extract_mturk_attr(result_set, attr): """ Extracts an attribute from a boto ResultSet """ if hasattr(result_set, attr): return getattr(result_set, attr) try: for r in result_set: if hasattr(r, attr): return getattr(r, attr) except TypeError: pass raise MTurkRequestError(status=0, reason='Missing %s in response' % attr)
def test_grant_bonus_wraps_exception_helpfully(self, with_mock): fake_assignment = Assignment(None) fake_assignment.WorkerId = 'some worker id' with_mock.mturk.configure_mock( **{ 'get_assignment.return_value': as_resultset(fake_assignment), 'grant_bonus.side_effect': MTurkRequestError(1, "Boom!"), }) with pytest.raises(MTurkServiceException) as execinfo: with_mock.grant_bonus(assignment_id='some assignment id', amount=2.99, reason='above and beyond') assert execinfo.match( "Failed to pay assignment some assignment id bonus of 2.99")
def test_check_credentials_bad_credentials(self, with_mock): with_mock.mturk.configure_mock( ** {'get_account_balance.side_effect': MTurkRequestError(1, 'ouch')}) with pytest.raises(MTurkRequestError): with_mock.check_credentials()