def test_select_analysis_throttled(self, mocker, processed_payload):
     """Test that the result is initialised using the helper function."""
     mocker.patch('libcrowds_analyst.analysis.playbills.enki')
     mock_sleep = mocker.patch(
         'libcrowds_analyst.analysis.playbills.time.sleep')
     playbills.analyse_selections(**processed_payload)
     mock_sleep.assert_called_with(processed_payload['throttle'])
 def test_select_analysis_throttled(self, mocker, processed_payload):
     """Test that the result is initialised using the helper function."""
     mocker.patch('libcrowds_analyst.analysis.playbills.enki')
     mock_sleep = mocker.patch(
       'libcrowds_analyst.analysis.playbills.time.sleep'
     )
     playbills.analyse_selections(**processed_payload)
     mock_sleep.assert_called_with(processed_payload['throttle'])
 def test_correct_result_analysed(self, mocker, project, result,
                                  processed_payload):
     """Test that the correct result is analysed."""
     mock_enki = mocker.patch('libcrowds_analyst.analysis.playbills.enki')
     playbills.analyse_selections(**processed_payload)
     mock_enki.pbclient.find_results.assert_called_with(project.id,
                                                        limit=1,
                                                        id=result.id,
                                                        all=1)
 def test_select_result_initialised_properly(self, mocker,
                                             processed_payload):
     """Test that the result is initialised using the helper function."""
     mocker.patch('libcrowds_analyst.analysis.playbills.enki')
     mock_init_info = mocker.patch('libcrowds_analyst.analysis.playbills.'
                                   'helpers.init_result_info')
     playbills.analyse_selections(**processed_payload)
     assert mock_init_info.call_args[0][0] == processed_payload['doi']
     assert mock_init_info.call_args[0][1] == processed_payload['path']
 def test_correct_result_analysed(self, mocker, project, result,
                                  processed_payload):
     """Test that the correct result is analysed."""
     mock_enki = mocker.patch(
         'libcrowds_analyst.analysis.playbills.enki'
     )
     playbills.analyse_selections(**processed_payload)
     mock_enki.pbclient.find_results.assert_called_with(project.id, limit=1,
                                                        id=result.id, all=1)
 def test_select_result_initialised_properly(self, mocker,
                                             processed_payload):
     """Test that the result is initialised using the helper function."""
     mocker.patch('libcrowds_analyst.analysis.playbills.enki')
     mock_init_info = mocker.patch('libcrowds_analyst.analysis.playbills.'
                                   'helpers.init_result_info')
     playbills.analyse_selections(**processed_payload)
     assert mock_init_info.call_args[0][0] == processed_payload['doi']
     assert mock_init_info.call_args[0][1] == processed_payload['path']
 def test_comments_accepted(self, mocker, processed_payload, result,
                            comment_annotation, create_task_run_df):
     """Test that comment annotations are handled properly."""
     mock_enki = mocker.patch('libcrowds_analyst.analysis.playbills.enki')
     comment = comment_annotation('Some comment')
     tr_info = [[comment]]
     df = create_task_run_df(tr_info)
     mock_enki.pbclient.find_results.return_value = [result]
     mock_enki.Enki().task_runs_df.__getitem__.return_value = df
     playbills.analyse_selections(**processed_payload)
     mock_enki.pbclient.update_result.assert_called_with(result)
     assert result.info['annotations'] == [comment]
 def test_equal_regions_combined(self, create_task_run_df, mocker, result,
                                 processed_payload, select_annotation):
     """Test that equal regions are combined."""
     mock_enki = mocker.patch('libcrowds_analyst.analysis.playbills.enki')
     selection = {'x': 400, 'y': 200, 'w': 100, 'h': 100}
     tr_info = [[
         select_annotation(**selection),
         select_annotation(**selection)
     ]]
     df = create_task_run_df(tr_info)
     mock_enki.pbclient.find_results.return_value = [result]
     mock_enki.Enki().task_runs_df.__getitem__.return_value = df
     playbills.analyse_selections(**processed_payload)
     mock_enki.pbclient.update_result.assert_called_with(result)
     expected = '?xywh=400,200,100,100'
     annotations = result.info['annotations']
     assert len(annotations) == 1
     assert annotations[0]['target']['selector']['value'] == expected
 def test_comments_accepted(self, mocker, processed_payload, result,
                            comment_annotation, create_task_run_df):
     """Test that comment annotations are handled properly."""
     mock_enki = mocker.patch(
         'libcrowds_analyst.analysis.playbills.enki'
     )
     comment = comment_annotation('Some comment')
     tr_info = [
         [
             comment
         ]
     ]
     df = create_task_run_df(tr_info)
     mock_enki.pbclient.find_results.return_value = [result]
     mock_enki.Enki().task_runs_df.__getitem__.return_value = df
     playbills.analyse_selections(**processed_payload)
     mock_enki.pbclient.update_result.assert_called_with(result)
     assert result.info['annotations'] == [comment]
 def test_empty_result_updated(self, create_task_run_df, mocker, result,
                               processed_payload):
     """Test that an empty result is updated correctly."""
     mock_enki = mocker.patch('libcrowds_analyst.analysis.playbills.enki')
     tr_info = [
         [],
         [],
     ]
     df = create_task_run_df(tr_info)
     mock_enki.pbclient.find_results.return_value = [result]
     mock_enki.Enki().task_runs_df.__getitem__.return_value = df
     playbills.analyse_selections(**processed_payload)
     mock_enki.pbclient.update_result.assert_called_with(result)
     assert result.info == {
         'annotations': [],
         'analysis_complete': True,
         'analysis_doi': '123/456',
         'analysis_path': '/example'
     }
 def test_empty_result_updated(self, create_task_run_df, mocker, result,
                               processed_payload):
     """Test that an empty result is updated correctly."""
     mock_enki = mocker.patch(
         'libcrowds_analyst.analysis.playbills.enki'
     )
     tr_info = [
         [],
         [],
     ]
     df = create_task_run_df(tr_info)
     mock_enki.pbclient.find_results.return_value = [result]
     mock_enki.Enki().task_runs_df.__getitem__.return_value = df
     playbills.analyse_selections(**processed_payload)
     mock_enki.pbclient.update_result.assert_called_with(result)
     assert result.info == {
         'annotations': [],
         'analysis_complete': True,
         'analysis_doi': '123/456',
         'analysis_path': '/example'
     }
 def test_equal_regions_combined(self, create_task_run_df, mocker,
                                 result, processed_payload,
                                 select_annotation):
     """Test that equal regions are combined."""
     mock_enki = mocker.patch(
         'libcrowds_analyst.analysis.playbills.enki'
     )
     selection = {'x': 400, 'y': 200, 'w': 100, 'h': 100}
     tr_info = [
         [
             select_annotation(**selection),
             select_annotation(**selection)
         ]
     ]
     df = create_task_run_df(tr_info)
     mock_enki.pbclient.find_results.return_value = [result]
     mock_enki.Enki().task_runs_df.__getitem__.return_value = df
     playbills.analyse_selections(**processed_payload)
     mock_enki.pbclient.update_result.assert_called_with(result)
     expected = '?xywh=400,200,100,100'
     annotations = result.info['annotations']
     assert len(annotations) == 1
     assert annotations[0]['target']['selector']['value'] == expected