Esempio n. 1
0
 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')
Esempio n. 2
0
    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")
Esempio n. 3
0
    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")
Esempio n. 4
0
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)
Esempio n. 5
0
    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")
Esempio n. 6
0
 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()