def test_does_nothing_if_assignment_still_current(self, a, active_config, run_check, recruiters): participants = [a.participant()] reference_time = datetime.datetime.now() run_check(participants, active_config, reference_time) recruiters.by_name.assert_not_called()
def test_no_assignment_on_mturk_shuts_down_hit(self, run_check): # Include whimsical set to True to avoid error in the False code branch: config = { 'duration': 1.0, 'host': 'fakehost.herokuapp.com', 'whimsical': True } mturk = mock.Mock(**{'get_assignment.return_value': []}) participants = [self.a.participant()] session = None # Move the clock forward so assignment is overdue: reference_time = datetime.datetime.now() + datetime.timedelta(hours=6) os_env_heroku_auth = None with mock.patch('dallinger.heroku.clock.requests') as mock_requests: run_check(config, mturk, participants, session, reference_time) mock_requests.patch.assert_called_once_with( 'https://api.heroku.com/apps/fakehost/config-vars', data='{"auto_recruit": "false"}', headers={ "Accept": "application/vnd.heroku+json; version=3", "Content-Type": "application/json", "Authorization": "Bearer {}".format(os_env_heroku_auth), } ) mock_requests.post.assert_called_once_with( 'http://fakehost.herokuapp.com/notifications', data={ 'Event.1.EventType': 'NotificationMissing', 'Event.1.AssignmentId': participants[0].assignment_id } )
def test_does_nothing_if_assignment_still_current(self, a, stub_config, run_check): mturk = mock.Mock(**{'get_assignment.return_value': ['fake']}) participants = [a.participant()] session = None reference_time = datetime.datetime.now() run_check(stub_config, mturk, participants, session, reference_time) mturk.get_assignment.assert_not_called()
def test_sets_participant_status_if_mturk_reports_rejected(self, a, stub_config, run_check): fake_assignment = {'status': 'Rejected'} mturk = mock.Mock(**{'get_assignment.return_value': fake_assignment}) participants = [a.participant()] session = mock.Mock() # Move the clock forward so assignment is overdue: reference_time = datetime.datetime.now() + datetime.timedelta(hours=6) run_check(stub_config, mturk, participants, session, reference_time) assert participants[0].status == 'rejected' session.commit.assert_called()
def test_rejects_bot_participants(self, a, stub_config, run_check): from dallinger.recruiters import BotRecruiter mturk = mock.Mock(**{'get_assignment.return_value': ['fake']}) participants = [a.participant(recruiter_id=BotRecruiter.nickname)] session = mock.Mock() # Move the clock forward so assignment is overdue: reference_time = datetime.datetime.now() + datetime.timedelta(hours=6) run_check(stub_config, mturk, participants, session, reference_time) assert participants[0].status == 'rejected' session.commit.assert_called()
def test_reports_late_participants_to_their_recruiter( self, a, active_config, run_check, recruiters): participants = [a.participant()] five_minutes_over = 60 * active_config.get("duration") + 5 reference_time = datetime.datetime.now() + datetime.timedelta( minutes=five_minutes_over) run_check(participants, active_config, reference_time) recruiters.by_name.assert_called_once_with( participants[0].recruiter_id)
def test_sets_participant_status_if_mturk_reports_rejected(self, run_check): config = {'duration': 1.0} fake_assignment = mock.Mock(AssignmentStatus='Rejected') mturk = mock.Mock(**{'get_assignment.return_value': [fake_assignment]}) participants = [self.a.participant()] session = mock.Mock() # Move the clock forward so assignment is overdue: reference_time = datetime.datetime.now() + datetime.timedelta(hours=6) run_check(config, mturk, participants, session, reference_time) assert participants[0].status == 'rejected' session.commit.assert_called()
def test_no_assignment_on_mturk_sends_hit_cancelled_message(self, a, stub_config, run_check): mturk = mock.Mock(**{'get_assignment.return_value': None}) participants = [a.participant()] session = None # Move the clock forward so assignment is overdue: reference_time = datetime.datetime.now() + datetime.timedelta(hours=6) mock_messenger = mock.Mock(spec=EmailingHITMessenger) with mock.patch.multiple('dallinger.heroku.clock', requests=mock.DEFAULT, get_messenger=mock.DEFAULT) as mocks: mocks['get_messenger'].return_value = mock_messenger run_check(stub_config, mturk, participants, session, reference_time) mock_messenger.send_hit_cancelled_msg.assert_called()
def test_no_assignement_on_mturk_sends_hit_cancelled_message(self, run_check): # Include whimsical set to True to avoid error in the False code branch: config = { 'duration': 1.0, 'host': 'fakehost.herokuapp.com', 'whimsical': False } mturk = mock.Mock(**{'get_assignment.return_value': []}) participants = [self.a.participant()] session = None # Move the clock forward so assignment is overdue: reference_time = datetime.datetime.now() + datetime.timedelta(hours=6) mock_messager = mock.Mock(spec=NullHITMessager) with mock.patch.multiple('dallinger.heroku.clock', requests=mock.DEFAULT, NullHITMessager=mock.DEFAULT) as mocks: mocks['NullHITMessager'].return_value = mock_messager run_check(config, mturk, participants, session, reference_time) mock_messager.send_hit_cancelled_msg.assert_called()
def test_resubmits_notification_if_mturk_reports_submitted(self, a, stub_config, run_check): # Include whimsical set to True to avoid error in the False code branch: stub_config.extend({'host': u'fakehost.herokuapp.com'}) fake_assignment = {'status': 'Submitted'} mturk = mock.Mock(**{'get_assignment.return_value': fake_assignment}) participants = [a.participant()] session = None # Move the clock forward so assignment is overdue: reference_time = datetime.datetime.now() + datetime.timedelta(hours=6) with mock.patch('dallinger.heroku.clock.requests') as mock_requests: run_check(stub_config, mturk, participants, session, reference_time) mock_requests.post.assert_called_once_with( 'http://fakehost.herokuapp.com/notifications', data={ 'Event.1.EventType': 'AssignmentSubmitted', 'Event.1.AssignmentId': participants[0].assignment_id } )