示例#1
0
def test_category_export_task_sends_correct_filenames(
        mocked_send_message, mocked_send_document, job_id,
        expected_marketplace, set_scrapinghub_requests_mock, bot_user):
    set_scrapinghub_requests_mock(job_id=job_id)

    calculate_category_stats(job_id, bot_user.chat_id)

    assert expected_marketplace in mocked_send_document.call_args.kwargs[
        'filename']
示例#2
0
def test_category_export_task_not_finished(mocked_send_message,
                                           set_scrapinghub_requests_mock,
                                           bot_user, requests_mock):
    requests_mock.get(
        'https://storage.scrapinghub.com/jobs/414324/1/926/state',
        text='"running"')

    with pytest.raises(Retry):
        calculate_category_stats('414324/1/926', bot_user.chat_id)
        mocked_send_message.assert_not_called()
示例#3
0
def test_category_export_task_empty_category(mocked_send_message,
                                             set_scrapinghub_requests_mock,
                                             bot_user, current_path,
                                             requests_mock):
    set_scrapinghub_requests_mock(job_id='414324/1/926')
    requests_mock.get(
        'https://storage.scrapinghub.com/items/414324/1/926?meta=_key',
        content=open(
            current_path + '/mocks/scrapinghub_items_wb_empty.msgpack',
            'rb').read(),
        headers={'Content-Type': 'application/x-msgpack; charset=UTF-8'})

    calculate_category_stats('414324/1/926', bot_user.chat_id)

    mocked_send_message.assert_called()
    assert 'Мы не смогли обработать ссылку' in mocked_send_message.call_args.kwargs[
        'text']
示例#4
0
def test_category_export_task_sends_message(
        mocked_send_message, mocked_send_document,
        mocked_send_category_requests_count_message,
        set_scrapinghub_requests_mock, bot_user):
    set_scrapinghub_requests_mock(job_id='414324/1/926')

    calculate_category_stats('414324/1/926', bot_user.chat_id)

    required_stats = [
        'Количество товаров',
        'Продаж всего',
        'В среднем продаются по',
        'Медиана продаж',
    ]

    for message in required_stats:
        assert message in mocked_send_message.call_args.kwargs['text']

    mocked_send_message.assert_called()
    mocked_send_document.assert_called()
    mocked_send_category_requests_count_message.assert_called()
def test_category_export_task_sends_message(mocked_send_message,
                                            mocked_send_document):
    calculate_category_stats('414324/1/356', '1423')

    mocked_send_message.assert_called()
    mocked_send_document.assert_called()