Exemplo n.º 1
0
def test_scrape_article_with_summary(mock_nltk, mock_article_cls):
    result = scrape_article(sentinel.url, summary=True)
    mock_article_cls.assert_called_once_with(url=sentinel.url)
    mock_article = mock_article_cls.return_value
    mock_nltk.download.assert_called_once_with('punkt')
    mock_article.assert_has_calls([call.download(), call.parse(), call.nlp()])
    assert result == (mock_article.text, mock_article.summary)
Exemplo n.º 2
0
def test_scrape_article_no_summary(mock_nltk, mock_article_cls):
    result = scrape_article(sentinel.url)
    mock_article_cls.assert_called_once_with(url=sentinel.url)
    mock_article = mock_article_cls.return_value
    mock_article.assert_has_calls([call.download(), call.parse()])
    mock_nltk.download.assert_not_called()
    mock_article.nlp.assert_not_called()
    assert result == (mock_article.text, None)
Exemplo n.º 3
0
    def test_params_plumbing_success(self, MockProcessor):
        # Set up mock context manager to return self.
        mock = MockProcessor.return_value
        mock.__enter__.return_value = mock
        mock.check_existing_run.return_value = False
        mock.results = ['/tmp/wpt_report.json.gz']
        mock.raw_results_url = 'https://wpt.fyi/test/report.json'
        mock.results_url = 'https://wpt.fyi/test'
        mock.test_run_id = 654321

        # NOTE: if you need to change the following params, you probably also
        # want to change api/receiver/api.go.
        params = MultiDict({
            'uploader':
            'blade-runner',
            'id':
            '654321',
            'callback_url':
            'https://test.wpt.fyi/api',
            'labels':
            'foo,bar',
            'results':
            'https://wpt.fyi/wpt_report.json.gz',
            'browser_name':
            'Chrome',
            'browser_version':
            '70',
            'os_name':
            'Linux',
            'os_version':
            '5.0',
            'revision':
            '21917b36553562d21c14fe086756a57cbe8a381b',
        })
        process_report('12345', params)
        mock.assert_has_calls([
            call.update_status('654321', 'WPTFYI_PROCESSING', None,
                               'https://test.wpt.fyi/api'),
            call.download(['https://wpt.fyi/wpt_report.json.gz'], [], None),
        ])
        mock.report.update_metadata.assert_called_once_with(
            revision='21917b36553562d21c14fe086756a57cbe8a381b',
            browser_name='Chrome',
            browser_version='70',
            os_name='Linux',
            os_version='5.0')
        mock.create_run.assert_called_once_with('654321', 'foo,bar',
                                                'blade-runner',
                                                'https://test.wpt.fyi/api')
Exemplo n.º 4
0
def test_api_protected_download(monkeypatch):
    mocked_api = Mock()
    mock_thread = Mock()

    testapi = api.APIHandler()
    testapi._api = mocked_api
    testapi._api_thread = mock_thread
    testapi._login_started = True
    testapi._login_done = False

    testapi.protected_download('url', 'path', 'name')

    assert mocked_api.mock_calls == [
        call.download('url', path='path', name='name')
    ]
    assert mock_thread.mock_calls == [call.join()]
    assert testapi._login_done == True
Exemplo n.º 5
0
    def test_params_plumbing_empty(self, MockProcessor):
        # Set up mock context manager to return self.
        mock = MockProcessor.return_value
        mock.__enter__.return_value = mock
        mock.results = []

        params = MultiDict({
            'uploader': 'blade-runner',
            'id': '654321',
        })
        with self.assertLogs():
            process_report('12345', params)
        mock.assert_has_calls([
            call.update_status('654321', 'WPTFYI_PROCESSING', None, None),
            call.download([], [], None),
            call.update_status('654321', 'EMPTY', None, None),
        ])
        mock.create_run.assert_not_called()
Exemplo n.º 6
0
 def test_load(self, mock_cleanup, mock_load_downloaded_workflow,
               mock_handle_download, mock_download_workflow, mock_mkdtemp):
     self.setup_mkdtemp(mock_mkdtemp)
     loader = BespinWorkflowLoader(self.workflow_version)
     manager = Mock()
     manager.attach_mock(mock_download_workflow, 'download')
     manager.attach_mock(mock_handle_download, 'handle')
     manager.attach_mock(mock_load_downloaded_workflow, 'load_downloaded')
     manager.attach_mock(mock_cleanup, 'cleanup')
     loaded = loader.load()
     self.assertEqual(manager.mock_calls, [
         call.download(),
         call.handle(),
         call.load_downloaded(),
         call.cleanup()
     ])
     # Make sure we assert this check after the order, because it interferes with the calls
     self.assertEqual(loaded, mock_load_downloaded_workflow.return_value)
Exemplo n.º 7
0
    def test_params_plumbing_error(self, MockProcessor):
        # Set up mock context manager to return self.
        mock = MockProcessor.return_value
        mock.__enter__.return_value = mock
        mock.results = ['/tmp/wpt_report.json.gz']
        mock.load_report.side_effect = wptreport.InvalidJSONError

        params = MultiDict({
            'uploader': 'blade-runner',
            'id': '654321',
            'results': 'https://wpt.fyi/wpt_report.json.gz',
        })
        # Suppress print_exception.
        with patch('traceback.print_exception'):
            process_report('12345', params)
        mock.assert_has_calls([
            call.update_status('654321', 'WPTFYI_PROCESSING', None, None),
            call.download(['https://wpt.fyi/wpt_report.json.gz'], [], None),
            call.load_report(),
            call.update_status(
                '654321', 'INVALID',
                "Invalid JSON (['https://wpt.fyi/wpt_report.json.gz'])", None),
        ])
        mock.create_run.assert_not_called()