示例#1
0
async def test_get_announce_url_succeeds(mocker):
    tracker = NblTracker(options={
        'username': '******',
        'password': '******',
        'base_url': 'http://nbl.local',
        'announce': 'http://nbl.local/announce',
        'exclude': 'some files',
    }, )

    mocks = AsyncMock(
        get=mocker.patch(
            'upsies.utils.http.get',
            AsyncMock(return_value='''
            <html>
                <input type="text" value="https://nbl.local:123/l33tb34f/announce">
            </html>
            ''', )),
        post=mocker.patch('upsies.utils.http.post', AsyncMock()),
        login=AsyncMock(),
        logout=AsyncMock(),
    )
    mocker.patch.object(tracker, 'login', mocks.login)
    mocker.patch.object(tracker, 'logout', mocks.logout)

    announce_url = await tracker.get_announce_url()
    assert announce_url == 'https://nbl.local:123/l33tb34f/announce'
    assert mocks.mock_calls == [
        call.login(),
        call.get('http://nbl.local' + NblTracker._url_path['upload'],
                 cache=False,
                 user_agent=True),
        call.logout(),
    ]
示例#2
0
async def test_get_announce_url_fails(mocker):
    tracker = NblTracker(options={
        'username': '******',
        'password': '******',
        'base_url': 'http://nbl.local',
        'announce': 'http://nbl.local/announce',
        'exclude': 'some files',
    }, )

    mocks = AsyncMock(
        get=mocker.patch('upsies.utils.http.get',
                         AsyncMock(return_value='<html>foo</html>', )),
        post=mocker.patch('upsies.utils.http.post', AsyncMock()),
        login=AsyncMock(),
        logout=AsyncMock(),
    )
    mocker.patch.object(tracker, 'login', mocks.login)
    mocker.patch.object(tracker, 'logout', mocks.logout)

    exp_cmd = f'{__project_name__} set trackers.{tracker.name}.announce_url <YOUR URL>'
    with pytest.raises(
            errors.RequestError,
            match=rf'^Failed to find announce URL - set it manually: {exp_cmd}$'
    ):
        await tracker.get_announce_url()
    assert mocks.mock_calls == [
        call.login(),
        call.get('http://nbl.local' + NblTracker._url_path['upload'],
                 cache=False,
                 user_agent=True),
        call.logout(),
    ]
示例#3
0
async def test_get_announce_url_succeeds(mocker):
    tracker = BbTracker(options={'base_url': 'http://bb.local'})

    mocks = AsyncMock(
        get=mocker.patch('upsies.utils.http.get', AsyncMock(
            return_value='''
            <html>
                <input type="text" value="https://bb.local:123/l33tb34f/announce">
            </html>
            ''',
        )),
        post=mocker.patch('upsies.utils.http.post', AsyncMock()),
        login=AsyncMock(),
        logout=AsyncMock(),
    )
    mocker.patch.object(tracker, 'login', mocks.login)
    mocker.patch.object(tracker, 'logout', mocks.logout)

    announce_url = await tracker.get_announce_url()
    assert announce_url == 'https://bb.local:123/l33tb34f/announce'
    assert mocks.mock_calls == [
        call.login(),
        call.get('http://bb.local' + BbTracker._url_path['upload'], cache=False, user_agent=True),
        call.logout(),
    ]
示例#4
0
def test_logout(caplog, store_mock):
    """Simple logout case."""
    caplog.set_level(logging.INFO, logger="charmcraft.commands")

    LogoutCommand('group').run(noargs)

    assert store_mock.mock_calls == [
        call.logout(),
    ]
    assert ["Credentials cleared."] == [rec.message for rec in caplog.records]
示例#5
0
async def test_submit_calls_methods_and_callbacks_in_correct_order(
        job, mocker):
    mocks = Mock()
    mocks.attach_mock(job._tracker.login, 'login')
    mocks.attach_mock(job._tracker.logout, 'logout')
    mocks.attach_mock(job._tracker.upload, 'upload')
    job.signal.register('logging_in', mocks.logging_in_cb)
    job.signal.register('logged_in', mocks.logged_in_cb)
    job.signal.register('uploading', mocks.uploading_cb)
    job.signal.register('uploaded', mocks.uploaded_cb)
    job.signal.register('logging_out', mocks.logging_out_cb)
    job.signal.register('logged_out', mocks.logged_out_cb)
    await job._submit()
    assert mocks.method_calls == [
        call.logging_in_cb(),
        call.login(),
        call.logged_in_cb(),
        call.uploading_cb(),
        call.upload(job._tracker_jobs),
        call.uploaded_cb(),
        call.logging_out_cb(),
        call.logout(),
        call.logged_out_cb(),
    ]